Skip to content

Commit f8a6b8a

Browse files
Subtract inapplicable suppressed notifications at a later point
Without this commit, every time the NotificationTimerHandler runs it will discard notifications that don't apply to the reason of the latest check result. This is probably intended to clear outdated suppressed notifications immediately when the TimePeriod resumes, but it also clears out important ones (see the test case). This commit fixes that by clearing out inapplicable notifications when the timer runs the first time after the TimePeriod resumes. By that time we can expect that no new suppressed notifications will be added and all notifications that don't conflict with the last check-result can still be run. Fixes #10575
1 parent 81bfbff commit f8a6b8a

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

lib/notification/notificationcomponent.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,37 +83,34 @@ void FireSuppressedNotifications(const Notification::Ptr& notification)
8383
int subtract = 0;
8484
auto checkable (notification->GetCheckable());
8585

86-
for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) {
87-
if ((suppressedTypes & type) && !checkable->NotificationReasonApplies(type)) {
88-
subtract |= type;
89-
suppressedTypes &= ~type;
90-
}
91-
}
86+
auto tp (notification->GetPeriod());
9287

93-
if (suppressedTypes) {
94-
auto tp (notification->GetPeriod());
88+
if ((!tp || tp->IsInside(Utility::GetTime())) && !checkable->IsLikelyToBeCheckedSoon()) {
89+
for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) {
90+
if (!(suppressedTypes & type) || checkable->NotificationReasonSuppressed(type)) {
91+
continue;
92+
}
9593

96-
if ((!tp || tp->IsInside(Utility::GetTime())) && !checkable->IsLikelyToBeCheckedSoon()) {
97-
for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) {
98-
if (!(suppressedTypes & type) || checkable->NotificationReasonSuppressed(type))
99-
continue;
94+
if (!checkable->NotificationReasonApplies(type)) {
95+
subtract |= type;
96+
continue;
97+
}
10098

101-
auto notificationName (notification->GetName());
99+
auto notificationName (notification->GetName());
102100

103-
Log(LogNotice, "NotificationComponent")
104-
<< "Attempting to re-send previously suppressed notification '" << notificationName << "'.";
101+
Log(LogNotice, "NotificationComponent")
102+
<< "Attempting to re-send previously suppressed notification '" << notificationName << "'.";
105103

106-
subtract |= type;
107-
SubtractSuppressedNotificationTypes(notification, subtract);
108-
subtract = 0;
109-
110-
try {
111-
notification->BeginExecuteNotification(type, checkable->GetLastCheckResult(), false, false);
112-
} catch (const std::exception& ex) {
113-
Log(LogWarning, "NotificationComponent")
114-
<< "Exception occurred during notification for object '"
115-
<< notificationName << "': " << DiagnosticInformation(ex, false);
116-
}
104+
subtract |= type;
105+
SubtractSuppressedNotificationTypes(notification, subtract);
106+
subtract = 0;
107+
108+
try {
109+
notification->BeginExecuteNotification(type, checkable->GetLastCheckResult(), false, false);
110+
} catch (const std::exception& ex) {
111+
Log(LogWarning, "NotificationComponent")
112+
<< "Exception occurred during notification for object '"
113+
<< notificationName << "': " << DiagnosticInformation(ex, false);
117114
}
118115
}
119116
}

0 commit comments

Comments
 (0)