]> granicus.if.org Git - icinga2/commitdiff
Internal methods must update the 'command' key in the check result 7305/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 10 Jul 2019 08:15:15 +0000 (10:15 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Wed, 10 Jul 2019 08:15:15 +0000 (10:15 +0200)
Currently this is `null` which isn't really correct.

As otherwise, it is tremendously hard to figure out which check
command was involved, if you're not looking at the `.check_command`
checkable object.

lib/methods/clusterchecktask.cpp
lib/methods/clusterzonechecktask.cpp
lib/methods/dummychecktask.cpp
lib/methods/icingachecktask.cpp
lib/methods/randomchecktask.cpp
lib/methods/sleepchecktask.cpp

index 4a8c76d8df6a46f044e0f70a876a0789530e7f92..a9be0414dcf3e5df7c3f44bb434341c41d30a21c 100644 (file)
@@ -6,6 +6,7 @@
 #include "icinga/cib.hpp"
 #include "icinga/service.hpp"
 #include "icinga/icingaapplication.hpp"
+#include "icinga/checkcommand.hpp"
 #include "base/application.hpp"
 #include "base/objectlock.hpp"
 #include "base/convert.hpp"
@@ -27,6 +28,9 @@ void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRe
        if (resolvedMacros && !useResolvedMacros)
                return;
 
+       CheckCommand::Ptr command = checkable->GetCheckCommand();
+       cr->SetCommand(command->GetName());
+
        ApiListener::Ptr listener = ApiListener::GetInstance();
 
        if (!listener) {
index 577fcdac785a47e1e8b5c3297dd158af1d3b82ea..c955b7dd9cacd77145018fa3637d3235894e7524 100644 (file)
@@ -29,8 +29,8 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
                return;
        }
 
-       CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
-       Value raw_command = commandObj->GetCommandLine();
+       CheckCommand::Ptr command = checkable->GetCheckCommand();
+       Value raw_command = command->GetCommandLine();
 
        Host::Ptr host;
        Service::Ptr service;
@@ -40,7 +40,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
        if (service)
                resolvers.emplace_back("service", service);
        resolvers.emplace_back("host", host);
-       resolvers.emplace_back("command", commandObj);
+       resolvers.emplace_back("command", command);
        resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
 
        String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(),
@@ -58,6 +58,8 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
        if (resolvedMacros && !useResolvedMacros)
                return;
 
+       cr->SetCommand(command->GetName());
+
        if (zoneName.IsEmpty()) {
                cr->SetOutput("Macro 'cluster_zone' must be set.");
                cr->SetState(ServiceUnknown);
index 570fdb681d3c5c72762ce732f78e6b6c80c1690f..e42754f3143c62c3e7a6b1b88fac1e70e01abb66 100644 (file)
@@ -22,7 +22,7 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
        REQUIRE_NOT_NULL(checkable);
        REQUIRE_NOT_NULL(cr);
 
-       CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
+       CheckCommand::Ptr command = checkable->GetCheckCommand();
 
        Host::Ptr host;
        Service::Ptr service;
@@ -32,7 +32,7 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
        if (service)
                resolvers.emplace_back("service", service);
        resolvers.emplace_back("host", host);
-       resolvers.emplace_back("command", commandObj);
+       resolvers.emplace_back("command", command);
        resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
 
        int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(),
@@ -55,6 +55,7 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
        cr->SetExitStatus(dummyState);
        cr->SetExecutionStart(now);
        cr->SetExecutionEnd(now);
+       cr->SetCommand(command->GetName());
 
        checkable->ProcessCheckResult(cr);
 }
index fa598d487362d7ce11440cfd6eec329dcbeb6578..e67d1ff94304be1929a35bce20805e70e26e792a 100644 (file)
@@ -26,7 +26,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
        REQUIRE_NOT_NULL(checkable);
        REQUIRE_NOT_NULL(cr);
 
-       CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
+       CheckCommand::Ptr command = checkable->GetCheckCommand();
 
        Host::Ptr host;
        Service::Ptr service;
@@ -36,7 +36,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
        if (service)
                resolvers.emplace_back("service", service);
        resolvers.emplace_back("host", host);
-       resolvers.emplace_back("command", commandObj);
+       resolvers.emplace_back("command", command);
        resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
 
        String missingIcingaMinVersion;
@@ -185,6 +185,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
        }
 
        cr->SetOutput(output);
+       cr->SetCommand(command->GetName());
 
        checkable->ProcessCheckResult(cr);
 }
index 3bb4b026c26273253d330e94ba82f59df73e7149..ddda9879b5cff1573ef2683b8445e7da92d8dea6 100644 (file)
@@ -5,6 +5,7 @@
 #endif /* _WIN32 */
 #include "methods/randomchecktask.hpp"
 #include "icinga/icingaapplication.hpp"
+#include "icinga/checkcommand.hpp"
 #include "base/utility.hpp"
 #include "base/perfdatavalue.hpp"
 #include "base/function.hpp"
@@ -44,5 +45,8 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
 
        cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
 
+       CheckCommand::Ptr command = checkable->GetCheckCommand();
+       cr->SetCommand(command->GetName());
+
        checkable->ProcessCheckResult(cr);
 }
index 888a71ac89fd0a399f65abb8ca3da6c78de132f3..47f735c3699accef973cd07ecf47c357e104ef2c 100644 (file)
@@ -47,5 +47,8 @@ void SleepCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
     cr->SetExecutionStart(now);
     cr->SetExecutionEnd(now);
 
+    CheckCommand::Ptr command = checkable->GetCheckCommand();
+    cr->SetCommand(command->GetName());
+
     checkable->ProcessCheckResult(cr);
 }
\ No newline at end of file