Module: check_mk
Branch: master
Commit: e95f01b1539ba26cfb7ee7316daf8b1128433ca8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e95f01b1539ba2…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Jun 6 13:50:14 2016 +0200
Fetched Livestatus from downstream.
---
livestatus/src/DynamicColumn.h | 3 +-
.../src/DynamicEventConsoleReplicationColumn.cc | 4 +-
.../src/DynamicEventConsoleReplicationColumn.h | 5 +-
livestatus/src/DynamicLogwatchFileColumn.cc | 56 +++++---------------
livestatus/src/DynamicLogwatchFileColumn.h | 3 +-
livestatus/src/Table.cc | 32 +++++++----
livestatus/src/Table.h | 10 ++--
livestatus/src/TableEventConsoleReplication.h | 2 +
8 files changed, 53 insertions(+), 62 deletions(-)
diff --git a/livestatus/src/DynamicColumn.h b/livestatus/src/DynamicColumn.h
index f37fcc5..e210d8c 100644
--- a/livestatus/src/DynamicColumn.h
+++ b/livestatus/src/DynamicColumn.h
@@ -35,7 +35,8 @@ public:
int indirect_offset, int extra_offset);
virtual ~DynamicColumn();
std::string name() const;
- virtual Column *createColumn(const std::string &arguments) = 0;
+ virtual Column *createColumn(const std::string &name,
+ const std::string &arguments) = 0;
protected:
const std::string _name;
diff --git a/livestatus/src/DynamicEventConsoleReplicationColumn.cc
b/livestatus/src/DynamicEventConsoleReplicationColumn.cc
index 93034be..73746bc 100644
--- a/livestatus/src/DynamicEventConsoleReplicationColumn.cc
+++ b/livestatus/src/DynamicEventConsoleReplicationColumn.cc
@@ -92,7 +92,7 @@
DynamicEventConsoleReplicationColumn::DynamicEventConsoleReplicationColumn(
}
Column *DynamicEventConsoleReplicationColumn::createColumn(
- const std::string &arguments) {
+ const std::string &name, const std::string &arguments) {
#ifdef CMC
string path = _core->_world->_config->_mkeventd_socket_path;
#else
@@ -100,6 +100,6 @@ Column *DynamicEventConsoleReplicationColumn::createColumn(
#endif
ECTableConnection ec(path, "REPLICATE " + arguments);
ec.run();
- return new ReplicationColumn("replication", "replication value",
-1, -1,
+ return new ReplicationColumn(name, "replication value", -1, -1,
ec.getResult());
}
diff --git a/livestatus/src/DynamicEventConsoleReplicationColumn.h
b/livestatus/src/DynamicEventConsoleReplicationColumn.h
index f9603be..b5b2b86 100644
--- a/livestatus/src/DynamicEventConsoleReplicationColumn.h
+++ b/livestatus/src/DynamicEventConsoleReplicationColumn.h
@@ -29,7 +29,9 @@
#include <string>
#include "DynamicColumn.h"
class Column;
+#ifdef CMC
class Core;
+#endif
class DynamicEventConsoleReplicationColumn : public DynamicColumn {
public:
@@ -41,7 +43,8 @@ public:
Core *core
#endif
);
- Column *createColumn(const std::string &arguments) override;
+ Column *createColumn(const std::string &name,
+ const std::string &arguments) override;
#ifdef CMC
private:
Core *_core;
diff --git a/livestatus/src/DynamicLogwatchFileColumn.cc
b/livestatus/src/DynamicLogwatchFileColumn.cc
index 49c844f..b722a0e 100644
--- a/livestatus/src/DynamicLogwatchFileColumn.cc
+++ b/livestatus/src/DynamicLogwatchFileColumn.cc
@@ -23,16 +23,12 @@
// Boston, MA 02110-1301 USA.
#include "DynamicLogwatchFileColumn.h"
-#include <string.h>
-#include <syslog.h>
-#include <vector>
+#include <ostream>
#include "HostFileColumn.h"
-#include "logger.h"
+#include "Logger.h"
#include "mk_logwatch.h"
-#include "strutil.h"
using std::string;
-using std::vector;
// Replace \\ with \ and \s with space
string unescape_filename(string filename) {
@@ -55,47 +51,23 @@ string unescape_filename(string filename) {
return filename_native;
}
-Column *DynamicLogwatchFileColumn::createColumn(const std::string &arguments) {
- // We expect:
- // COLNAME:FILENAME
-
- // Example:
- // file_contents:var\log\messages
-
- vector<char> args(arguments.begin(), arguments.end());
- args.push_back('\0');
- char *scan = &args[0];
-
- char *colname = next_token(&scan, ':');
- if ((colname == nullptr) || (colname[0] == 0)) {
- logger(LOG_WARNING,
- "Invalid arguments for column %s: missing result column name",
- _name.c_str());
- return nullptr;
- }
-
- // Start time of queried range - UNIX time stamp
- char *filename = scan;
- if ((filename == nullptr) || (filename[0] == 0)) {
- logger(LOG_WARNING,
- "Invalid arguments for column %s: missing file name",
- _name.c_str());
+Column *DynamicLogwatchFileColumn::createColumn(const std::string &name,
+ const std::string &arguments) {
+ // arguments contains a file name
+ if (arguments.empty()) {
+ Warning() << "Invalid arguments for column '" << _name
+ << "': missing file name";
return nullptr;
}
- if (nullptr != strchr(filename, '/')) {
- logger(LOG_WARNING,
- "Invalid arguments for column %s: file name '%s' contains
slash",
- _name.c_str(), filename);
+ if (arguments.find('/') != string::npos) {
+ Warning() << "Invalid arguments for column '" << _name
+ << "': file name '" << arguments <<
"' contains slash";
return nullptr;
}
- string filename_native = unescape_filename(filename);
-
- string suffix("/");
- suffix += filename_native;
-
- return new HostFileColumn(colname, "Contents of logwatch file",
- MK_LOGWATCH_PATH, suffix.c_str(),
+ return new HostFileColumn(name, "Contents of logwatch file",
+ MK_LOGWATCH_PATH,
+ ("/" + unescape_filename(arguments)).c_str(),
_indirect_offset, _extra_offset);
}
diff --git a/livestatus/src/DynamicLogwatchFileColumn.h
b/livestatus/src/DynamicLogwatchFileColumn.h
index a60cf22..9258489 100644
--- a/livestatus/src/DynamicLogwatchFileColumn.h
+++ b/livestatus/src/DynamicLogwatchFileColumn.h
@@ -36,7 +36,8 @@ public:
int indirect_offset, int extra_offset = -1)
: DynamicColumn(name, description, indirect_offset, extra_offset) {}
~DynamicLogwatchFileColumn() {}
- Column *createColumn(const std::string &arguments) override;
+ Column *createColumn(const std::string &name,
+ const std::string &arguments) override;
};
#endif // DynamicLogwatchFileColumn_h
diff --git a/livestatus/src/Table.cc b/livestatus/src/Table.cc
index 0411066..8cb2dea 100644
--- a/livestatus/src/Table.cc
+++ b/livestatus/src/Table.cc
@@ -24,8 +24,10 @@
#include "Table.h"
#include <string.h>
+#include <ostream>
#include "Column.h"
#include "DynamicColumn.h"
+#include "Logger.h"
using std::string;
@@ -63,8 +65,9 @@ Column *Table::column(const char *colname) {
colname += prefix_len;
}
- if (strchr(colname, ':') != nullptr) {
- return dynamicColumn(colname);
+ const char *sep_pos = strchr(colname, ':');
+ if (sep_pos != nullptr) {
+ return dynamicColumn(string(colname, sep_pos), string(sep_pos + 1));
}
// First try exact match...
@@ -83,17 +86,26 @@ Column *Table::column(const char *colname) {
return nullptr;
}
-Column *Table::dynamicColumn(const char *colname_with_args) {
- const char *sep_pos = strchr(colname_with_args, ':');
- string name(colname_with_args, sep_pos - colname_with_args);
+Column *Table::dynamicColumn(const string &name, const string &rest) {
+ auto it = _dynamic_columns.find(name);
+ if (it == _dynamic_columns.end()) {
+ Warning() << "Unknown dynamic column '" << name
<< "'";
+ return nullptr;
+ }
- const char *argstring = sep_pos + 1;
+ auto sep_pos = rest.find(':');
+ if (sep_pos == string::npos) {
+ Warning() << "Missing separator in dynamic column '" <<
name << "'";
+ return nullptr;
+ }
- auto it = _dynamic_columns.find(name);
- if (it != _dynamic_columns.end()) {
- return it->second->createColumn(argstring);
+ string name2 = rest.substr(0, sep_pos);
+ if (name2.empty()) {
+ Warning() << "Empty column name for dynamic column '"
<< name << "'";
+ return nullptr;
}
- return nullptr;
+
+ return it->second->createColumn(name2, rest.substr(sep_pos + 1));
}
bool Table::isAuthorized(contact * /*unused*/, void * /*unused*/) {
diff --git a/livestatus/src/Table.h b/livestatus/src/Table.h
index e02124a..515d59a 100644
--- a/livestatus/src/Table.h
+++ b/livestatus/src/Table.h
@@ -69,10 +69,10 @@ public:
/// \brief Retrieve a column with a give name.
///
/// If the name contains a ':' then we have a dynamic column with column
- /// arguments: The part before the colon is the column name and the part
- /// after it represents the arguments, which are passed to
- /// DynamicColumn::createColumn. This whole mechanism is used to access RRD
- /// metrics data.
+ /// arguments: The part before the colon is the column name of the dynamic
+ /// column and the part after it is the name of the fresh, dynamically
+ /// created column (up to the 2nd ':') and further arguments. This whole
+ /// mechanism is e.g. used to access RRD metrics data.
///
/// \todo This member function is virtual just because TableStateHistory and
/// TableLog override it for some dubious reason: They first try the normal
@@ -85,7 +85,7 @@ public:
virtual void *findObject(char *objectspec);
private:
- Column *dynamicColumn(const char *colname_with_args);
+ Column *dynamicColumn(const std::string &name, const std::string &rest);
std::map<std::string, Column *> _columns;
std::map<std::string, DynamicColumn *> _dynamic_columns;
diff --git a/livestatus/src/TableEventConsoleReplication.h
b/livestatus/src/TableEventConsoleReplication.h
index 558b6e4..cff08d0 100644
--- a/livestatus/src/TableEventConsoleReplication.h
+++ b/livestatus/src/TableEventConsoleReplication.h
@@ -27,7 +27,9 @@
#include "config.h" // IWYU pragma: keep
#include "Table.h"
+#ifdef CMC
class Core;
+#endif
class Query;
class TableEventConsoleReplication : public Table {