From 91901eafd8d607241363e481440786ef32b7ab78 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 30 Sep 2020 16:16:53 +0200 Subject: [PATCH 1/4] Introduce EnvResolver refs #6259 --- lib/icinga/CMakeLists.txt | 1 + lib/icinga/envresolver.cpp | 20 ++++++++++++++++++++ lib/icinga/envresolver.hpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/icinga/envresolver.cpp create mode 100644 lib/icinga/envresolver.hpp diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index 7079d84e5..62077bce7 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -41,6 +41,7 @@ set(icinga_SOURCES customvarobject.cpp customvarobject.hpp customvarobject-ti.hpp dependency.cpp dependency.hpp dependency-ti.hpp dependency-apply.cpp downtime.cpp downtime.hpp downtime-ti.hpp + envresolver.cpp envresolver.hpp eventcommand.cpp eventcommand.hpp eventcommand-ti.hpp externalcommandprocessor.cpp externalcommandprocessor.hpp host.cpp host.hpp host-ti.hpp diff --git a/lib/icinga/envresolver.cpp b/lib/icinga/envresolver.cpp new file mode 100644 index 000000000..633255c86 --- /dev/null +++ b/lib/icinga/envresolver.cpp @@ -0,0 +1,20 @@ +/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */ + +#include "base/string.hpp" +#include "base/value.hpp" +#include "icinga/envresolver.hpp" +#include "icinga/checkresult.hpp" +#include + +using namespace icinga; + +bool EnvResolver::ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *result) const +{ + auto value (getenv(macro.CStr())); + + if (value) { + *result = value; + } + + return value; +} diff --git a/lib/icinga/envresolver.hpp b/lib/icinga/envresolver.hpp new file mode 100644 index 000000000..b3f0076fa --- /dev/null +++ b/lib/icinga/envresolver.hpp @@ -0,0 +1,30 @@ +/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */ + +#ifndef ENVRESOLVER_H +#define ENVRESOLVER_H + +#include "base/object.hpp" +#include "base/string.hpp" +#include "base/value.hpp" +#include "icinga/macroresolver.hpp" +#include "icinga/checkresult.hpp" + +namespace icinga +{ + +/** + * Resolves env var names. + * + * @ingroup icinga + */ +class EnvResolver final : public Object, public MacroResolver +{ +public: + DECLARE_PTR_TYPEDEFS(EnvResolver); + + bool ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *result) const override; +}; + +} + +#endif /* ENVRESOLVER_H */ From a309b4a41568f3da3426c12d89eb2da7b70a274a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 30 Sep 2020 16:35:47 +0200 Subject: [PATCH 2/4] ResolverSpec: add option not to resolve "$name$" but only "$host.name$". --- lib/icinga/macroprocessor.cpp | 13 ++++++++----- lib/icinga/macroprocessor.hpp | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index 6fd30581c..8f9b19b3b 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -89,11 +89,14 @@ bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resol } for (const ResolverSpec& resolver : resolvers) { - if (!objName.IsEmpty() && objName != resolver.first) + if (!objName.IsEmpty() && objName != resolver.Name) continue; if (objName.IsEmpty()) { - CustomVarObject::Ptr dobj = dynamic_pointer_cast(resolver.second); + if (!resolver.ResolveShortMacros) + continue; + + CustomVarObject::Ptr dobj = dynamic_pointer_cast(resolver.Obj); if (dobj) { Dictionary::Ptr vars = dobj->GetVars(); @@ -106,12 +109,12 @@ bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resol } } - auto *mresolver = dynamic_cast(resolver.second.get()); + auto *mresolver = dynamic_cast(resolver.Obj.get()); if (mresolver && mresolver->ResolveMacro(boost::algorithm::join(tokens, "."), cr, result)) return true; - Value ref = resolver.second; + Value ref = resolver.Obj; bool valid = true; for (const String& token : tokens) { @@ -172,7 +175,7 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver Dictionary::Ptr resolvers_this = new Dictionary(); for (const ResolverSpec& resolver : resolvers) { - resolvers_this->Set(resolver.first, resolver.second); + resolvers_this->Set(resolver.Name, resolver.Obj); } auto internalResolveMacrosShim = [resolvers, cr, resolvedMacros, useResolvedMacros, recursionLevel](const std::vector& args) { diff --git a/lib/icinga/macroprocessor.hpp b/lib/icinga/macroprocessor.hpp index d6c16107a..7e7482153 100644 --- a/lib/icinga/macroprocessor.hpp +++ b/lib/icinga/macroprocessor.hpp @@ -7,6 +7,7 @@ #include "icinga/checkable.hpp" #include "base/value.hpp" #include +#include namespace icinga { @@ -19,8 +20,21 @@ namespace icinga class MacroProcessor { public: + struct ResolverSpec + { + String Name; + Object::Ptr Obj; + + // Whether to resolve not only e.g. $host.address$, but also just $address$ + bool ResolveShortMacros; + + inline ResolverSpec(String name, Object::Ptr obj, bool resolveShortMacros = true) + : Name(std::move(name)), Obj(std::move(obj)), ResolveShortMacros(resolveShortMacros) + { + } + }; + typedef std::function EscapeCallback; - typedef std::pair ResolverSpec; typedef std::vector ResolverList; static Value ResolveMacros(const Value& str, const ResolverList& resolvers, From b2b49caf6176e46a2ac63a4195216f517dc518fb Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 6 Feb 2023 16:35:38 +0100 Subject: [PATCH 3/4] Macros: support $env.ENV_VAR_NAME$ refs #6259 --- doc/03-monitoring-basics.md | 7 +++++++ lib/db_ido/idochecktask.cpp | 2 ++ lib/icinga/apiactions.cpp | 2 ++ lib/icingadb/icingadbchecktask.cpp | 2 ++ lib/livestatus/hoststable.cpp | 13 +++++++++---- lib/livestatus/servicestable.cpp | 13 +++++++++---- lib/methods/clusterzonechecktask.cpp | 2 ++ lib/methods/dummychecktask.cpp | 2 ++ lib/methods/icingachecktask.cpp | 2 ++ lib/methods/pluginchecktask.cpp | 2 ++ lib/methods/plugineventtask.cpp | 2 ++ lib/methods/pluginnotificationtask.cpp | 2 ++ lib/methods/sleepchecktask.cpp | 2 ++ lib/perfdata/graphitewriter.cpp | 2 ++ lib/perfdata/influxdbcommonwriter.cpp | 2 ++ lib/perfdata/opentsdbwriter.cpp | 2 ++ lib/perfdata/perfdatawriter.cpp | 2 ++ 17 files changed, 53 insertions(+), 8 deletions(-) diff --git a/doc/03-monitoring-basics.md b/doc/03-monitoring-basics.md index 672c026ff..79ef8cc5d 100644 --- a/doc/03-monitoring-basics.md +++ b/doc/03-monitoring-basics.md @@ -664,6 +664,13 @@ The following macros provide global statistics: icinga.num\_hosts\_in\_downtime | Current number of hosts in downtime. icinga.num\_hosts\_acknowledged | Current number of acknowledged host problems. +### Environment Variable Runtime Macros + +All environment variables of the Icinga process are available as runtime macros +named `env.`. E.g. `$env.ProgramFiles$` for ProgramFiles which is +especially useful on Windows. In contrast to the other runtime macros env vars +require the `env.` prefix. + ## Apply Rules diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index 6a7f0d363..d3b456963 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "db_ido/idochecktask.hpp" +#include "icinga/envresolver.hpp" #include "icinga/host.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -61,6 +62,7 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); String idoType = MacroProcessor::ResolveMacros("$ido_type$", resolvers, checkable->GetLastCheckResult(), nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index ff3c6506d..2b9de044d 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -2,6 +2,7 @@ #include "icinga/apiactions.hpp" #include "icinga/checkable.hpp" +#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/servicegroup.hpp" #include "icinga/hostgroup.hpp" @@ -668,6 +669,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons resolvers.emplace_back("host", host); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); String resolved_endpoint = MacroProcessor::ResolveMacros( endpoint, resolvers, checkable->GetLastCheckResult(), diff --git a/lib/icingadb/icingadbchecktask.cpp b/lib/icingadb/icingadbchecktask.cpp index c2f1a3699..4e2bb5f16 100644 --- a/lib/icingadb/icingadbchecktask.cpp +++ b/lib/icingadb/icingadbchecktask.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2022 Icinga GmbH | GPLv2+ */ #include "icingadb/icingadbchecktask.hpp" +#include "icinga/envresolver.hpp" #include "icinga/host.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -62,6 +63,7 @@ void IcingadbCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckR resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); auto resolve ([&](const String& macro) { return MacroProcessor::ResolveMacros(macro, resolvers, checkable->GetLastCheckResult(), diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index ad049edbe..edf921c72 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -3,6 +3,7 @@ #include "livestatus/hoststable.hpp" #include "livestatus/hostgroupstable.hpp" #include "livestatus/endpointstable.hpp" +#include "icinga/envresolver.hpp" #include "icinga/host.hpp" #include "icinga/service.hpp" #include "icinga/hostgroup.hpp" @@ -315,7 +316,8 @@ Value HostsTable::NotesExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "host", host }, - { "icinga", IcingaApplication::GetInstance() } + { "icinga", IcingaApplication::GetInstance() }, + { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(host->GetNotes(), resolvers); @@ -340,7 +342,8 @@ Value HostsTable::NotesUrlExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "host", host }, - { "icinga", IcingaApplication::GetInstance() } + { "icinga", IcingaApplication::GetInstance() }, + { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(host->GetNotesUrl(), resolvers); @@ -365,7 +368,8 @@ Value HostsTable::ActionUrlExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "host", host }, - { "icinga", IcingaApplication::GetInstance() } + { "icinga", IcingaApplication::GetInstance() }, + { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(host->GetActionUrl(), resolvers); @@ -422,7 +426,8 @@ Value HostsTable::IconImageExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "host", host }, - { "icinga", IcingaApplication::GetInstance() } + { "icinga", IcingaApplication::GetInstance() }, + { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(host->GetIconImage(), resolvers); diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index bb5d4fb81..f472e0ff0 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -9,6 +9,7 @@ #include "icinga/servicegroup.hpp" #include "icinga/hostgroup.hpp" #include "icinga/checkcommand.hpp" +#include "icinga/envresolver.hpp" #include "icinga/eventcommand.hpp" #include "icinga/timeperiod.hpp" #include "icinga/macroprocessor.hpp" @@ -372,7 +373,8 @@ Value ServicesTable::NotesExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "service", service }, { "host", service->GetHost() }, - { "icinga", IcingaApplication::GetInstance() } + { "icinga", IcingaApplication::GetInstance() }, + { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers); @@ -398,7 +400,8 @@ Value ServicesTable::NotesUrlExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "service", service }, { "host", service->GetHost() }, - { "icinga", IcingaApplication::GetInstance() } + { "icinga", IcingaApplication::GetInstance() }, + { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers); @@ -424,7 +427,8 @@ Value ServicesTable::ActionUrlExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "service", service }, { "host", service->GetHost() }, - { "icinga", IcingaApplication::GetInstance() } + { "icinga", IcingaApplication::GetInstance() }, + { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers); @@ -450,7 +454,8 @@ Value ServicesTable::IconImageExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "service", service }, { "host", service->GetHost() }, - { "icinga", IcingaApplication::GetInstance() } + { "icinga", IcingaApplication::GetInstance() }, + { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers); diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 983719795..838d94422 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -2,6 +2,7 @@ #include "methods/clusterzonechecktask.hpp" #include "icinga/checkcommand.hpp" +#include "icinga/envresolver.hpp" #include "icinga/macroprocessor.hpp" #include "remote/apilistener.hpp" #include "remote/endpoint.hpp" @@ -64,6 +65,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che resolvers.emplace_back("host", host); resolvers.emplace_back("command", command); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(), nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/methods/dummychecktask.cpp b/lib/methods/dummychecktask.cpp index 561415c64..2f9a27286 100644 --- a/lib/methods/dummychecktask.cpp +++ b/lib/methods/dummychecktask.cpp @@ -4,6 +4,7 @@ # include #endif /* _WIN32 */ #include "methods/dummychecktask.hpp" +#include "icinga/envresolver.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/pluginutility.hpp" #include "base/utility.hpp" @@ -38,6 +39,7 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu resolvers.emplace_back("host", host); resolvers.emplace_back("command", command); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(), nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 40795495d..5662f9cbd 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -2,6 +2,7 @@ #include "methods/icingachecktask.hpp" #include "icinga/cib.hpp" +#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -42,6 +43,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes resolvers.emplace_back("host", host); resolvers.emplace_back("command", command); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); String missingIcingaMinVersion; diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 9bfa72203..2710c01c1 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "methods/pluginchecktask.hpp" +#include "icinga/envresolver.hpp" #include "icinga/pluginutility.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -38,6 +39,7 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); int timeout = commandObj->GetTimeout(); diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 8b2fc44ac..76204d6ec 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "methods/plugineventtask.hpp" +#include "icinga/envresolver.hpp" #include "icinga/eventcommand.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/pluginutility.hpp" @@ -37,6 +38,7 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); int timeout = commandObj->GetTimeout(); std::function callback; diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 17f34cda8..09880e973 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "methods/pluginnotificationtask.hpp" +#include "icinga/envresolver.hpp" #include "icinga/notification.hpp" #include "icinga/notificationcommand.hpp" #include "icinga/pluginutility.hpp" @@ -54,6 +55,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); int timeout = commandObj->GetTimeout(); std::function callback; diff --git a/lib/methods/sleepchecktask.cpp b/lib/methods/sleepchecktask.cpp index a018de46b..61bb91794 100644 --- a/lib/methods/sleepchecktask.cpp +++ b/lib/methods/sleepchecktask.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "methods/sleepchecktask.hpp" +#include "icinga/envresolver.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/pluginutility.hpp" #include "base/utility.hpp" @@ -34,6 +35,7 @@ void SleepCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); double sleepTime = MacroProcessor::ResolveMacros("$sleep_time$", resolvers, checkable->GetLastCheckResult(), nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 4b9424e80..4ea12dcdf 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -2,6 +2,7 @@ #include "perfdata/graphitewriter.hpp" #include "perfdata/graphitewriter-ti.cpp" +#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -294,6 +295,7 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); String prefix; diff --git a/lib/perfdata/influxdbcommonwriter.cpp b/lib/perfdata/influxdbcommonwriter.cpp index 42b7f02b7..1490ffb10 100644 --- a/lib/perfdata/influxdbcommonwriter.cpp +++ b/lib/perfdata/influxdbcommonwriter.cpp @@ -3,6 +3,7 @@ #include "perfdata/influxdbcommonwriter.hpp" #include "perfdata/influxdbcommonwriter-ti.cpp" #include "remote/url.hpp" +#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" @@ -225,6 +226,7 @@ void InfluxdbCommonWriter::CheckResultHandlerWQ(const Checkable::Ptr& checkable, resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); String prefix; diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index 066377ab1..4291a4fe5 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -2,6 +2,7 @@ #include "perfdata/opentsdbwriter.hpp" #include "perfdata/opentsdbwriter-ti.cpp" +#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -196,6 +197,7 @@ void OpenTsdbWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); // Resolve macros for the service and host template config line if (config_tmpl_tags) { diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 77652b1da..711f9e193 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -2,6 +2,7 @@ #include "perfdata/perfdatawriter.hpp" #include "perfdata/perfdatawriter-ti.cpp" +#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" @@ -117,6 +118,7 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); + resolvers.emplace_back("env", new EnvResolver(), false); if (service) { String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, nullptr, &PerfdataWriter::EscapeMacroMetric); From f2974c07cffa90c9da20486a2699fd39e18ef338 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 17 Feb 2023 15:33:36 +0100 Subject: [PATCH 4/4] Centralise default icinga.* and env.* macros --- lib/db_ido/idochecktask.cpp | 3 - lib/icinga/apiactions.cpp | 3 - lib/icinga/macroprocessor.cpp | 155 ++++++++++++++----------- lib/icingadb/icingadbchecktask.cpp | 3 - lib/livestatus/hoststable.cpp | 10 -- lib/livestatus/servicestable.cpp | 10 -- lib/methods/clusterzonechecktask.cpp | 3 - lib/methods/dummychecktask.cpp | 4 - lib/methods/icingachecktask.cpp | 4 - lib/methods/pluginchecktask.cpp | 4 - lib/methods/plugineventtask.cpp | 4 - lib/methods/pluginnotificationtask.cpp | 4 - lib/methods/sleepchecktask.cpp | 4 - lib/perfdata/graphitewriter.cpp | 3 - lib/perfdata/influxdbcommonwriter.cpp | 3 - lib/perfdata/opentsdbwriter.cpp | 5 +- lib/perfdata/perfdatawriter.cpp | 3 - 17 files changed, 88 insertions(+), 137 deletions(-) diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index d3b456963..3b5856a65 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -1,7 +1,6 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "db_ido/idochecktask.hpp" -#include "icinga/envresolver.hpp" #include "icinga/host.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -61,8 +60,6 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); String idoType = MacroProcessor::ResolveMacros("$ido_type$", resolvers, checkable->GetLastCheckResult(), nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 2b9de044d..1e3fe851f 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -2,7 +2,6 @@ #include "icinga/apiactions.hpp" #include "icinga/checkable.hpp" -#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/servicegroup.hpp" #include "icinga/hostgroup.hpp" @@ -668,8 +667,6 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); String resolved_endpoint = MacroProcessor::ResolveMacros( endpoint, resolvers, checkable->GetLastCheckResult(), diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index 8f9b19b3b..97f0affe0 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -3,6 +3,8 @@ #include "icinga/macroprocessor.hpp" #include "icinga/macroresolver.hpp" #include "icinga/customvarobject.hpp" +#include "icinga/envresolver.hpp" +#include "icinga/icingaapplication.hpp" #include "base/array.hpp" #include "base/objectlock.hpp" #include "base/logger.hpp" @@ -73,6 +75,16 @@ Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolv return result; } +static const EnvResolver::Ptr l_EnvResolver = new EnvResolver(); + +static MacroProcessor::ResolverList GetDefaultResolvers() +{ + return { + { "icinga", IcingaApplication::GetInstance() }, + { "env", l_EnvResolver, false } + }; +} + bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resolvers, const CheckResult::Ptr& cr, Value *result, bool *recursive_macro) { @@ -88,80 +100,84 @@ bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resol tokens.erase(tokens.begin()); } - for (const ResolverSpec& resolver : resolvers) { - if (!objName.IsEmpty() && objName != resolver.Name) - continue; + const auto defaultResolvers (GetDefaultResolvers()); - if (objName.IsEmpty()) { - if (!resolver.ResolveShortMacros) + for (auto resolverList : {&resolvers, &defaultResolvers}) { + for (auto& resolver : *resolverList) { + if (!objName.IsEmpty() && objName != resolver.Name) continue; - CustomVarObject::Ptr dobj = dynamic_pointer_cast(resolver.Obj); - - if (dobj) { - Dictionary::Ptr vars = dobj->GetVars(); - - if (vars && vars->Contains(macro)) { - *result = vars->Get(macro); - *recursive_macro = true; - return true; - } - } - } - - auto *mresolver = dynamic_cast(resolver.Obj.get()); - - if (mresolver && mresolver->ResolveMacro(boost::algorithm::join(tokens, "."), cr, result)) - return true; - - Value ref = resolver.Obj; - bool valid = true; - - for (const String& token : tokens) { - if (ref.IsObjectType()) { - Dictionary::Ptr dict = ref; - if (dict->Contains(token)) { - ref = dict->Get(token); + if (objName.IsEmpty()) { + if (!resolver.ResolveShortMacros) continue; - } else { - valid = false; - break; + + CustomVarObject::Ptr dobj = dynamic_pointer_cast(resolver.Obj); + + if (dobj) { + Dictionary::Ptr vars = dobj->GetVars(); + + if (vars && vars->Contains(macro)) { + *result = vars->Get(macro); + *recursive_macro = true; + return true; + } } - } else if (ref.IsObject()) { - Object::Ptr object = ref; - - Type::Ptr type = object->GetReflectionType(); - - if (!type) { - valid = false; - break; - } - - int field = type->GetFieldId(token); - - if (field == -1) { - valid = false; - break; - } - - ref = object->GetField(field); - - Field fieldInfo = type->GetFieldInfo(field); - - if (strcmp(fieldInfo.TypeName, "Timestamp") == 0) - ref = static_cast(ref); } - } - if (valid) { - if (tokens[0] == "vars" || - tokens[0] == "action_url" || - tokens[0] == "notes_url" || - tokens[0] == "notes") - *recursive_macro = true; + auto *mresolver = dynamic_cast(resolver.Obj.get()); - *result = ref; - return true; + if (mresolver && mresolver->ResolveMacro(boost::algorithm::join(tokens, "."), cr, result)) + return true; + + Value ref = resolver.Obj; + bool valid = true; + + for (const String& token : tokens) { + if (ref.IsObjectType()) { + Dictionary::Ptr dict = ref; + if (dict->Contains(token)) { + ref = dict->Get(token); + continue; + } else { + valid = false; + break; + } + } else if (ref.IsObject()) { + Object::Ptr object = ref; + + Type::Ptr type = object->GetReflectionType(); + + if (!type) { + valid = false; + break; + } + + int field = type->GetFieldId(token); + + if (field == -1) { + valid = false; + break; + } + + ref = object->GetField(field); + + Field fieldInfo = type->GetFieldInfo(field); + + if (strcmp(fieldInfo.TypeName, "Timestamp") == 0) + ref = static_cast(ref); + } + } + + if (valid) { + if (tokens[0] == "vars" || + tokens[0] == "action_url" || + tokens[0] == "notes_url" || + tokens[0] == "notes") + *recursive_macro = true; + + *result = ref; + return true; + } } } @@ -173,9 +189,12 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel) { Dictionary::Ptr resolvers_this = new Dictionary(); + const auto defaultResolvers (GetDefaultResolvers()); - for (const ResolverSpec& resolver : resolvers) { - resolvers_this->Set(resolver.Name, resolver.Obj); + for (auto resolverList : {&resolvers, &defaultResolvers}) { + for (auto& resolver: *resolverList) { + resolvers_this->Set(resolver.Name, resolver.Obj); + } } auto internalResolveMacrosShim = [resolvers, cr, resolvedMacros, useResolvedMacros, recursionLevel](const std::vector& args) { diff --git a/lib/icingadb/icingadbchecktask.cpp b/lib/icingadb/icingadbchecktask.cpp index 4e2bb5f16..f7c596457 100644 --- a/lib/icingadb/icingadbchecktask.cpp +++ b/lib/icingadb/icingadbchecktask.cpp @@ -1,7 +1,6 @@ /* Icinga 2 | (c) 2022 Icinga GmbH | GPLv2+ */ #include "icingadb/icingadbchecktask.hpp" -#include "icinga/envresolver.hpp" #include "icinga/host.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -62,8 +61,6 @@ void IcingadbCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckR resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); auto resolve ([&](const String& macro) { return MacroProcessor::ResolveMacros(macro, resolvers, checkable->GetLastCheckResult(), diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index edf921c72..d90f4a56e 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -3,7 +3,6 @@ #include "livestatus/hoststable.hpp" #include "livestatus/hostgroupstable.hpp" #include "livestatus/endpointstable.hpp" -#include "icinga/envresolver.hpp" #include "icinga/host.hpp" #include "icinga/service.hpp" #include "icinga/hostgroup.hpp" @@ -11,7 +10,6 @@ #include "icinga/eventcommand.hpp" #include "icinga/timeperiod.hpp" #include "icinga/macroprocessor.hpp" -#include "icinga/icingaapplication.hpp" #include "icinga/compatutility.hpp" #include "icinga/pluginutility.hpp" #include "base/configtype.hpp" @@ -316,8 +314,6 @@ Value HostsTable::NotesExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "host", host }, - { "icinga", IcingaApplication::GetInstance() }, - { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(host->GetNotes(), resolvers); @@ -342,8 +338,6 @@ Value HostsTable::NotesUrlExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "host", host }, - { "icinga", IcingaApplication::GetInstance() }, - { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(host->GetNotesUrl(), resolvers); @@ -368,8 +362,6 @@ Value HostsTable::ActionUrlExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "host", host }, - { "icinga", IcingaApplication::GetInstance() }, - { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(host->GetActionUrl(), resolvers); @@ -426,8 +418,6 @@ Value HostsTable::IconImageExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "host", host }, - { "icinga", IcingaApplication::GetInstance() }, - { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(host->GetIconImage(), resolvers); diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index f472e0ff0..681445aaf 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -9,11 +9,9 @@ #include "icinga/servicegroup.hpp" #include "icinga/hostgroup.hpp" #include "icinga/checkcommand.hpp" -#include "icinga/envresolver.hpp" #include "icinga/eventcommand.hpp" #include "icinga/timeperiod.hpp" #include "icinga/macroprocessor.hpp" -#include "icinga/icingaapplication.hpp" #include "icinga/compatutility.hpp" #include "icinga/pluginutility.hpp" #include "base/configtype.hpp" @@ -373,8 +371,6 @@ Value ServicesTable::NotesExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "service", service }, { "host", service->GetHost() }, - { "icinga", IcingaApplication::GetInstance() }, - { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers); @@ -400,8 +396,6 @@ Value ServicesTable::NotesUrlExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "service", service }, { "host", service->GetHost() }, - { "icinga", IcingaApplication::GetInstance() }, - { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers); @@ -427,8 +421,6 @@ Value ServicesTable::ActionUrlExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "service", service }, { "host", service->GetHost() }, - { "icinga", IcingaApplication::GetInstance() }, - { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers); @@ -454,8 +446,6 @@ Value ServicesTable::IconImageExpandedAccessor(const Value& row) MacroProcessor::ResolverList resolvers { { "service", service }, { "host", service->GetHost() }, - { "icinga", IcingaApplication::GetInstance() }, - { "env", new EnvResolver(), false } }; return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers); diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 838d94422..fd52534c3 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -2,7 +2,6 @@ #include "methods/clusterzonechecktask.hpp" #include "icinga/checkcommand.hpp" -#include "icinga/envresolver.hpp" #include "icinga/macroprocessor.hpp" #include "remote/apilistener.hpp" #include "remote/endpoint.hpp" @@ -64,8 +63,6 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", command); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(), nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/methods/dummychecktask.cpp b/lib/methods/dummychecktask.cpp index 2f9a27286..905a022c3 100644 --- a/lib/methods/dummychecktask.cpp +++ b/lib/methods/dummychecktask.cpp @@ -4,8 +4,6 @@ # include #endif /* _WIN32 */ #include "methods/dummychecktask.hpp" -#include "icinga/envresolver.hpp" -#include "icinga/icingaapplication.hpp" #include "icinga/pluginutility.hpp" #include "base/utility.hpp" #include "base/perfdatavalue.hpp" @@ -38,8 +36,6 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", command); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(), nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 5662f9cbd..d3eae1f33 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -2,11 +2,9 @@ #include "methods/icingachecktask.hpp" #include "icinga/cib.hpp" -#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" -#include "icinga/icingaapplication.hpp" #include "icinga/clusterevents.hpp" #include "icinga/checkable.hpp" #include "remote/apilistener.hpp" @@ -42,8 +40,6 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", command); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); String missingIcingaMinVersion; diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 2710c01c1..b4749fbfd 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -1,11 +1,9 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "methods/pluginchecktask.hpp" -#include "icinga/envresolver.hpp" #include "icinga/pluginutility.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" -#include "icinga/icingaapplication.hpp" #include "base/configtype.hpp" #include "base/logger.hpp" #include "base/function.hpp" @@ -38,8 +36,6 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); int timeout = commandObj->GetTimeout(); diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 76204d6ec..00efb6ce4 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -1,11 +1,9 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "methods/plugineventtask.hpp" -#include "icinga/envresolver.hpp" #include "icinga/eventcommand.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/pluginutility.hpp" -#include "icinga/icingaapplication.hpp" #include "base/configtype.hpp" #include "base/logger.hpp" #include "base/function.hpp" @@ -37,8 +35,6 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); int timeout = commandObj->GetTimeout(); std::function callback; diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 09880e973..a20c971a1 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -1,13 +1,11 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "methods/pluginnotificationtask.hpp" -#include "icinga/envresolver.hpp" #include "icinga/notification.hpp" #include "icinga/notificationcommand.hpp" #include "icinga/pluginutility.hpp" #include "icinga/service.hpp" #include "icinga/macroprocessor.hpp" -#include "icinga/icingaapplication.hpp" #include "base/function.hpp" #include "base/logger.hpp" #include "base/utility.hpp" @@ -54,8 +52,6 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); int timeout = commandObj->GetTimeout(); std::function callback; diff --git a/lib/methods/sleepchecktask.cpp b/lib/methods/sleepchecktask.cpp index 61bb91794..af6b0638e 100644 --- a/lib/methods/sleepchecktask.cpp +++ b/lib/methods/sleepchecktask.cpp @@ -1,8 +1,6 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "methods/sleepchecktask.hpp" -#include "icinga/envresolver.hpp" -#include "icinga/icingaapplication.hpp" #include "icinga/pluginutility.hpp" #include "base/utility.hpp" #include "base/convert.hpp" @@ -34,8 +32,6 @@ void SleepCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); resolvers.emplace_back("command", commandObj); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); double sleepTime = MacroProcessor::ResolveMacros("$sleep_time$", resolvers, checkable->GetLastCheckResult(), nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 4ea12dcdf..19e1209bd 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -2,7 +2,6 @@ #include "perfdata/graphitewriter.hpp" #include "perfdata/graphitewriter-ti.cpp" -#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -294,8 +293,6 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, if (service) resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); String prefix; diff --git a/lib/perfdata/influxdbcommonwriter.cpp b/lib/perfdata/influxdbcommonwriter.cpp index 1490ffb10..0303af09f 100644 --- a/lib/perfdata/influxdbcommonwriter.cpp +++ b/lib/perfdata/influxdbcommonwriter.cpp @@ -3,7 +3,6 @@ #include "perfdata/influxdbcommonwriter.hpp" #include "perfdata/influxdbcommonwriter-ti.cpp" #include "remote/url.hpp" -#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" @@ -225,8 +224,6 @@ void InfluxdbCommonWriter::CheckResultHandlerWQ(const Checkable::Ptr& checkable, if (service) resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); String prefix; diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index 4291a4fe5..e34a2e09e 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -2,7 +2,6 @@ #include "perfdata/opentsdbwriter.hpp" #include "perfdata/opentsdbwriter-ti.cpp" -#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" @@ -196,9 +195,7 @@ void OpenTsdbWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C if (service) resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); - + // Resolve macros for the service and host template config line if (config_tmpl_tags) { ObjectLock olock(config_tmpl_tags); diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 711f9e193..0e99c2728 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -2,7 +2,6 @@ #include "perfdata/perfdatawriter.hpp" #include "perfdata/perfdatawriter-ti.cpp" -#include "icinga/envresolver.hpp" #include "icinga/service.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" @@ -117,8 +116,6 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C if (service) resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); - resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); - resolvers.emplace_back("env", new EnvResolver(), false); if (service) { String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, nullptr, &PerfdataWriter::EscapeMacroMetric);