Module: check_mk
Branch: master
Commit: 992f13575686d7f83b9a837353ed7e7c47e7fb49
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=992f13575686d7…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Nov 14 08:19:29 2017 +0100
5458 FIX Enable filtering on columns with macros when the Nagios core is used
Some host/service columns (check_command, notes, notes_url, action_url,
icon_image) can contain macros, and they have a corresponding "..._expanded"
column with those macros already expanded. Previously, it was not possible
to use filters on those expanded columns when the Nagios core was used.
This has been fixed.
Change-Id: Id8d6a43c4420cb5be20a12498e7c7a857af76566
---
.werks/5458 | 14 +++++++++++
livestatus/src/OffsetStringMacroColumn.cc | 40 ++++++++++---------------------
livestatus/src/OffsetStringMacroColumn.h | 21 +++++-----------
3 files changed, 32 insertions(+), 43 deletions(-)
diff --git a/.werks/5458 b/.werks/5458
new file mode 100644
index 0000000..3ebdc2b
--- /dev/null
+++ b/.werks/5458
@@ -0,0 +1,14 @@
+Title: Enable filtering on columns with macros when the Nagios core is used
+Level: 1
+Component: livestatus
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1510645640
+Class: fix
+
+Some host/service columns (check_command, notes, notes_url, action_url,
+icon_image) can contain macros, and they have a corresponding "..._expanded"
+column with those macros already expanded. Previously, it was not possible
+to use filters on those expanded columns when the Nagios core was used.
+This has been fixed.
diff --git a/livestatus/src/OffsetStringMacroColumn.cc
b/livestatus/src/OffsetStringMacroColumn.cc
index adc8bfb..2af859d 100644
--- a/livestatus/src/OffsetStringMacroColumn.cc
+++ b/livestatus/src/OffsetStringMacroColumn.cc
@@ -25,36 +25,25 @@
#include "OffsetStringMacroColumn.h"
#include <cstdlib>
#include <cstring>
-#include <memory>
-#include <vector>
-#include "AndingFilter.h"
#include "Column.h"
-#include "Filter.h"
-#include "Logger.h"
-#include "Renderer.h"
#include "Row.h"
-extern char *macro_user[MAX_USER_MACROS];
-
std::string OffsetStringMacroColumn::getValue(Row row) const {
if (auto p = columnData<void>(row)) {
auto s = offset_cast<const char *>(p, _string_offset);
- return *s == nullptr ? "" : *s;
+ return *s == nullptr ? ""
+ : expandMacros(*s, getHost(row), getService(row));
}
return "";
}
-void OffsetStringMacroColumn::output(
- Row row, RowRenderer &r, const contact * /*auth_user*/,
- std::chrono::seconds /*timezone_offset*/) const {
- std::string raw = getValue(row);
- const host *hst = getHost(row);
- const service *svc = getService(row);
-
+// static
+std::string OffsetStringMacroColumn::expandMacros(const std::string &raw,
+ const host *hst,
+ const service *svc) {
// search for macro names, beginning with $
std::string result;
const char *scan = raw.c_str();
-
while (*scan != 0) {
const char *dollar = strchr(scan, '$');
if (dollar == nullptr) {
@@ -78,20 +67,13 @@ void OffsetStringMacroColumn::output(
}
scan = otherdollar + 1;
}
- r.output(result);
-}
-
-std::unique_ptr<Filter> OffsetStringMacroColumn::createFilter(
- RelationalOperator /*unused */, const std::string & /*unused*/) const {
- Informational(logger())
- << "Sorry. No filtering on macro columns implemented yet";
- return std::make_unique<AndingFilter>(
- std::vector<std::unique_ptr<Filter>>());
+ return result;
}
+// static
const char *OffsetStringMacroColumn::expandMacro(const char *macroname,
const host *hst,
- const service *svc) const {
+ const service *svc) {
// host macros
if (strcmp(macroname, "HOSTNAME") == 0) {
return hst->name;
@@ -158,6 +140,7 @@ const char *OffsetStringMacroColumn::expandMacro(const char
*macroname,
if (strncmp(macroname, "USER", 4) == 0) {
int n = atoi(macroname + 4);
if (n > 0 && n <= MAX_USER_MACROS) {
+ extern char *macro_user[MAX_USER_MACROS];
return macro_user[n - 1];
}
}
@@ -165,8 +148,9 @@ const char *OffsetStringMacroColumn::expandMacro(const char
*macroname,
return nullptr;
}
+// static
const char *OffsetStringMacroColumn::expandCustomVariables(
- const char *varname, const customvariablesmember *custvars) const {
+ const char *varname, const customvariablesmember *custvars) {
for (; custvars != nullptr; custvars = custvars->next) {
if (strcasecmp(varname, custvars->variable_name) == 0) {
return custvars->variable_value;
diff --git a/livestatus/src/OffsetStringMacroColumn.h
b/livestatus/src/OffsetStringMacroColumn.h
index 5421b8a..0530db4 100644
--- a/livestatus/src/OffsetStringMacroColumn.h
+++ b/livestatus/src/OffsetStringMacroColumn.h
@@ -26,15 +26,10 @@
#define OffsetStringMacroColumn_h
#include "config.h" // IWYU pragma: keep
-#include <chrono>
-#include <memory>
#include <string>
#include "StringColumn.h"
#include "nagios.h"
-#include "opids.h"
-class Filter;
class Row;
-class RowRenderer;
class OffsetStringMacroColumn : public StringColumn {
public:
@@ -48,22 +43,18 @@ public:
std::string getValue(Row row) const override;
- void output(Row row, RowRenderer &r, const contact *auth_user,
- std::chrono::seconds timezone_offset) const override;
- std::unique_ptr<Filter> createFilter(
- RelationalOperator relOp, const std::string &value) const override;
-
- // overriden by host and service macro columns
virtual const host *getHost(Row) const = 0;
virtual const service *getService(Row) const = 0;
private:
const int _string_offset;
- const char *expandMacro(const char *macroname, const host *hst,
- const service *svc) const;
- const char *expandCustomVariables(
- const char *varname, const customvariablesmember *custvars) const;
+ static std::string expandMacros(const std::string &raw, const host *hst,
+ const service *svc);
+ static const char *expandMacro(const char *macroname, const host *hst,
+ const service *svc);
+ static const char *expandCustomVariables(
+ const char *varname, const customvariablesmember *custvars);
};
#endif // OffsetStringMacroColumn_h