MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ScriptFunc

Method ScriptFunc

lib/methods/randomchecktask.cpp:19–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17REGISTER_FUNCTION_NONCONST(Internal, RandomCheck, &RandomCheckTask::ScriptFunc, "checkable:cr:producer:resolvedMacros:useResolvedMacros");
18
19void RandomCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
20 const WaitGroup::Ptr& producer, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
21{
22 REQUIRE_NOT_NULL(checkable);
23 REQUIRE_NOT_NULL(cr);
24
25 if (resolvedMacros && !useResolvedMacros)
26 return;
27
28 double now = Utility::GetTime();
29 double uptime = Application::GetUptime();
30
31 String output = "Hello from " + IcingaApplication::GetInstance()->GetNodeName()
32 + ". Icinga 2 has been running for " + Utility::FormatDuration(uptime)
33 + ". Version: " + Application::GetAppVersion();
34
35 CheckCommand::Ptr command = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand();
36 String commandName = command->GetName();
37 ServiceState state = static_cast<ServiceState>(Utility::Random() % 4);
38
39 if (Checkable::ExecuteCommandProcessFinishedHandler) {
40 double now = Utility::GetTime();
41 ProcessResult pr;
42 pr.PID = -1;
43 pr.Output = output;
44 pr.ExecutionStart = now;
45 pr.ExecutionEnd = now;
46 pr.ExitStatus = state;
47
48 Checkable::ExecuteCommandProcessFinishedHandler(commandName, pr);
49 } else {
50 cr->SetOutput(output);
51
52 double random = Utility::Random() % 1000;
53 cr->SetPerformanceData(new Array({
54 new PerfdataValue("time", now),
55 new PerfdataValue("value", random),
56 new PerfdataValue("value_1m", random * 0.9),
57 new PerfdataValue("value_5m", random * 0.8),
58 new PerfdataValue("uptime", uptime),
59 }));
60
61 cr->SetState(state);
62 cr->SetCommand(commandName);
63
64 checkable->ProcessCheckResult(cr, producer);
65 }
66}

Callers

nothing calls this directly

Calls 4

GetNodeNameMethod · 0.80
GetCheckCommandMethod · 0.80
GetNameMethod · 0.45
ProcessCheckResultMethod · 0.45

Tested by

no test coverage detected