From e28f30a727bec11f95b69f036586ea52896efde9 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 12 Aug 2016 14:49:29 +0200 Subject: [PATCH] Enhance log messages for {,reminder} notifications refs #12402 --- lib/icinga/checkable-notification.cpp | 2 +- lib/icinga/notification.cpp | 30 +++++++++++----------- lib/icinga/notification.hpp | 7 ++--- lib/notification/notificationcomponent.cpp | 2 +- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/icinga/checkable-notification.cpp b/lib/icinga/checkable-notification.cpp index 5dc22f1d7..0ceae52c3 100644 --- a/lib/icinga/checkable-notification.cpp +++ b/lib/icinga/checkable-notification.cpp @@ -74,7 +74,7 @@ void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr& BOOST_FOREACH(const Notification::Ptr& notification, notifications) { try { if (!notification->IsPaused()) - notification->BeginExecuteNotification(type, cr, force, author, text); + notification->BeginExecuteNotification(type, cr, force, false, author, text); } catch (const std::exception& ex) { Log(LogWarning, "Checkable") << "Exception occured during notification for service '" diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 4e702f94d..3452d9f9d 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -262,10 +262,10 @@ String Notification::NotificationTypeToString(NotificationType type) } } -void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author, const String& text) +void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, bool reminder, const String& author, const String& text) { Log(LogNotice, "Notification") - << "Attempting to send notifications for notification object '" << GetName() << "'."; + << "Attempting to send " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "'."; Checkable::Ptr checkable = GetCheckable(); @@ -274,7 +274,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe if (tp && !tp->IsInside(Utility::GetTime())) { Log(LogNotice, "Notification") - << "Not sending notifications for notification object '" << GetName() + << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': not in timeperiod '" << tp->GetName() << "'"; return; } @@ -288,7 +288,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe if (timesBegin != Empty && timesBegin >= 0 && now < checkable->GetLastHardStateChange() + timesBegin) { Log(LogNotice, "Notification") - << "Not sending notifications for notification object '" << GetName() + << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': before specified begin time (" << Utility::FormatDuration(timesBegin) << ")"; /* we need to adjust the next notification time @@ -303,7 +303,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe if (timesEnd != Empty && timesEnd >= 0 && now > checkable->GetLastHardStateChange() + timesEnd) { Log(LogNotice, "Notification") - << "Not sending notifications for notification object '" << GetName() + << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': after specified end time (" << Utility::FormatDuration(timesEnd) << ")"; return; } @@ -318,7 +318,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe if (!(ftype & GetTypeFilter())) { Log(LogNotice, "Notification") - << "Not sending notifications for notification object '" << GetName() << "': type '" + << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': type '" << NotificationTypeToStringInternal(type) << "' does not match type filter: " << NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << "."; return; @@ -347,14 +347,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe if (!(fstate & GetStateFilter())) { Log(LogNotice, "Notification") - << "Not sending notifications for notification object '" << GetName() << "': state '" << stateStr + << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': state '" << stateStr << "' does not match state filter: " << NotificationFilterToString(GetStateFilter(), GetStateFilterMap()) << "."; return; } } } else { Log(LogNotice, "Notification") - << "Not checking notification filters for notification object '" << GetName() << "': Notification was forced."; + << "Not checking " << (reminder ? "reminder " : " ") << "notification filters for notification object '" << GetName() << "': Notification was forced."; } { @@ -393,7 +393,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe continue; } - if (!CheckNotificationUserFilters(type, user, force)) { + if (!CheckNotificationUserFilters(type, user, force, reminder)) { Log(LogNotice, "Notification") << "Notification filters for user '" << userName << "' not matched. Not sending notification."; continue; @@ -409,7 +409,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe } Log(LogInformation, "Notification") - << "Sending '" << NotificationTypeToStringInternal(type) << "' notification '" + << "Sending " << (reminder ? "reminder " : " ") << "'" << NotificationTypeToStringInternal(type) << "' notification '" << GetName() << " for user '" << userName << "'"; Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text)); @@ -430,14 +430,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe Service::OnNotificationSentToAllUsers(this, checkable, allNotifiedUsers, type, cr, author, text, MessageOrigin::Ptr()); } -bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force) +bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder) { if (!force) { TimePeriod::Ptr tp = user->GetPeriod(); if (tp && !tp->IsInside(Utility::GetTime())) { Log(LogNotice, "Notification") - << "Not sending notifications for notification object '" + << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << " and user '" << user->GetName() << "': user period not in timeperiod '" << tp->GetName() << "'"; return false; @@ -453,7 +453,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use if (!(ftype & user->GetTypeFilter())) { Log(LogNotice, "Notification") - << "Not sending notifications for notification object '" + << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << " and user '" << user->GetName() << "': type '" << NotificationTypeToStringInternal(type) << "' does not match type filter: " << NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << "."; @@ -485,7 +485,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use if (!(fstate & user->GetStateFilter())) { Log(LogNotice, "Notification") - << "Not sending notifications for notification object '" + << "Not " << (reminder ? "reminder " : " ") << "sending notifications for notification object '" << GetName() << " and user '" << user->GetName() << "': state '" << stateStr << "' does not match state filter: " << NotificationFilterToString(user->GetStateFilter(), GetStateFilterMap()) << "."; return false; @@ -493,7 +493,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use } } else { Log(LogNotice, "Notification") - << "Not checking notification filters for notification object '" + << "Not checking " << (reminder ? "reminder " : " ") << "notification filters for notification object '" << GetName() << "' and user '" << user->GetName() << "': Notification was forced."; } diff --git a/lib/icinga/notification.hpp b/lib/icinga/notification.hpp index 37145c8fa..33f42a569 100644 --- a/lib/icinga/notification.hpp +++ b/lib/icinga/notification.hpp @@ -94,9 +94,8 @@ public: void UpdateNotificationNumber(void); void ResetNotificationNumber(void); - void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = ""); - - bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force); + void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, + bool reminder = false, const String& author = "", const String& text = ""); Endpoint::Ptr GetCommandEndpoint(void) const; @@ -127,6 +126,8 @@ protected: private: ObjectImpl::Ptr m_Checkable; + bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder); + void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = ""); static bool EvaluateApplyRuleInstance(const intrusive_ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule); diff --git a/lib/notification/notificationcomponent.cpp b/lib/notification/notificationcomponent.cpp index 20cfa0163..a33064ccf 100644 --- a/lib/notification/notificationcomponent.cpp +++ b/lib/notification/notificationcomponent.cpp @@ -116,7 +116,7 @@ void NotificationComponent::NotificationTimerHandler(void) try { Log(LogNotice, "NotificationComponent") << "Attempting to send reminder notification for object '" << checkable->GetName() << "'"; - notification->BeginExecuteNotification(NotificationProblem, checkable->GetLastCheckResult(), false); + notification->BeginExecuteNotification(NotificationProblem, checkable->GetLastCheckResult(), false, true); } catch (const std::exception& ex) { Log(LogWarning, "NotificationComponent") << "Exception occured during notification for object '"