]> granicus.if.org Git - icinga2/blobdiff - lib/icinga/checkable-notification.cpp
Merge pull request #6727 from Icinga/feature/cluster-config-sync-stage
[icinga2] / lib / icinga / checkable-notification.cpp
index 99511acaa64fad0c49ba9b629fb290b36fc4feed..568ff6c52daf0e08340d44a607fe5fc03f300b4d 100644 (file)
@@ -1,21 +1,4 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/)  *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
+/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
 
 #include "icinga/checkable.hpp"
 #include "icinga/icingaapplication.hpp"
@@ -31,10 +14,10 @@ boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, c
        const NotificationType&, const CheckResult::Ptr&, const String&, const String&,
        const MessageOrigin::Ptr&)> Checkable::OnNotificationSentToAllUsers;
 boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const User::Ptr&,
-       const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&,
-       const MessageOrigin::Ptr&)> Checkable::OnNotificationSentToUser;
+       const NotificationType&, const CheckResult::Ptr&, const NotificationResult::Ptr&, const String&,
+       const String&, const String&, const MessageOrigin::Ptr&)> Checkable::OnNotificationSentToUser;
 
-void Checkable::ResetNotificationNumbers(void)
+void Checkable::ResetNotificationNumbers()
 {
        for (const Notification::Ptr& notification : GetNotifications()) {
                ObjectLock olock(notification);
@@ -44,7 +27,9 @@ void Checkable::ResetNotificationNumbers(void)
 
 void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text)
 {
-       CONTEXT("Sending notifications for object '" + GetName() + "'");
+       String checkableName = GetName();
+
+       CONTEXT("Sending notifications for object '" + checkableName + "'");
 
        bool force = GetForceNextNotification();
 
@@ -53,36 +38,36 @@ void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr&
        if (!IcingaApplication::GetInstance()->GetEnableNotifications() || !GetEnableNotifications()) {
                if (!force) {
                        Log(LogInformation, "Checkable")
-                               << "Notifications are disabled for service '" << GetName() << "'.";
+                               << "Notifications are disabled for checkable '" << checkableName << "'.";
                        return;
                }
        }
 
-       Log(LogInformation, "Checkable")
-               << "Checking for configured notifications for object '" << GetName() << "'";
-
        std::set<Notification::Ptr> notifications = GetNotifications();
 
-       if (notifications.empty())
-               Log(LogInformation, "Checkable")
-                       << "Checkable '" << GetName() << "' does not have any notifications.";
+       Log(LogInformation, "Checkable")
+               << "Checkable '" << checkableName << "' has " << notifications.size() << " notification(s). Proceeding with filters, successful sends will be logged.";
 
-       Log(LogDebug, "Checkable")
-               << "Checkable '" << GetName() << "' has " << notifications.size() << " notification(s).";
+       if (notifications.empty())
+               return;
 
        for (const Notification::Ptr& notification : notifications) {
                try {
-                       if (!notification->IsPaused())
+                       if (!notification->IsPaused()) {
                                notification->BeginExecuteNotification(type, cr, force, false, author, text);
+                       } else {
+                               Log(LogNotice, "Notification")
+                                       << "Notification '" << notification->GetName() << "': HA cluster active, this endpoint does not have the authority (paused=true). Skipping.";
+                       }
                } catch (const std::exception& ex) {
                        Log(LogWarning, "Checkable")
-                               << "Exception occured during notification for service '"
-                               << GetName() << "': " << DiagnosticInformation(ex);
+                               << "Exception occurred during notification '" << notification->GetName() << "' for checkable '"
+                               << GetName() << "': " << DiagnosticInformation(ex, false);
                }
        }
 }
 
-std::set<Notification::Ptr> Checkable::GetNotifications(void) const
+std::set<Notification::Ptr> Checkable::GetNotifications() const
 {
        boost::mutex::scoped_lock lock(m_NotificationMutex);
        return m_Notifications;