Module: check_mk
Branch: master
Commit: 747403c359cafcb50f496da3f692094d6762df34
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=747403c359cafc…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Apr 8 09:56:02 2019 +0200
Pass MonitoringCore through to CustomVariableExpander::expand.
This is where we will need it later.
Change-Id: I3af0cb7b29a210eac7a0c8b16bc830e7afaffa81
---
livestatus/src/OffsetStringHostMacroColumn.cc | 6 +++---
livestatus/src/OffsetStringHostMacroColumn.h | 2 +-
livestatus/src/OffsetStringMacroColumn.cc | 6 ++++--
livestatus/src/OffsetStringMacroColumn.h | 9 ++++++---
livestatus/src/OffsetStringServiceMacroColumn.cc | 9 +++++----
livestatus/src/OffsetStringServiceMacroColumn.h | 2 +-
6 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/livestatus/src/OffsetStringHostMacroColumn.cc
b/livestatus/src/OffsetStringHostMacroColumn.cc
index 659eef3..fe5ca07 100644
--- a/livestatus/src/OffsetStringHostMacroColumn.cc
+++ b/livestatus/src/OffsetStringHostMacroColumn.cc
@@ -26,8 +26,8 @@
#include "Row.h"
#include "nagios.h"
-HostMacroExpander::HostMacroExpander(const host *hst)
- : _hst(hst), _cve("_HOST", hst->custom_variables) {}
+HostMacroExpander::HostMacroExpander(const host *hst, const MonitoringCore *mc)
+ : _hst(hst), _cve("_HOST", hst->custom_variables, mc) {}
std::optional<std::string> HostMacroExpander::expand(const std::string &str) {
if (str == "HOSTNAME") {
@@ -64,6 +64,6 @@ std::optional<std::string> HostMacroExpander::expand(const
std::string &str) {
std::unique_ptr<MacroExpander> OffsetStringHostMacroColumn::getMacroExpander(
Row row) const {
return std::make_unique<CompoundMacroExpander>(
- std::make_unique<HostMacroExpander>(columnData<host>(row)),
+ std::make_unique<HostMacroExpander>(columnData<host>(row), _mc),
std::make_unique<UserMacroExpander>());
}
diff --git a/livestatus/src/OffsetStringHostMacroColumn.h
b/livestatus/src/OffsetStringHostMacroColumn.h
index b1cef0f..23c6300 100644
--- a/livestatus/src/OffsetStringHostMacroColumn.h
+++ b/livestatus/src/OffsetStringHostMacroColumn.h
@@ -36,7 +36,7 @@ class Row;
class HostMacroExpander : public MacroExpander {
public:
- explicit HostMacroExpander(const host *hst);
+ HostMacroExpander(const host *hst, const MonitoringCore *mc);
std::optional<std::string> expand(const std::string &str) override;
private:
diff --git a/livestatus/src/OffsetStringMacroColumn.cc
b/livestatus/src/OffsetStringMacroColumn.cc
index c96b7a0..59c36e8 100644
--- a/livestatus/src/OffsetStringMacroColumn.cc
+++ b/livestatus/src/OffsetStringMacroColumn.cc
@@ -59,11 +59,13 @@ std::optional<std::string> UserMacroExpander::expand(const
std::string &str) {
}
CustomVariableExpander::CustomVariableExpander(std::string prefix,
- const customvariablesmember *cvm)
- : _prefix(std::move(prefix)), _cvm(cvm) {}
+ const customvariablesmember *cvm,
+ const MonitoringCore *mc)
+ : _prefix(std::move(prefix)), _mc(mc), _cvm(cvm) {}
std::optional<std::string> CustomVariableExpander::expand(
const std::string &str) {
+ (void)_mc;
if (mk::starts_with(str, _prefix)) {
RegExp regExp(str.substr(_prefix.size()), RegExp::Case::ignore,
RegExp::Syntax::literal);
diff --git a/livestatus/src/OffsetStringMacroColumn.h
b/livestatus/src/OffsetStringMacroColumn.h
index c46efcb..f1309ec 100644
--- a/livestatus/src/OffsetStringMacroColumn.h
+++ b/livestatus/src/OffsetStringMacroColumn.h
@@ -61,13 +61,14 @@ public:
class CustomVariableExpander : public MacroExpander {
public:
- CustomVariableExpander(std::string prefix,
- const customvariablesmember *cvm);
+ CustomVariableExpander(std::string prefix, const customvariablesmember *cvm,
+ const MonitoringCore *mc);
std::optional<std::string> expand(const std::string &str) override;
private:
std::string _prefix;
+ const MonitoringCore *const _mc;
const customvariablesmember *_cvm;
};
@@ -86,8 +87,10 @@ public:
virtual std::unique_ptr<MacroExpander> getMacroExpander(Row row) const = 0;
-private:
+protected:
const MonitoringCore *const _mc;
+
+private:
const int _string_offset;
};
diff --git a/livestatus/src/OffsetStringServiceMacroColumn.cc
b/livestatus/src/OffsetStringServiceMacroColumn.cc
index 490f48b..6ec404c 100644
--- a/livestatus/src/OffsetStringServiceMacroColumn.cc
+++ b/livestatus/src/OffsetStringServiceMacroColumn.cc
@@ -28,8 +28,9 @@
#include "Row.h"
#include "nagios.h"
-ServiceMacroExpander::ServiceMacroExpander(const service *svc)
- : _svc(svc), _cve("_SERVICE", svc->custom_variables) {}
+ServiceMacroExpander::ServiceMacroExpander(const service *svc,
+ const MonitoringCore *mc)
+ : _svc(svc), _cve("_SERVICE", svc->custom_variables, mc) {}
std::optional<std::string> ServiceMacroExpander::expand(
const std::string &str) {
@@ -62,8 +63,8 @@ std::unique_ptr<MacroExpander>
OffsetStringServiceMacroColumn::getMacroExpander(
Row row) const {
auto svc = columnData<service>(row);
return std::make_unique<CompoundMacroExpander>(
- std::make_unique<HostMacroExpander>(svc->host_ptr),
+ std::make_unique<HostMacroExpander>(svc->host_ptr, _mc),
std::make_unique<CompoundMacroExpander>(
- std::make_unique<ServiceMacroExpander>(svc),
+ std::make_unique<ServiceMacroExpander>(svc, _mc),
std::make_unique<UserMacroExpander>()));
}
diff --git a/livestatus/src/OffsetStringServiceMacroColumn.h
b/livestatus/src/OffsetStringServiceMacroColumn.h
index 4001f1a..590d347 100644
--- a/livestatus/src/OffsetStringServiceMacroColumn.h
+++ b/livestatus/src/OffsetStringServiceMacroColumn.h
@@ -36,7 +36,7 @@ class Row;
class ServiceMacroExpander : public MacroExpander {
public:
- explicit ServiceMacroExpander(const service *svc);
+ ServiceMacroExpander(const service *svc, const MonitoringCore *mc);
std::optional<std::string> expand(const std::string &str) override;
private: