2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2017-11-09 20:19:31 +01:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
# include <stdlib.h>
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
#include "methods/dummychecktask.hpp"
|
|
|
|
#include "icinga/pluginutility.hpp"
|
|
|
|
#include "base/utility.hpp"
|
|
|
|
#include "base/perfdatavalue.hpp"
|
|
|
|
#include "base/convert.hpp"
|
|
|
|
#include "base/function.hpp"
|
|
|
|
#include "base/logger.hpp"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2018-08-07 13:55:41 +02:00
|
|
|
REGISTER_FUNCTION_NONCONST(Internal, DummyCheck, &DummyCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
2017-11-09 20:19:31 +01:00
|
|
|
|
|
|
|
void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
2017-12-19 15:50:05 +01:00
|
|
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
2017-11-09 20:19:31 +01:00
|
|
|
{
|
2018-02-21 13:42:58 +01:00
|
|
|
REQUIRE_NOT_NULL(checkable);
|
|
|
|
REQUIRE_NOT_NULL(cr);
|
2018-01-30 11:26:07 +01:00
|
|
|
|
2020-08-03 08:07:32 +02:00
|
|
|
CheckCommand::Ptr command = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand();
|
2017-11-09 20:19:31 +01:00
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
|
|
|
MacroProcessor::ResolverList resolvers;
|
2020-11-23 16:39:24 +01:00
|
|
|
|
2020-07-31 14:21:09 +02:00
|
|
|
if (MacroResolver::OverrideMacros)
|
|
|
|
resolvers.emplace_back("override", MacroResolver::OverrideMacros);
|
|
|
|
|
2017-11-09 20:19:31 +01:00
|
|
|
if (service)
|
2017-11-30 08:19:58 +01:00
|
|
|
resolvers.emplace_back("service", service);
|
|
|
|
resolvers.emplace_back("host", host);
|
2019-07-10 10:15:15 +02:00
|
|
|
resolvers.emplace_back("command", command);
|
2017-11-09 20:19:31 +01:00
|
|
|
|
|
|
|
int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(),
|
2017-12-19 15:50:05 +01:00
|
|
|
nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
|
2017-11-09 20:19:31 +01:00
|
|
|
|
|
|
|
String dummyText = MacroProcessor::ResolveMacros("$dummy_text$", resolvers, checkable->GetLastCheckResult(),
|
2017-12-19 15:50:05 +01:00
|
|
|
nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
|
2017-11-09 20:19:31 +01:00
|
|
|
|
|
|
|
if (resolvedMacros && !useResolvedMacros)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Parse output and performance data. */
|
|
|
|
std::pair<String, String> co = PluginUtility::ParseCheckOutput(dummyText);
|
|
|
|
|
|
|
|
double now = Utility::GetTime();
|
2020-07-20 16:29:26 +02:00
|
|
|
String commandName = command->GetName();
|
2017-11-09 20:19:31 +01:00
|
|
|
|
2020-07-20 16:29:26 +02:00
|
|
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
|
|
|
ProcessResult pr;
|
|
|
|
pr.PID = -1;
|
2020-07-22 11:38:41 +02:00
|
|
|
pr.Output = dummyText;
|
2020-07-20 16:29:26 +02:00
|
|
|
pr.ExecutionStart = now;
|
|
|
|
pr.ExecutionEnd = now;
|
|
|
|
pr.ExitStatus = dummyState;
|
2017-11-09 20:19:31 +01:00
|
|
|
|
2020-07-20 16:29:26 +02:00
|
|
|
Checkable::ExecuteCommandProcessFinishedHandler(commandName, pr);
|
|
|
|
} else {
|
|
|
|
cr->SetOutput(co.first);
|
|
|
|
cr->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
|
|
|
|
cr->SetState(PluginUtility::ExitStatusToState(dummyState));
|
|
|
|
cr->SetExitStatus(dummyState);
|
|
|
|
cr->SetExecutionStart(now);
|
|
|
|
cr->SetExecutionEnd(now);
|
|
|
|
cr->SetCommand(commandName);
|
|
|
|
|
|
|
|
checkable->ProcessCheckResult(cr);
|
|
|
|
}
|
2017-11-09 20:19:31 +01:00
|
|
|
}
|