Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions lib/notification/notificationcomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,34 @@ void FireSuppressedNotifications(const Notification::Ptr& notification)
int subtract = 0;
auto checkable (notification->GetCheckable());

for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) {
if ((suppressedTypes & type) && !checkable->NotificationReasonApplies(type)) {
subtract |= type;
suppressedTypes &= ~type;
}
}
auto tp (notification->GetPeriod());

if (suppressedTypes) {
auto tp (notification->GetPeriod());
if ((!tp || tp->IsInside(Utility::GetTime())) && !checkable->IsLikelyToBeCheckedSoon()) {
for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) {
if (!(suppressedTypes & type) || checkable->NotificationReasonSuppressed(type)) {
continue;
}

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

auto notificationName (notification->GetName());
auto notificationName (notification->GetName());

Log(LogNotice, "NotificationComponent")
<< "Attempting to re-send previously suppressed notification '" << notificationName << "'.";
Log(LogNotice, "NotificationComponent")
<< "Attempting to re-send previously suppressed notification '" << notificationName << "'.";

subtract |= type;
SubtractSuppressedNotificationTypes(notification, subtract);
subtract = 0;

try {
notification->BeginExecuteNotification(type, checkable->GetLastCheckResult(), false, false);
} catch (const std::exception& ex) {
Log(LogWarning, "NotificationComponent")
<< "Exception occurred during notification for object '"
<< notificationName << "': " << DiagnosticInformation(ex, false);
}
subtract |= type;
SubtractSuppressedNotificationTypes(notification, subtract);
subtract = 0;

try {
notification->BeginExecuteNotification(type, checkable->GetLastCheckResult(), false, false);
} catch (const std::exception& ex) {
Log(LogWarning, "NotificationComponent")
<< "Exception occurred during notification for object '"
<< notificationName << "': " << DiagnosticInformation(ex, false);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ set(base_test_SOURCES
$<TARGET_OBJECTS:methods>
)

if(ICINGA2_WITH_NOTIFICATION)
list(APPEND base_test_SOURCES
notification-notificationcomponent.cpp
$<TARGET_OBJECTS:notification>
)
endif()

if(ICINGA2_UNITY_BUILD)
mkunity_target(base test base_test_SOURCES)
endif()
Expand Down
9 changes: 9 additions & 0 deletions test/base-testloggerfixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class TestLogger : public Logger
return ret;
}

void Clear()
{
std::lock_guard lock(m_Mutex);
m_Expects.clear();
m_LogEntries.clear();
}

private:
void ProcessLogEntry(const LogEntry& entry) override
{
Expand Down Expand Up @@ -119,6 +126,8 @@ struct TestLoggerFixture
return testLogger->ExpectLogPattern(pattern, timeout);
}

void ClearTestLogger() const { testLogger->Clear(); }

TestLogger::Ptr testLogger = new TestLogger;
};

Expand Down
Loading
Loading