Merge pull request #8513 from Icinga/bugfix/notifications-downtime-change-in-timeperiod-8509

FireSuppressedNotifications(const Notification::Ptr&): don't send notifications while suppressed by checkable
This commit is contained in:
Alexander Aleksandrovič Klimov 2021-01-28 10:01:23 +01:00 committed by GitHub
commit 9a867c2c25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 19 deletions

View File

@ -173,24 +173,7 @@ static void FireSuppressedNotifications(Checkable* checkable)
bool still_applies = checkable->NotificationReasonApplies(type);
if (still_applies) {
bool still_suppressed;
switch (type) {
case NotificationProblem:
/* Fall through. */
case NotificationRecovery:
still_suppressed = !checkable->IsReachable(DependencyNotification) || checkable->IsInDowntime() || checkable->IsAcknowledged();
break;
case NotificationFlappingStart:
/* Fall through. */
case NotificationFlappingEnd:
still_suppressed = checkable->IsInDowntime();
break;
default:
break;
}
if (!still_suppressed && !checkable->IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) {
if (!checkable->NotificationReasonSuppressed(type) && !checkable->IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) {
Checkable::OnNotificationsRequested(checkable, type, checkable->GetLastCheckResult(), "", "", nullptr);
subtract |= type;
@ -258,6 +241,27 @@ bool Checkable::NotificationReasonApplies(NotificationType type)
}
}
/**
* Checks if notifications of a given type should be suppressed for this Checkable at the moment.
*
* @param type The notification type for which to query the suppression status.
*
* @return true if no notification of this type should be sent.
*/
bool Checkable::NotificationReasonSuppressed(NotificationType type)
{
switch (type) {
case NotificationProblem:
case NotificationRecovery:
return !IsReachable(DependencyNotification) || IsInDowntime() || IsAcknowledged();
case NotificationFlappingStart:
case NotificationFlappingEnd:
return IsInDowntime();
default:
return false;
}
}
/**
* E.g. we're going to re-send a stashed problem notification as *this is still not ok.
* But if the next check result recovers *this soon, we would send a recovery notification soon after the problem one.

View File

@ -186,6 +186,7 @@ public:
void ValidateMaxCheckAttempts(const Lazy<int>& lvalue, const ValidationUtils& value) final;
bool NotificationReasonApplies(NotificationType type);
bool NotificationReasonSuppressed(NotificationType type);
bool IsLikelyToBeCheckedSoon();
static void IncreasePendingChecks();

View File

@ -91,7 +91,7 @@ void FireSuppressedNotifications(const Notification::Ptr& notification)
if ((!tp || tp->IsInside(Utility::GetTime())) && !checkable->IsLikelyToBeCheckedSoon()) {
for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) {
if (!(suppressedTypes & type))
if (!(suppressedTypes & type) || checkable->NotificationReasonSuppressed(type))
continue;
auto notificationName (notification->GetName());