]> granicus.if.org Git - icinga2/blob - lib/methods/nullchecktask.cpp
Merge pull request #7527 from Icinga/bugfix/checkable-command-endpoint-zone
[icinga2] / lib / methods / nullchecktask.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef _WIN32
4 #       include <stdlib.h>
5 #endif /* _WIN32 */
6 #include "methods/nullchecktask.hpp"
7 #include "icinga/icingaapplication.hpp"
8 #include "base/utility.hpp"
9 #include "base/perfdatavalue.hpp"
10 #include "base/convert.hpp"
11 #include "base/function.hpp"
12 #include "base/logger.hpp"
13
14 using namespace icinga;
15
16 REGISTER_FUNCTION_NONCONST(Internal, NullCheck, &NullCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
17
18 void NullCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
19         const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
20 {
21         REQUIRE_NOT_NULL(checkable);
22         REQUIRE_NOT_NULL(cr);
23
24         if (resolvedMacros && !useResolvedMacros)
25                 return;
26
27         String output = "Hello from ";
28         output += IcingaApplication::GetInstance()->GetNodeName();
29
30         cr->SetOutput(output);
31         cr->SetPerformanceData(new Array({
32                 new PerfdataValue("time", Convert::ToDouble(Utility::GetTime()))
33         }));
34         cr->SetState(ServiceOK);
35
36         checkable->ProcessCheckResult(cr);
37 }