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

Method ScriptFunc

lib/methods/pluginnotificationtask.cpp:34–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32REGISTER_FUNCTION_NONCONST(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc, "notification:user:cr:itype:author:comment:resolvedMacros:useResolvedMacros");
33
34void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
35 const User::Ptr& user, const CheckResult::Ptr& cr, int itype,
36 const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros,
37 bool useResolvedMacros)
38{
39 REQUIRE_NOT_NULL(notification);
40 REQUIRE_NOT_NULL(user);
41
42 NotificationCommand::Ptr commandObj = NotificationCommand::ExecuteOverride ? NotificationCommand::ExecuteOverride : notification->GetCommand();
43
44 auto type = static_cast<NotificationType>(itype);
45
46 Checkable::Ptr checkable = notification->GetCheckable();
47
48 Dictionary::Ptr notificationExtra = new Dictionary({
49 { "type", Notification::NotificationTypeToStringCompat(type) }, //TODO: Change that to our types.
50 { "author", author },
51#ifdef __linux__
52 { "comment", comment.SubStr(0, l_MaxOutLen) }
53#else /* __linux__ */
54 { "comment", comment }
55#endif /* __linux__ */
56 });
57
58 Host::Ptr host;
59 Service::Ptr service;
60 tie(host, service) = GetHostService(checkable);
61
62 MacroProcessor::ResolverList resolvers;
63
64 if (MacroResolver::OverrideMacros)
65 resolvers.emplace_back("override", MacroResolver::OverrideMacros);
66
67 resolvers.emplace_back("user", user);
68 resolvers.emplace_back("notification", notificationExtra);
69 resolvers.emplace_back("notification", notification);
70
71 if (service) {
72#ifdef __linux__
73 auto cr (service->GetLastCheckResult());
74
75 if (cr) {
76 auto output (cr->GetOutput());
77
78 if (output.GetLength() > l_MaxOutLen) {
79 resolvers.emplace_back("service", new Dictionary({{"output", output.SubStr(0, l_MaxOutLen)}}));
80 }
81 }
82#endif /* __linux__ */
83
84 resolvers.emplace_back("service", service);
85 }
86
87#ifdef __linux__
88 auto hcr (host->GetLastCheckResult());
89
90 if (hcr) {
91 auto output (hcr->GetOutput());

Callers

nothing calls this directly

Calls 6

ExecuteCommandFunction · 0.85
GetCommandMethod · 0.80
SubStrMethod · 0.80
GetTimeoutMethod · 0.80
GetCheckableMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected