]> granicus.if.org Git - icinga2/commitdiff
Move notification options wrapper into StatusDataWriter
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 6 Dec 2017 16:17:47 +0000 (17:17 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 15 Jan 2018 12:39:34 +0000 (13:39 +0100)
That's the only location which requires the old mapping.

lib/compat/statusdatawriter.cpp
lib/compat/statusdatawriter.hpp
lib/icinga/compatutility.cpp
lib/icinga/compatutility.hpp

index bbb5469cafc2de23a038995202442701915e762c..142fdd91e64ab005c1e9dda1c471af2f61c5efc3 100644 (file)
@@ -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<long>(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<String> 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, ",");
+}
index c19377408000ab3474644b8d1142ab7fd79d2950..5dd68427f5d560ac1454b6f09bc9b5e12690983d 100644 (file)
@@ -97,6 +97,8 @@ private:
        void UpdateObjectsCache();
        void StatusTimerHandler();
        void ObjectHandler();
+
+       static String GetNotificationOptions(const Checkable::Ptr& checkable);
 };
 
 }
index 154fcc4db765a8c8c11ac62efa91b7a85b9bb7cc..e86f201263792057e26f9eecaff503eb4f0a390c 100644 (file)
@@ -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<String> 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;
index 55a08d082606635ac79a448fc6568052ead6317a..4f1c59c600b4791019a4f8e15703abf972e3f028 100644 (file)
@@ -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);