diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 393bbbb04..6be9b236a 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -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); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index b50ebe13d..e8d3cc2de 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -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); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 89a0cb95b..60a269baf 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -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 CompatUtility::GetCheckableNotificationUsers(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 20ea8c601..25ae136f0 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -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 GetCheckableNotificationUsers(const Checkable::Ptr& checkable); static std::set GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 08e6104e1..6e637c258 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -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) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index c3a941c5e..b0c70ce32 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -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)