Remove the escape_macros attribute.

Refs #5855
This commit is contained in:
Gunnar Beutner 2014-04-06 10:45:50 +02:00
parent 5c671eab15
commit 98fba78fe4
8 changed files with 17 additions and 36 deletions

View File

@ -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. 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. 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. env |**Optional.** A dictionary 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.
vars |**Optional.** A dictionary containing custom attributes that are specific to this 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. 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. 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. 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. env |**Optional.** A dictionary 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.
vars |**Optional.** A dictionary containing custom attributes that are specific to this 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. 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. 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. 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. env |**Optional.** A dictionary 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.
vars |**Optional.** A dictionary containing custom attributes that are specific to this 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. timeout |**Optional.** The command timeout in seconds. Defaults to 5 minutes.

View File

@ -10,7 +10,6 @@ abstract class Command : DynamicObject
default {{{ return 300; }}} default {{{ return 300; }}}
}; };
[config] Dictionary::Ptr env; [config] Dictionary::Ptr env;
[config] Array::Ptr escape_macros;
}; };
} }

View File

@ -163,9 +163,6 @@
%attribute %dictionary "env" { %attribute %dictionary "env" {
%attribute %string "*" %attribute %string "*"
}, },
%attribute %array "escape_macros" {
%attribute %string "*"
},
%attribute %number "timeout" %attribute %number "timeout"
/* } */ /* } */
} }

View File

@ -29,7 +29,7 @@
using namespace icinga; using namespace icinga;
Value MacroProcessor::ResolveMacros(const Value& str, const std::vector<MacroResolver::Ptr>& resolvers, Value MacroProcessor::ResolveMacros(const Value& str, const std::vector<MacroResolver::Ptr>& resolvers,
const CheckResult::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn, const Array::Ptr& escapeMacros) const CheckResult::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn)
{ {
Value result; Value result;
@ -37,7 +37,7 @@ Value MacroProcessor::ResolveMacros(const Value& str, const std::vector<MacroRes
return Empty; return Empty;
if (str.IsScalar()) { if (str.IsScalar()) {
result = InternalResolveMacros(str, resolvers, cr, escapeFn, escapeMacros); result = InternalResolveMacros(str, resolvers, cr, escapeFn);
} else if (str.IsObjectType<Array>()) { } else if (str.IsObjectType<Array>()) {
Array::Ptr resultArr = make_shared<Array>(); Array::Ptr resultArr = make_shared<Array>();
Array::Ptr arr = str; Array::Ptr arr = str;
@ -46,7 +46,7 @@ Value MacroProcessor::ResolveMacros(const Value& str, const std::vector<MacroRes
BOOST_FOREACH(const Value& arg, arr) { BOOST_FOREACH(const Value& arg, arr) {
/* Note: don't escape macros here. */ /* Note: don't escape macros here. */
resultArr->Add(InternalResolveMacros(arg, resolvers, cr, EscapeCallback(), Array::Ptr())); resultArr->Add(InternalResolveMacros(arg, resolvers, cr, EscapeCallback()));
} }
result = resultArr; result = resultArr;
@ -72,7 +72,7 @@ bool MacroProcessor::ResolveMacro(const String& macro, const std::vector<MacroRe
String MacroProcessor::InternalResolveMacros(const String& str, const std::vector<MacroResolver::Ptr>& resolvers, String MacroProcessor::InternalResolveMacros(const String& str, const std::vector<MacroResolver::Ptr>& 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 + "'"); CONTEXT("Resolving macros for string '" + str + "'");
@ -100,20 +100,8 @@ String MacroProcessor::InternalResolveMacros(const String& str, const std::vecto
if (!found) if (!found)
Log(LogWarning, "icinga", "Macro '" + name + "' is not defined."); Log(LogWarning, "icinga", "Macro '" + name + "' is not defined.");
if (escapeFn && escapeMacros) { if (escapeFn)
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); resolved_macro = escapeFn(resolved_macro);
}
result.Replace(pos_first, pos_second - pos_first + 1, resolved_macro); result.Replace(pos_first, pos_second - pos_first + 1, resolved_macro);
offset = pos_first + resolved_macro.GetLength() + 1; offset = pos_first + resolved_macro.GetLength() + 1;

View File

@ -41,7 +41,7 @@ public:
typedef boost::function<String (const String&)> EscapeCallback; typedef boost::function<String (const String&)> EscapeCallback;
static Value ResolveMacros(const Value& str, const std::vector<MacroResolver::Ptr>& resolvers, static Value ResolveMacros(const Value& str, const std::vector<MacroResolver::Ptr>& 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<MacroResolver::Ptr>& resolvers, static bool ResolveMacro(const String& macro, const std::vector<MacroResolver::Ptr>& resolvers,
const CheckResult::Ptr& cr, String *result); const CheckResult::Ptr& cr, String *result);
@ -50,7 +50,7 @@ private:
static String InternalResolveMacros(const String& str, static String InternalResolveMacros(const String& str,
const std::vector<MacroResolver::Ptr>& resolvers, const CheckResult::Ptr& cr, const std::vector<MacroResolver::Ptr>& resolvers, const CheckResult::Ptr& cr,
const EscapeCallback& escapeFn, const Array::Ptr& escapeMacros); const EscapeCallback& escapeFn);
}; };
} }

View File

@ -57,7 +57,7 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
resolvers.push_back(commandObj); resolvers.push_back(commandObj);
resolvers.push_back(IcingaApplication::GetInstance()); 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<Dictionary>(); Dictionary::Ptr envMacros = make_shared<Dictionary>();
@ -67,7 +67,7 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
BOOST_FOREACH(const Dictionary::Pair& kv, env) { BOOST_FOREACH(const Dictionary::Pair& kv, env) {
String name = kv.second; 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); envMacros->Set(kv.first, value);
} }

View File

@ -54,7 +54,7 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable)
resolvers.push_back(commandObj); resolvers.push_back(commandObj);
resolvers.push_back(IcingaApplication::GetInstance()); 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<Dictionary>(); Dictionary::Ptr envMacros = make_shared<Dictionary>();
@ -64,7 +64,7 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable)
BOOST_FOREACH(const Dictionary::Pair& kv, env) { BOOST_FOREACH(const Dictionary::Pair& kv, env) {
String name = kv.second; 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); envMacros->Set(kv.first, value);
} }

View File

@ -63,7 +63,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c
resolvers.push_back(commandObj); resolvers.push_back(commandObj);
resolvers.push_back(IcingaApplication::GetInstance()); 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<Dictionary>(); Dictionary::Ptr envMacros = make_shared<Dictionary>();
@ -73,7 +73,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c
BOOST_FOREACH(const Dictionary::Pair& kv, env) { BOOST_FOREACH(const Dictionary::Pair& kv, env) {
String name = kv.second; 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); envMacros->Set(kv.first, value);
} }