Add extensions status to osquery_info

This commit is contained in:
Teddy Reed 2015-02-10 12:00:03 -08:00
parent 93a2dcde18
commit 2593e8f837
4 changed files with 46 additions and 2 deletions

View File

@ -194,6 +194,9 @@ class ExtensionManagerRunner : public InternalRunnable {
std::string path_;
};
/// Ping an extension manager or extension.
Status pingExtension(const std::string& path);
/**
* @brief Call a Plugin exposed by an Extension Registry route.
*

View File

@ -271,13 +271,47 @@ Status startExtension(const std::string& manager_path,
return Status(0, std::to_string(status.uuid));
}
Status pingExtension(const std::string& path) {
if (FLAGS_disable_extensions) {
return Status(1, "Extensions disabled");
}
// Make sure the extension path exists, and is writable.
if (!pathExists(path) || !isWritable(path)) {
return Status(1, "Extension socket not availabe: " + path);
}
// Open a socket to the extension.
boost::shared_ptr<TSocket> socket(new TSocket(path));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
ExtensionClient client(protocol);
ExtensionStatus ext_status;
try {
transport->open();
client.ping(ext_status);
transport->close();
} catch (const std::exception& e) {
return Status(1, "Extension call failed: " + std::string(e.what()));
}
return Status(ext_status.code, ext_status.message);
}
Status callExtension(const RouteUUID uuid,
const std::string& registry,
const std::string& item,
const PluginRequest& request,
PluginResponse& response) {
// Not yet implemented.
return Status(0, "OK");
if (FLAGS_disable_extensions) {
return Status(1, "Extensions disabled");
}
return callExtension(FLAGS_extensions_socket + "." + std::to_string(uuid),
registry,
item,
request,
response);
}
Status callExtension(const std::string& extension_path,
@ -329,6 +363,9 @@ Status startExtensionWatcher(const std::string& manager_path,
}
Status startExtensionManager() {
if (FLAGS_disable_extensions) {
return Status(1, "Extensions disabled");
}
return startExtensionManager(FLAGS_extensions_socket);
}

View File

@ -5,5 +5,6 @@ schema([
Column("config_md5", TEXT),
Column("config_path", TEXT),
Column("pid", INTEGER, "Process (or thread) ID"),
Column("extensions", TEXT),
])
implementation("osquery@genOsqueryInfo")

View File

@ -10,6 +10,7 @@
#include <osquery/config.h>
#include <osquery/core.h>
#include <osquery/extensions.h>
#include <osquery/flags.h>
#include <osquery/logger.h>
#include <osquery/sql.h>
@ -65,6 +66,8 @@ QueryData genOsqueryInfo(QueryContext& context) {
}
r["config_path"] = Flag::get().getValue("config_path");
r["extensions"] =
(pingExtension(FLAGS_extensions_socket).ok()) ? "active" : "inactive";
results.push_back(r);
return results;