From: Michael Friedrich Date: Wed, 6 Dec 2017 16:17:47 +0000 (+0100) Subject: Move notification options wrapper into StatusDataWriter X-Git-Tag: v2.9.0~222^2~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15e3524e42fa26f52d3eb9754bdd60652090de9f;p=icinga2 Move notification options wrapper into StatusDataWriter That's the only location which requires the old mapping. --- diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index bbb5469ca..142fdd91e 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -270,7 +270,7 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) "\t" "active_checks_enabled" "\t" << Convert::ToLong(host->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled" "\t" << Convert::ToLong(host->GetEnablePassiveChecks()) << "\n" "\t" "notifications_enabled" "\t" << Convert::ToLong(host->GetEnableNotifications()) << "\n" - "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(host) << "\n" + "\t" "notification_options" "\t" << GetNotificationOptions(host) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(host) << "\n" "\t" "event_handler_enabled" "\t" << Convert::ToLong(host->GetEnableEventHandler()) << "\n"; @@ -372,7 +372,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl if (cr) { fp << "\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n" "\t" "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n" - "\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n" + "\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n"; } fp << "\t" << "next_check=" << static_cast(checkable->GetNextCheck()) << "\n" @@ -436,7 +436,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s "\t" "flap_detection_enabled" "\t" << Convert::ToLong(service->GetEnableFlapping()) << "\n" "\t" "is_volatile" "\t" << Convert::ToLong(service->GetVolatile()) << "\n" "\t" "notifications_enabled" "\t" << Convert::ToLong(service->GetEnableNotifications()) << "\n" - "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n" + "\t" "notification_options" "\t" << GetNotificationOptions(service) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n" "\t" "notification_period" "\t" << "" << "\n" "\t" "event_handler_enabled" "\t" << Convert::ToLong(service->GetEnableEventHandler()) << "\n"; @@ -864,3 +864,53 @@ void StatusDataWriter::ObjectHandler() { m_ObjectsCacheOutdated = true; } + +String StatusDataWriter::GetNotificationOptions(const Checkable::Ptr& checkable) +{ + Host::Ptr host; + Service::Ptr service; + tie(host, service) = GetHostService(checkable); + + unsigned long notification_type_filter = 0; + unsigned long notification_state_filter = 0; + + for (const Notification::Ptr& notification : checkable->GetNotifications()) { + notification_type_filter |= notification->GetTypeFilter(); + notification_state_filter |= notification->GetStateFilter(); + } + + std::vector notification_options; + + /* notification state filters */ + if (service) { + if (notification_state_filter & ServiceWarning) { + notification_options.push_back("w"); + } + if (notification_state_filter & ServiceUnknown) { + notification_options.push_back("u"); + } + if (notification_state_filter & ServiceCritical) { + notification_options.push_back("c"); + } + } else { + if (notification_state_filter & HostDown) { + notification_options.push_back("d"); + } + } + + /* notification type filters */ + if (notification_type_filter & NotificationRecovery) { + notification_options.push_back("r"); + } + if ((notification_type_filter & NotificationFlappingStart) || + (notification_type_filter & NotificationFlappingEnd)) { + notification_options.push_back("f"); + } + if ((notification_type_filter & NotificationDowntimeStart) || + (notification_type_filter & NotificationDowntimeEnd) || + (notification_type_filter & NotificationDowntimeRemoved)) { + notification_options.push_back("s"); + } + + return boost::algorithm::join(notification_options, ","); +} diff --git a/lib/compat/statusdatawriter.hpp b/lib/compat/statusdatawriter.hpp index c19377408..5dd68427f 100644 --- a/lib/compat/statusdatawriter.hpp +++ b/lib/compat/statusdatawriter.hpp @@ -97,6 +97,8 @@ private: void UpdateObjectsCache(); void StatusTimerHandler(); void ObjectHandler(); + + static String GetNotificationOptions(const Checkable::Ptr& checkable); }; } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 154fcc4db..e86f20126 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -282,57 +282,6 @@ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkab return notification_interval / 60.0; } -String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable) -{ - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - unsigned long notification_type_filter = 0; - unsigned long notification_state_filter = 0; - - for (const Notification::Ptr& notification : checkable->GetNotifications()) { - notification_type_filter |= notification->GetTypeFilter(); - notification_state_filter |= notification->GetStateFilter(); - } - - std::vector notification_options; - - /* notification state filters */ - if (service) { - if (notification_state_filter & ServiceWarning) { - notification_options.emplace_back("w"); - } - if (notification_state_filter & ServiceUnknown) { - notification_options.emplace_back("u"); - } - if (notification_state_filter & ServiceCritical) { - notification_options.emplace_back("c"); - } - } else { - if (notification_state_filter & HostDown) { - notification_options.emplace_back("d"); - } - } - - /* notification type filters */ - if (notification_type_filter & NotificationRecovery) { - notification_options.emplace_back("r"); - } - if ((notification_type_filter & NotificationFlappingStart) || - (notification_type_filter & NotificationFlappingEnd)) { - notification_options.emplace_back("f"); - } - if ((notification_type_filter & NotificationDowntimeStart) || - (notification_type_filter & NotificationDowntimeEnd) || - (notification_type_filter & NotificationDowntimeRemoved)) { - notification_options.emplace_back("s"); - } - - return boost::algorithm::join(notification_options, ","); -} - int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable) { unsigned long notification_type_filter = 0; diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 55a08d082..4f1c59c60 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -65,7 +65,6 @@ public: static int GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable); static int GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable); static double GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable); - static String GetCheckableNotificationNotificationOptions(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);