]> granicus.if.org Git - icinga2/commitdiff
Move the IDO specific compat notification filter logic into the feature
authorMichael Friedrich <michael.friedrich@icinga.com>
Thu, 21 Dec 2017 07:57:36 +0000 (08:57 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 15 Jan 2018 12:39:34 +0000 (13:39 +0100)
lib/db_ido/hostdbobject.cpp
lib/db_ido/servicedbobject.cpp
lib/icinga/compatutility.cpp
lib/icinga/compatutility.hpp
lib/livestatus/hoststable.cpp
lib/livestatus/servicestable.cpp

index 393bbbb041cf8f8251ca4bacd604fd60800ecfaa..6be9b236a881982e027b16914aa0e72160b97188 100644 (file)
@@ -75,12 +75,17 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const
        fields->Set("first_notification_delay", Empty);
 
        fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host));
-       fields->Set("notify_on_down", CompatUtility::GetHostNotifyOnDown(host));
-       fields->Set("notify_on_unreachable", CompatUtility::GetHostNotifyOnDown(host));
 
-       fields->Set("notify_on_recovery", CompatUtility::GetCheckableNotifyOnRecovery(host));
-       fields->Set("notify_on_flapping", CompatUtility::GetCheckableNotifyOnFlapping(host));
-       fields->Set("notify_on_downtime", CompatUtility::GetCheckableNotifyOnDowntime(host));
+        unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(host);
+        unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(host);
+
+       fields->Set("notify_on_down", (notificationStateFilter & ServiceWarning) || (notificationStateFilter && ServiceCritical));
+       fields->Set("notify_on_unreachable", 1); /* We don't have this filter and state, and as such we don't filter such notifications. */
+       fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery);
+       fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) ||
+               (notificationTypeFilter & NotificationFlappingEnd));
+       fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) ||
+               (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved));
 
        fields->Set("stalk_on_up", Empty);
        fields->Set("stalk_on_down", Empty);
index b50ebe13d7421d4704fabf2660508dea73fe08c7..e8d3cc2de740b0e2b2657fa1cbb3c480865d5f3b 100644 (file)
@@ -68,12 +68,19 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const
        fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
        fields->Set("first_notification_delay", Empty);
        fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service));
-       fields->Set("notify_on_warning", CompatUtility::GetCheckableNotifyOnWarning(service));
-       fields->Set("notify_on_unknown", CompatUtility::GetCheckableNotifyOnUnknown(service));
-       fields->Set("notify_on_critical", CompatUtility::GetCheckableNotifyOnCritical(service));
-       fields->Set("notify_on_recovery", CompatUtility::GetCheckableNotifyOnRecovery(service));
-       fields->Set("notify_on_flapping", CompatUtility::GetCheckableNotifyOnFlapping(service));
-       fields->Set("notify_on_downtime", CompatUtility::GetCheckableNotifyOnDowntime(service));
+
+        unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(service);
+        unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(service);
+
+       fields->Set("notify_on_warning", notificationStateFilter & ServiceWarning);
+       fields->Set("notify_on_unknown", notificationStateFilter & ServiceUnknown);
+       fields->Set("notify_on_critical", notificationStateFilter & ServiceCritical);
+       fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery);
+       fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) ||
+               (notificationTypeFilter & NotificationFlappingEnd));
+       fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) ||
+               (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved));
+
        fields->Set("stalk_on_ok", 0);
        fields->Set("stalk_on_warning", 0);
        fields->Set("stalk_on_unknown", 0);
index 89a0cb95bd2535eea8de6613fff05d2b5e915cb7..60a269baf974ceebe8bde8164a67e5ca8371755d 100644 (file)
@@ -99,29 +99,6 @@ String CompatUtility::GetHostStateString(const Host::Ptr& host)
        return Host::StateToString(host->GetState());
 }
 
-/* Used in DB IDO. */
-int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host)
-{
-       unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host);
-
-       if ((notification_state_filter & ServiceCritical) ||
-               (notification_state_filter & ServiceWarning))
-               return 1;
-
-       return 0;
-}
-
-/* Used in DB IDO. */
-int CompatUtility::GetHostNotifyOnUnreachable(const Host::Ptr& host)
-{
-       unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host);
-
-       if (notification_state_filter & ServiceUnknown)
-               return 1;
-
-       return 0;
-}
-
 /* Used in DB IDO, StatusDataWriter and Livestatus. */
 String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable)
 {
@@ -188,15 +165,6 @@ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable)
        return Empty;
 }
 
-/* Used in Livestatus. */
-int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable)
-{
-       if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile())
-               return 1;
-
-       return 0;
-}
-
 /* Used in Livestatus. */
 int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable)
 {
@@ -290,67 +258,6 @@ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& che
        return notification_state_filter;
 }
 
-/* Used in DB IDO. */
-int CompatUtility::GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable)
-{
-       if (GetCheckableNotificationStateFilter(checkable) & ServiceWarning)
-               return 1;
-
-       return 0;
-}
-
-/* Used in DB IDO. */
-int CompatUtility::GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable)
-{
-       if (GetCheckableNotificationStateFilter(checkable) & ServiceCritical)
-               return 1;
-
-       return 0;
-}
-
-/* Used in DB IDO. */
-int CompatUtility::GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable)
-{
-       if (GetCheckableNotificationStateFilter(checkable) & ServiceUnknown)
-               return 1;
-
-       return 0;
-}
-
-/* Used in DB IDO. */
-int CompatUtility::GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable)
-{
-       if (GetCheckableNotificationTypeFilter(checkable) & NotificationRecovery)
-               return 1;
-
-       return 0;
-}
-
-/* Used in DB IDO. */
-int CompatUtility::GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable)
-{
-       unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable);
-
-       if ((notification_type_filter & NotificationFlappingStart) ||
-               (notification_type_filter & NotificationFlappingEnd))
-               return 1;
-
-       return 0;
-}
-
-/* Used in DB IDO. */
-int CompatUtility::GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable)
-{
-       unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable);
-
-       if ((notification_type_filter & NotificationDowntimeStart) ||
-               (notification_type_filter & NotificationDowntimeEnd) ||
-               (notification_type_filter & NotificationDowntimeRemoved))
-               return 1;
-
-       return 0;
-}
-
 /* Used in DB IDO, StatusDataWriter and Livestatus. */
 std::set<User::Ptr> CompatUtility::GetCheckableNotificationUsers(const Checkable::Ptr& checkable)
 {
index 20ea8c601dc075a88876d26778e14dd41e976750..25ae136f02a7ba33bc87416d46784e8d505cd7cc 100644 (file)
@@ -42,13 +42,10 @@ public:
        /* host */
        static int GetHostCurrentState(const Host::Ptr& host);
        static String GetHostStateString(const Host::Ptr& host);
-       static int GetHostNotifyOnDown(const Host::Ptr& host);
-       static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
 
        /* service */
        static String GetCheckableCommandArgs(const Checkable::Ptr& checkable);
 
-       static int GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable);
        static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable);
 
        /* notification */
@@ -59,12 +56,6 @@ public:
        static double GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable);
        static int GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable);
        static int GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable);
-       static int GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable);
-       static int GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable);
-       static int GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable);
-       static int GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable);
-       static int GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable);
-       static int GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable);
 
        static std::set<User::Ptr> GetCheckableNotificationUsers(const Checkable::Ptr& checkable);
        static std::set<UserGroup::Ptr> GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable);
index 08e6104e1c55d6ef16dfedc737d71e16815635d0..6e637c258e91344dd19b517c7fdfcf5ee3728ce3 100644 (file)
@@ -699,7 +699,7 @@ Value HostsTable::NoMoreNotificationsAccessor(const Value& row)
        if (!host)
                return Empty;
 
-       return CompatUtility::GetCheckableNoMoreNotifications(host);
+       return (CompatUtility::GetCheckableNotificationNotificationInterval(host) == 0 && !host->GetVolatile()) ? 1 : 0;
 }
 
 Value HostsTable::LastCheckAccessor(const Value& row)
index c3a941c5e6a777aaedcdf69f92cc6af0d6711e95..b0c70ce322b6a7cd9096f1eff4d5faa37d2c1d7d 100644 (file)
@@ -587,7 +587,7 @@ Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return CompatUtility::GetCheckableNoMoreNotifications(service);
+       return (CompatUtility::GetCheckableNotificationNotificationInterval(service) == 0 && !service->GetVolatile()) ? 1 : 0;
 }
 
 Value ServicesTable::LastTimeOkAccessor(const Value& row)