Module: check_mk
Branch: master
Commit: b777444fe3ff94aa0720c790df4e6fdb0fcacaa3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b777444fe3ff94…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Jun 6 11:32:21 2016 +0200
Fetched Livestatus from downstream.
---
.../src/DynamicEventConsoleReplicationColumn.cc | 75 +++++++++++++++++++-
.../src/DynamicEventConsoleReplicationColumn.h | 12 +++-
livestatus/src/TableEventConsoleReplication.cc | 18 ++++-
livestatus/src/TableEventConsoleReplication.h | 7 +-
4 files changed, 104 insertions(+), 8 deletions(-)
diff --git a/livestatus/src/DynamicEventConsoleReplicationColumn.cc
b/livestatus/src/DynamicEventConsoleReplicationColumn.cc
index 7f3d22d..c8b4ef2 100644
--- a/livestatus/src/DynamicEventConsoleReplicationColumn.cc
+++ b/livestatus/src/DynamicEventConsoleReplicationColumn.cc
@@ -23,13 +23,82 @@
// Boston, MA 02110-1301 USA.
#include "DynamicEventConsoleReplicationColumn.h"
+#include <memory>
+#include <utility>
+#include <vector>
+#include "BlobColumn.h"
+#include "EventConsoleConnection.h"
+#include "Logger.h"
+#ifdef CMC
+#include "Config.h"
+#include "Core.h"
+#include "World.h"
+#else
+extern "C" {
+extern char g_mkeventd_socket_path[4096];
+}
+#endif
+
+using std::make_unique;
+using std::string;
+using std::unique_ptr;
+using std::vector;
+
+namespace {
+class ECTableConnection : public EventConsoleConnection {
+public:
+ ECTableConnection(string path, string command)
+ : EventConsoleConnection(path), _command(move(command)) {}
+ string getResult() const { return _result; }
+
+private:
+ void sendRequest(std::ostream &os) override { os << _command; }
+ bool receiveReply() override { return getline(_result); }
+
+ const string _command;
+ string _result;
+};
+
+class ReplicationColumn : public BlobColumn {
+public:
+ ReplicationColumn(string name, string description, int indirect_offset,
+ int extra_offset, string blob)
+ : BlobColumn(name, description, indirect_offset, extra_offset)
+ , _blob(blob) {}
+
+ unique_ptr<vector<char>> getBlob(void *) override {
+ return make_unique<vector<char>>(_blob.begin(), _blob.end());
+ };
+
+private:
+ const string _blob;
+};
+} // namespace
DynamicEventConsoleReplicationColumn::DynamicEventConsoleReplicationColumn(
std::string name, std::string description, int indirect_offset,
- int extra_offset)
- : DynamicColumn(name, description, indirect_offset, extra_offset) {}
+ int extra_offset
+#ifdef CMC
+ ,
+ Core *core
+#endif
+ )
+ : DynamicColumn(name, description, indirect_offset, extra_offset)
+#ifdef CMC
+ , _core(core)
+#endif
+{
+}
Column *DynamicEventConsoleReplicationColumn::createColumn(
const std::string &arguments) {
- return nullptr;
+#ifdef CMC
+ string path = _core->_world->_config->_mkeventd_socket_path;
+#else
+ string path = g_mkeventd_socket_path;
+#endif
+ ECTableConnection ec(path, "REPLICATE " + arguments);
+ ec.run();
+ return new ReplicationColumn("replication", "replication value",
-1, -1,
+ ec.getResult());
}
diff --git a/livestatus/src/DynamicEventConsoleReplicationColumn.h
b/livestatus/src/DynamicEventConsoleReplicationColumn.h
index 804463b..f9603be 100644
--- a/livestatus/src/DynamicEventConsoleReplicationColumn.h
+++ b/livestatus/src/DynamicEventConsoleReplicationColumn.h
@@ -29,13 +29,23 @@
#include <string>
#include "DynamicColumn.h"
class Column;
+class Core;
class DynamicEventConsoleReplicationColumn : public DynamicColumn {
public:
DynamicEventConsoleReplicationColumn(std::string name,
std::string description,
- int indirect_offset, int extra_offset);
+ int indirect_offset, int extra_offset
+#ifdef CMC
+ ,
+ Core *core
+#endif
+ );
Column *createColumn(const std::string &arguments) override;
+#ifdef CMC
+private:
+ Core *_core;
+#endif
};
#endif // DynamicEventConsoleReplicationColumn_h
diff --git a/livestatus/src/TableEventConsoleReplication.cc
b/livestatus/src/TableEventConsoleReplication.cc
index 78e5357..42550e7 100644
--- a/livestatus/src/TableEventConsoleReplication.cc
+++ b/livestatus/src/TableEventConsoleReplication.cc
@@ -24,10 +24,20 @@
#include "TableEventConsoleReplication.h"
#include "DynamicEventConsoleReplicationColumn.h"
+#include "Query.h"
-TableEventConsoleReplication::TableEventConsoleReplication() {
+TableEventConsoleReplication::TableEventConsoleReplication(
+#ifdef CMC
+ Core *core
+#endif
+ ) {
addDynamicColumn(new DynamicEventConsoleReplicationColumn(
- "value", "The replication value", -1, -1));
+ "value", "The replication value", -1, -1
+#ifdef CMC
+ ,
+ core
+#endif
+ ));
}
const char *TableEventConsoleReplication::name() const {
@@ -38,4 +48,6 @@ const char *TableEventConsoleReplication::namePrefix() const {
return "eventconsolereplication_";
}
-void TableEventConsoleReplication::answerQuery(Query *query) {}
+void TableEventConsoleReplication::answerQuery(Query *query) {
+ query->processDataset(nullptr);
+}
diff --git a/livestatus/src/TableEventConsoleReplication.h
b/livestatus/src/TableEventConsoleReplication.h
index c19a553..301ba11 100644
--- a/livestatus/src/TableEventConsoleReplication.h
+++ b/livestatus/src/TableEventConsoleReplication.h
@@ -27,11 +27,16 @@
#include "config.h" // IWYU pragma: keep
#include "Table.h"
+class Core;
class Query;
class TableEventConsoleReplication : public Table {
public:
- TableEventConsoleReplication();
+ TableEventConsoleReplication(
+#ifdef CMC
+ Core *core
+#endif
+ );
const char *name() const override;
const char *namePrefix() const override;
void answerQuery(Query *query) override;