]> granicus.if.org Git - icinga2/commitdiff
Enhance log messages for {,reminder} notifications
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 12 Aug 2016 12:49:29 +0000 (14:49 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 12 Aug 2016 12:49:29 +0000 (14:49 +0200)
refs #12402

lib/icinga/checkable-notification.cpp
lib/icinga/notification.cpp
lib/icinga/notification.hpp
lib/notification/notificationcomponent.cpp

index 5dc22f1d72ab01c136f7d7de637840c2ac723b10..0ceae52c3b96bab3d39f6c9fa960d0e11bda5d14 100644 (file)
@@ -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 '"
index 4e702f94d2577ba6f62e3cf26a3fdbbf820b7af1..3452d9f9de662f7097ef129444b7ca3474423694 100644 (file)
@@ -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.";
        }
 
index 37145c8fabbd634937bc60804aae6a55d3de07ed..33f42a569f8eb6dc5e67cfac404810101b79855a 100644 (file)
@@ -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<Checkable>::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>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
index 20cfa0163c12857d45cdee0b593272a4712e29ea..a33064ccfc533bff6c31396c0890107c5e65e635 100644 (file)
@@ -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 '"