mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
Internal methods must update the 'command' key in the check result
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.
This commit is contained in:
parent
0712589bd1
commit
406ecb448c
@ -6,6 +6,7 @@
|
|||||||
#include "icinga/cib.hpp"
|
#include "icinga/cib.hpp"
|
||||||
#include "icinga/service.hpp"
|
#include "icinga/service.hpp"
|
||||||
#include "icinga/icingaapplication.hpp"
|
#include "icinga/icingaapplication.hpp"
|
||||||
|
#include "icinga/checkcommand.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
@ -27,6 +28,9 @@ void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRe
|
|||||||
if (resolvedMacros && !useResolvedMacros)
|
if (resolvedMacros && !useResolvedMacros)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
||||||
|
cr->SetCommand(command->GetName());
|
||||||
|
|
||||||
ApiListener::Ptr listener = ApiListener::GetInstance();
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
||||||
|
|
||||||
if (!listener) {
|
if (!listener) {
|
||||||
|
@ -29,8 +29,8 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
||||||
Value raw_command = commandObj->GetCommandLine();
|
Value raw_command = command->GetCommandLine();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
@ -40,7 +40,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
|
|||||||
if (service)
|
if (service)
|
||||||
resolvers.emplace_back("service", service);
|
resolvers.emplace_back("service", service);
|
||||||
resolvers.emplace_back("host", host);
|
resolvers.emplace_back("host", host);
|
||||||
resolvers.emplace_back("command", commandObj);
|
resolvers.emplace_back("command", command);
|
||||||
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
|
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
|
||||||
|
|
||||||
String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(),
|
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)
|
if (resolvedMacros && !useResolvedMacros)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
cr->SetCommand(command->GetName());
|
||||||
|
|
||||||
if (zoneName.IsEmpty()) {
|
if (zoneName.IsEmpty()) {
|
||||||
cr->SetOutput("Macro 'cluster_zone' must be set.");
|
cr->SetOutput("Macro 'cluster_zone' must be set.");
|
||||||
cr->SetState(ServiceUnknown);
|
cr->SetState(ServiceUnknown);
|
||||||
|
@ -22,7 +22,7 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
|
|||||||
REQUIRE_NOT_NULL(checkable);
|
REQUIRE_NOT_NULL(checkable);
|
||||||
REQUIRE_NOT_NULL(cr);
|
REQUIRE_NOT_NULL(cr);
|
||||||
|
|
||||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
@ -32,7 +32,7 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
|
|||||||
if (service)
|
if (service)
|
||||||
resolvers.emplace_back("service", service);
|
resolvers.emplace_back("service", service);
|
||||||
resolvers.emplace_back("host", host);
|
resolvers.emplace_back("host", host);
|
||||||
resolvers.emplace_back("command", commandObj);
|
resolvers.emplace_back("command", command);
|
||||||
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
|
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
|
||||||
|
|
||||||
int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(),
|
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->SetExitStatus(dummyState);
|
||||||
cr->SetExecutionStart(now);
|
cr->SetExecutionStart(now);
|
||||||
cr->SetExecutionEnd(now);
|
cr->SetExecutionEnd(now);
|
||||||
|
cr->SetCommand(command->GetName());
|
||||||
|
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
|||||||
REQUIRE_NOT_NULL(checkable);
|
REQUIRE_NOT_NULL(checkable);
|
||||||
REQUIRE_NOT_NULL(cr);
|
REQUIRE_NOT_NULL(cr);
|
||||||
|
|
||||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
@ -36,7 +36,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
|||||||
if (service)
|
if (service)
|
||||||
resolvers.emplace_back("service", service);
|
resolvers.emplace_back("service", service);
|
||||||
resolvers.emplace_back("host", host);
|
resolvers.emplace_back("host", host);
|
||||||
resolvers.emplace_back("command", commandObj);
|
resolvers.emplace_back("command", command);
|
||||||
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
|
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
|
||||||
|
|
||||||
String missingIcingaMinVersion;
|
String missingIcingaMinVersion;
|
||||||
@ -185,6 +185,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
cr->SetOutput(output);
|
cr->SetOutput(output);
|
||||||
|
cr->SetCommand(command->GetName());
|
||||||
|
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
#include "methods/randomchecktask.hpp"
|
#include "methods/randomchecktask.hpp"
|
||||||
#include "icinga/icingaapplication.hpp"
|
#include "icinga/icingaapplication.hpp"
|
||||||
|
#include "icinga/checkcommand.hpp"
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/perfdatavalue.hpp"
|
#include "base/perfdatavalue.hpp"
|
||||||
#include "base/function.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));
|
cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
|
||||||
|
|
||||||
|
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
||||||
|
cr->SetCommand(command->GetName());
|
||||||
|
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
}
|
}
|
||||||
|
@ -47,5 +47,8 @@ void SleepCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
|
|||||||
cr->SetExecutionStart(now);
|
cr->SetExecutionStart(now);
|
||||||
cr->SetExecutionEnd(now);
|
cr->SetExecutionEnd(now);
|
||||||
|
|
||||||
|
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
||||||
|
cr->SetCommand(command->GetName());
|
||||||
|
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user