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

Method ExecuteEventHandler

lib/icinga/checkable-event.cpp:21–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21void Checkable::ExecuteEventHandler(const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
22{
23 CONTEXT("Executing event handler for object '" << GetName() << "'");
24
25 if (!IcingaApplication::GetInstance()->GetEnableEventHandlers() || !GetEnableEventHandler())
26 return;
27
28 /* HA enabled zones. */
29 if (IsActive() && IsPaused()) {
30 Log(LogNotice, "Checkable")
31 << "Skipping event handler for HA-paused checkable '" << GetName() << "'";
32 return;
33 }
34
35 EventCommand::Ptr ec = GetEventCommand();
36
37 if (!ec)
38 return;
39
40 Log(LogNotice, "Checkable")
41 << "Executing event handler '" << ec->GetName() << "' for checkable '" << GetName() << "'";
42
43 Dictionary::Ptr macros;
44 Endpoint::Ptr endpoint = GetCommandEndpoint();
45
46 if (endpoint && !useResolvedMacros)
47 macros = new Dictionary();
48 else
49 macros = resolvedMacros;
50
51 ec->Execute(this, macros, useResolvedMacros);
52
53 if (endpoint && !GetExtension("agent_check")) {
54 Dictionary::Ptr message = new Dictionary();
55 message->Set("jsonrpc", "2.0");
56 message->Set("method", "event::ExecuteCommand");
57
58 Host::Ptr host;
59 Service::Ptr service;
60 tie(host, service) = GetHostService(this);
61
62 Dictionary::Ptr params = new Dictionary();
63 message->Set("params", params);
64 params->Set("command_type", "event_command");
65 params->Set("command", GetEventCommand()->GetName());
66 params->Set("host", host->GetName());
67
68 if (service)
69 params->Set("service", service->GetShortName());
70
71 params->Set("macros", macros);
72
73 ApiListener::Ptr listener = ApiListener::GetInstance();
74
75 if (listener)
76 listener->SyncSendMessage(endpoint, message);
77
78 return;

Callers 1

ExecuteCheckFromQueueMethod · 0.80

Calls 5

LogClass · 0.85
SyncSendMessageMethod · 0.80
GetNameMethod · 0.45
ExecuteMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected