]> granicus.if.org Git - icinga2/commitdiff
Use the right CheckResult object for commands.
authorGunnar Beutner <gunnar@beutner.name>
Thu, 22 May 2014 06:59:46 +0000 (08:59 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Thu, 22 May 2014 07:11:16 +0000 (09:11 +0200)
Fixes #6260

lib/icinga/pluginutility.cpp
lib/icinga/pluginutility.h
lib/methods/pluginchecktask.cpp
lib/methods/plugineventtask.cpp
lib/methods/pluginnotificationtask.cpp

index df749b73d891f7ffc07dc7eb0481946b5d8c14bd..4670f9eef04a046867181cb01a4ae0cc488fb24c 100644 (file)
@@ -60,7 +60,7 @@ private:
 };
 
 void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable,
-    const MacroProcessor::ResolverList& macroResolvers,
+    const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers,
     const boost::function<void(const Value& commandLine, const ProcessResult&)>& callback)
 {
        Value raw_command = commandObj->GetCommandLine();
@@ -68,7 +68,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
 
        Value command;
        if (!raw_arguments || raw_command.IsObjectType<Array>())
-               command = MacroProcessor::ResolveMacros(raw_command, macroResolvers, checkable->GetLastCheckResult(), NULL, Utility::EscapeShellArg);
+               command = MacroProcessor::ResolveMacros(raw_command, macroResolvers, cr, NULL, Utility::EscapeShellArg);
        else {
                Array::Ptr arr = make_shared<Array>();
                arr->Add(raw_command);
@@ -101,7 +101,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
                                if (!set_if.IsEmpty()) {
                                        String missingMacro;
                                        String set_if_resolved = MacroProcessor::ResolveMacros(set_if, macroResolvers,
-                                               checkable->GetLastCheckResult(), &missingMacro);
+                                               cr, &missingMacro);
 
                                        if (!missingMacro.IsEmpty() || !Convert::ToLong(set_if_resolved))
                                                continue;
@@ -115,7 +115,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
 
                        String missingMacro;
                        arg.Value = MacroProcessor::ResolveMacros(argval, macroResolvers,
-                           checkable->GetLastCheckResult(), &missingMacro);
+                           cr, &missingMacro);
 
                        if (!missingMacro.IsEmpty()) {
                                if (required) {
@@ -162,7 +162,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
                BOOST_FOREACH(const Dictionary::Pair& kv, env) {
                        String name = kv.second;
 
-                       Value value = MacroProcessor::ResolveMacros(name, macroResolvers, checkable->GetLastCheckResult());
+                       Value value = MacroProcessor::ResolveMacros(name, macroResolvers, cr);
 
                        envMacros->Set(kv.first, value);
                }
index f772e1abc4bb3f0370ed3cba59810b42373de8d5..060e2215291c7e0829ef88edbb4419750634a990 100644 (file)
@@ -40,7 +40,7 @@ class I2_ICINGA_API PluginUtility
 {
 public:
        static void ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable,
-           const MacroProcessor::ResolverList& macroResolvers,
+           const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers,
            const boost::function<void(const Value& commandLine, const ProcessResult&)>& callback = boost::function<void(const Value& commandLine, const ProcessResult&)>());
 
        static ServiceState ExitStatusToState(int exitStatus);
index d50a8e668d87273b73a039cfdf81be960aa82a5e..0908adfe5f97d0824e2476aeeeb5b6c0377325c5 100644 (file)
@@ -50,7 +50,7 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
        resolvers.push_back(std::make_pair("command", commandObj));
        resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
 
-       PluginUtility::ExecuteCommand(commandObj, checkable, resolvers, boost::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2));
+       PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers, boost::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2));
 }
 
 void PluginCheckTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Value& commandLine, const ProcessResult& pr)
index 0c079275b4140f9cea0622a18bfe7d1857048f9c..7773e04b3e85d3cf9391c05ea8889b7a271a8894 100644 (file)
@@ -48,5 +48,5 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable)
        resolvers.push_back(std::make_pair("command", commandObj));
        resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
 
-       PluginUtility::ExecuteCommand(commandObj, checkable, resolvers);
+       PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers);
 }
index 848847ad2cb2f31cb974ca986e71c5145be183a7..996c2c5ee26f7405261ab03ad79b0bca2c61baf7 100644 (file)
@@ -62,7 +62,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c
        resolvers.push_back(std::make_pair("command", commandObj));
        resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
 
-       PluginUtility::ExecuteCommand(commandObj, checkable, resolvers, boost::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, _1, _2));
+       PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers, boost::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, _1, _2));
 }
 
 void PluginNotificationTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const Value& command, const ProcessResult& pr)