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

Method SendNotifications

lib/icinga/checkable-notification.cpp:34–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text)
35{
36 String checkableName = GetName();
37
38 CONTEXT("Sending notifications for object '" << checkableName << "'");
39
40 bool force = GetForceNextNotification();
41
42 SetForceNextNotification(false);
43
44 if (!IcingaApplication::GetInstance()->GetEnableNotifications() || !GetEnableNotifications()) {
45 if (!force) {
46 Log(LogInformation, "Checkable")
47 << "Notifications are disabled for checkable '" << checkableName << "'.";
48 return;
49 }
50 }
51
52 std::set<Notification::Ptr> notifications = GetNotifications();
53
54 String notificationTypeName = Notification::NotificationTypeToString(type);
55
56 // Bail early if there are no notifications.
57 if (notifications.empty()) {
58 Log(LogNotice, "Checkable")
59 << "Skipping checkable '" << checkableName << "' which doesn't have any notification objects configured.";
60 return;
61 }
62
63 Log(LogInformation, "Checkable")
64 << "Checkable '" << checkableName << "' has " << notifications.size()
65 << " notification(s). Checking filters for type '" << notificationTypeName << "', sends will be logged.";
66
67 for (const Notification::Ptr& notification : notifications) {
68 // Re-send stashed notifications from cold startup.
69 if (ApiListener::UpdatedObjectAuthority()) {
70 try {
71 if (!notification->IsPaused()) {
72 auto stashedNotifications (notification->GetStashedNotifications());
73
74 if (stashedNotifications->GetLength()) {
75 Log(LogNotice, "Notification")
76 << "Notification '" << notification->GetName() << "': there are some stashed notifications. Stashing notification to preserve order.";
77
78 stashedNotifications->Add(new Dictionary({
79 {"notification_type", type},
80 {"cr", cr},
81 {"force", force},
82 {"reminder", false},
83 {"author", author},
84 {"text", text}
85 }));
86 } else {
87 notification->BeginExecuteNotification(type, cr, force, false, author, text);
88 }
89 } else {
90 Log(LogNotice, "Notification")
91 << "Notification '" << notification->GetName() << "': HA cluster active, this endpoint does not have the authority (paused=true). Skipping.";

Callers 1

Calls 8

LogClass · 0.85
IsPausedMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
GetLengthMethod · 0.45
GetNameMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected