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/icingaapplication.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
|
|
|
|
2019-07-10 10:15:15 +02:00
|
|
|
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
2017-11-09 20:19:31 +01:00
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
|
|
|
MacroProcessor::ResolverList resolvers;
|
|
|
|
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-30 08:19:58 +01:00
|
|
|
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
|
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();
|
|
|
|
|
|
|
|
cr->SetOutput(co.first);
|
|
|
|
cr->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
|
|
|
|
cr->SetState(PluginUtility::ExitStatusToState(dummyState));
|
|
|
|
cr->SetExitStatus(dummyState);
|
|
|
|
cr->SetExecutionStart(now);
|
|
|
|
cr->SetExecutionEnd(now);
|
2019-07-10 10:15:15 +02:00
|
|
|
cr->SetCommand(command->GetName());
|
2017-11-09 20:19:31 +01:00
|
|
|
|
|
|
|
checkable->ProcessCheckResult(cr);
|
|
|
|
}
|