diff --git a/doc/4.3-object-types.md b/doc/4.3-object-types.md index a03ca24c4..6ba17b4c4 100644 --- a/doc/4.3-object-types.md +++ b/doc/4.3-object-types.md @@ -454,8 +454,7 @@ Attributes: ----------------|---------------- methods |**Required.** The "execute" script method takes care of executing the check. In virtually all cases you should import the "plugin-check-command" template to take care of this setting. command |**Required.** The command. This can either be an array of individual command arguments. Alternatively a string can be specified in which case the shell interpreter (usually /bin/sh) takes care of parsing the command. - export_macros |**Optional.** A list of macros which should be exported as environment variables prior to executing the command. - escape_macros |**Optional.** A list of macros which should be shell-escaped in the command. + env |**Optional.** A dictionary of macros which should be exported as environment variables prior to executing the command. vars |**Optional.** A dictionary containing custom attributes that are specific to this command. timeout |**Optional.** The command timeout in seconds. Defaults to 5 minutes. @@ -494,8 +493,7 @@ Attributes: ----------------|---------------- methods |**Required.** The "execute" script method takes care of executing the notification. In virtually all cases you should import the "plugin-notification-command" template to take care of this setting. command |**Required.** The command. This can either be an array of individual command arguments. Alternatively a string can be specified in which case the shell interpreter (usually /bin/sh) takes care of parsing the command. - export_macros |**Optional.** A list of macros which should be exported as environment variables prior to executing the command. - escape_macros |**Optional.** A list of macros which should be shell-escaped in the command. + env |**Optional.** A dictionary of macros which should be exported as environment variables prior to executing the command. vars |**Optional.** A dictionary containing custom attributes that are specific to this command. timeout |**Optional.** The command timeout in seconds. Defaults to 5 minutes. @@ -522,8 +520,7 @@ Attributes: ----------------|---------------- methods |**Required.** The "execute" script method takes care of executing the event handler. In virtually all cases you should import the "plugin-event-command" template to take care of this setting. command |**Required.** The command. This can either be an array of individual command arguments. Alternatively a string can be specified in which case the shell interpreter (usually /bin/sh) takes care of parsing the command. - export_macros |**Optional.** A list of macros which should be exported as environment variables prior to executing the command. - escape_macros |**Optional.** A list of macros which should be shell-escaped in the command. + env |**Optional.** A dictionary of macros which should be exported as environment variables prior to executing the command. vars |**Optional.** A dictionary containing custom attributes that are specific to this command. timeout |**Optional.** The command timeout in seconds. Defaults to 5 minutes. diff --git a/lib/icinga/command.ti b/lib/icinga/command.ti index d0593d038..ff8d6e6b3 100644 --- a/lib/icinga/command.ti +++ b/lib/icinga/command.ti @@ -10,7 +10,6 @@ abstract class Command : DynamicObject default {{{ return 300; }}} }; [config] Dictionary::Ptr env; - [config] Array::Ptr escape_macros; }; } diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf index b1c1850b8..e2ed754cc 100644 --- a/lib/icinga/icinga-type.conf +++ b/lib/icinga/icinga-type.conf @@ -163,9 +163,6 @@ %attribute %dictionary "env" { %attribute %string "*" }, - %attribute %array "escape_macros" { - %attribute %string "*" - }, %attribute %number "timeout" /* } */ } diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index c6fd025c7..0cf1d9e01 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -29,7 +29,7 @@ using namespace icinga; Value MacroProcessor::ResolveMacros(const Value& str, const std::vector& resolvers, - const CheckResult::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn, const Array::Ptr& escapeMacros) + const CheckResult::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn) { Value result; @@ -37,7 +37,7 @@ Value MacroProcessor::ResolveMacros(const Value& str, const std::vector()) { Array::Ptr resultArr = make_shared(); Array::Ptr arr = str; @@ -46,7 +46,7 @@ Value MacroProcessor::ResolveMacros(const Value& str, const std::vectorAdd(InternalResolveMacros(arg, resolvers, cr, EscapeCallback(), Array::Ptr())); + resultArr->Add(InternalResolveMacros(arg, resolvers, cr, EscapeCallback())); } result = resultArr; @@ -72,7 +72,7 @@ bool MacroProcessor::ResolveMacro(const String& macro, const std::vector& resolvers, - const CheckResult::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn, const Array::Ptr& escapeMacros) + const CheckResult::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn) { CONTEXT("Resolving macros for string '" + str + "'"); @@ -100,20 +100,8 @@ String MacroProcessor::InternalResolveMacros(const String& str, const std::vecto if (!found) Log(LogWarning, "icinga", "Macro '" + name + "' is not defined."); - if (escapeFn && escapeMacros) { - bool escape = false; - - ObjectLock olock(escapeMacros); - BOOST_FOREACH(const String& escapeMacro, escapeMacros) { - if (escapeMacro == name) { - escape = true; - break; - } - } - - if (escape) - resolved_macro = escapeFn(resolved_macro); - } + if (escapeFn) + resolved_macro = escapeFn(resolved_macro); result.Replace(pos_first, pos_second - pos_first + 1, resolved_macro); offset = pos_first + resolved_macro.GetLength() + 1; diff --git a/lib/icinga/macroprocessor.h b/lib/icinga/macroprocessor.h index 16db5bb1a..cd7fead01 100644 --- a/lib/icinga/macroprocessor.h +++ b/lib/icinga/macroprocessor.h @@ -41,7 +41,7 @@ public: typedef boost::function EscapeCallback; static Value ResolveMacros(const Value& str, const std::vector& resolvers, - const CheckResult::Ptr& cr, const EscapeCallback& escapeFn = EscapeCallback(), const Array::Ptr& escapeMacros = Array::Ptr()); + const CheckResult::Ptr& cr, const EscapeCallback& escapeFn = EscapeCallback()); static bool ResolveMacro(const String& macro, const std::vector& resolvers, const CheckResult::Ptr& cr, String *result); @@ -50,7 +50,7 @@ private: static String InternalResolveMacros(const String& str, const std::vector& resolvers, const CheckResult::Ptr& cr, - const EscapeCallback& escapeFn, const Array::Ptr& escapeMacros); + const EscapeCallback& escapeFn); }; } diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 517261ec7..e4e80ddb3 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -57,7 +57,7 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes resolvers.push_back(commandObj); resolvers.push_back(IcingaApplication::GetInstance()); - Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros()); + Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd); Dictionary::Ptr envMacros = make_shared(); @@ -67,7 +67,7 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes BOOST_FOREACH(const Dictionary::Pair& kv, env) { String name = kv.second; - Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros()); + Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult()); envMacros->Set(kv.first, value); } diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 016ae776f..7a37cc850 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -54,7 +54,7 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable) resolvers.push_back(commandObj); resolvers.push_back(IcingaApplication::GetInstance()); - Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros()); + Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd); Dictionary::Ptr envMacros = make_shared(); @@ -64,7 +64,7 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable) BOOST_FOREACH(const Dictionary::Pair& kv, env) { String name = kv.second; - Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros()); + Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult()); envMacros->Set(kv.first, value); } diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index c9c942be6..88d7b148e 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -63,7 +63,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c resolvers.push_back(commandObj); resolvers.push_back(IcingaApplication::GetInstance()); - Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, cr, Utility::EscapeShellCmd, commandObj->GetEscapeMacros()); + Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, cr, Utility::EscapeShellCmd); Dictionary::Ptr envMacros = make_shared(); @@ -73,7 +73,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c BOOST_FOREACH(const Dictionary::Pair& kv, env) { String name = kv.second; - Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros()); + Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult()); envMacros->Set(kv.first, value); }