Module: check_mk
Branch: master
Commit: 9230ef40c0c30e86ce85ffab17b70d4899e0adb7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9230ef40c0c30e…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri May 20 14:57:19 2016 +0200
Fetched livestatus from downstream.
---
livestatus/src/TableEventConsole.cc | 10 +++----
livestatus/src/TableEventConsole.h | 41 ++++++++++++++++++++++++++++-
livestatus/src/TableEventConsoleEvents.cc | 6 ++---
livestatus/src/TableEventConsoleEvents.h | 1 +
4 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/livestatus/src/TableEventConsole.cc b/livestatus/src/TableEventConsole.cc
index daca67c..1121a8b 100644
--- a/livestatus/src/TableEventConsole.cc
+++ b/livestatus/src/TableEventConsole.cc
@@ -67,8 +67,10 @@ string readLine(int sock) {
} while (true);
return line; // unreachable
}
+}; // namespace
-vector<string> split(string str, char delimiter = '\t') {
+// static
+vector<string> TableEventConsole::split(string str, char delimiter) {
istringstream iss(str);
vector<string> result;
string field;
@@ -78,8 +80,6 @@ vector<string> split(string str, char delimiter = '\t') {
return result;
}
-}; // namespace
-
void TableEventConsole::answerQuery(Query *query) {
string path = "/omd/sites/heute/tmp/run/mkeventd/status";
int sock = socket(PF_LOCAL, SOCK_STREAM, 0);
@@ -125,7 +125,7 @@ void TableEventConsole::answerQuery(Query *query) {
bytes_to_write -= bytes_written;
}
- vector<string> headers = split(readLine(sock));
+ vector<string> headers = split(readLine(sock), '\t');
do {
string line = readLine(sock);
@@ -134,7 +134,7 @@ void TableEventConsole::answerQuery(Query *query) {
}
_row_t row;
int i = 0;
- for (const auto &field : split(line)) {
+ for (const auto &field : split(line, '\t')) {
logger(LOG_DEBUG, "setting EC column \"%s\" to
\"%s\"",
headers[i].c_str(), field.c_str());
row[headers[i++]] = field;
diff --git a/livestatus/src/TableEventConsole.h b/livestatus/src/TableEventConsole.h
index 347becb..f6f4314 100644
--- a/livestatus/src/TableEventConsole.h
+++ b/livestatus/src/TableEventConsole.h
@@ -32,12 +32,14 @@
#include <functional>
#include <map>
#include <string>
+#include <vector>
#include "DoubleColumn.h"
#include "IntColumn.h"
+#include "ListColumn.h"
#include "OffsetTimeColumn.h"
+#include "Query.h"
#include "StringColumn.h"
#include "Table.h"
-class Query;
class TableEventConsole : public Table {
public:
@@ -46,6 +48,9 @@ public:
protected:
typedef std::map<std::string, std::string> _row_t;
+ // TODO(sp) Move this to some helper.
+ static std::vector<std::string> split(std::string str, char delimiter);
+
template <typename T>
class EventConsoleColumn {
std::string _name;
@@ -116,6 +121,40 @@ protected:
return _ecc.getValue(data);
}
};
+
+ class ListEventConsoleColumn : public ListColumn {
+ typedef std::vector<std::string> _column_t;
+ EventConsoleColumn<_column_t> _ecc;
+
+ public:
+ ListEventConsoleColumn(std::string name, std::string description)
+ : ListColumn(name, description, -1, -1)
+ , _ecc(name, _column_t(),
+ [](std::string x) { return split(x, '\001'); }) {}
+
+ void output(void *data, Query *query) override {
+ query->outputBeginList();
+ bool first = true;
+ for (const auto &elem : _ecc.getValue(data)) {
+ if (first) {
+ first = false;
+ } else {
+ query->outputListSeparator();
+ }
+ query->outputString(elem.c_str());
+ }
+ query->outputEndList();
+ }
+
+ bool isEmpty(void *data) override {
+ return _ecc.getValue(data).empty();
+ }
+
+ // TODO(sp) We should probably rename the methods below and actually
+ // implement them here for real.
+ void *getNagiosObject(char *) override { return nullptr; }
+ bool isNagiosMember(void *, void *) override { return false; }
+ };
};
#endif // TableEventConsole_h
diff --git a/livestatus/src/TableEventConsoleEvents.cc
b/livestatus/src/TableEventConsoleEvents.cc
index 1361de1..656d26f 100644
--- a/livestatus/src/TableEventConsoleEvents.cc
+++ b/livestatus/src/TableEventConsoleEvents.cc
@@ -23,6 +23,7 @@
// Boston, MA 02110-1301 USA.
#include "TableEventConsoleEvents.h"
+#include "Table.h"
TableEventConsoleEvents::TableEventConsoleEvents() { addColumns(this); }
@@ -67,9 +68,8 @@ void TableEventConsoleEvents::addColumns(Table *table) {
"of open/closed/delayed/counting/ack)"));
table->addColumn(
new StringEventConsoleColumn("event_owner", "The owner of the
event"));
- table->addColumn(new StringEventConsoleColumn(
- "event_match_groups",
- "Text groups from regular expression match")); // list
+ table->addColumn(new ListEventConsoleColumn(
+ "event_match_groups", "Text groups from regular expression
match"));
table->addColumn(new StringEventConsoleColumn("event_contact_groups",
"Contact groups")); // list
table->addColumn(new StringEventConsoleColumn(
diff --git a/livestatus/src/TableEventConsoleEvents.h
b/livestatus/src/TableEventConsoleEvents.h
index 80b174c..287d7f2 100644
--- a/livestatus/src/TableEventConsoleEvents.h
+++ b/livestatus/src/TableEventConsoleEvents.h
@@ -27,6 +27,7 @@
#include "config.h" // IWYU pragma: keep
#include "TableEventConsole.h"
+class Table;
class TableEventConsoleEvents : public TableEventConsole {
public: