From fda032c0c4c9b3461f233a9e0248fcd927e9cd9c Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 14 Aug 2016 16:58:46 +0200 Subject: [PATCH] Fix incorrect return values for some of the CompatUtility methods fixes #12425 --- lib/compat/statusdatawriter.cpp | 2 +- lib/db_ido/hostdbobject.cpp | 2 +- lib/db_ido/servicedbobject.cpp | 2 +- lib/icinga/compatutility.cpp | 34 +++++++------------------------- lib/icinga/compatutility.hpp | 1 - lib/livestatus/hoststable.cpp | 12 +---------- lib/livestatus/hoststable.hpp | 1 - lib/livestatus/servicestable.cpp | 12 +---------- lib/livestatus/servicestable.hpp | 1 - 9 files changed, 12 insertions(+), 55 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 3c88e8a0a..8e52526e5 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -431,7 +431,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s "\t" "notifications_enabled" "\t" << CompatUtility::GetCheckableNotificationsEnabled(service) << "\n" "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n" - "\t" "notification_period" "\t" << CompatUtility::GetCheckableNotificationNotificationPeriod(service) << "\n" + "\t" "notification_period" "\t" << "" << "\n" "\t" "event_handler_enabled" "\t" << CompatUtility::GetCheckableEventHandlerEnabled(service) << "\n"; CheckCommand::Ptr checkcommand = service->GetCheckCommand(); diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index b6422a0a3..ef69c6db2 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -57,7 +57,7 @@ Dictionary::Ptr HostDbObject::GetConfigFields(void) const fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(host)); fields->Set("eventhandler_command_object_id", host->GetEventCommand()); fields->Set("eventhandler_command_args", Empty); - fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetCheckableNotificationNotificationPeriod(host))); + fields->Set("notification_timeperiod_object_id", Empty); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); fields->Set("failure_prediction_options", Empty); fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(host)); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 7f2c6211f..2ad793a5f 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -60,7 +60,7 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields(void) const fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(service)); fields->Set("eventhandler_command_object_id", service->GetEventCommand()); fields->Set("eventhandler_command_args", Empty); - fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetCheckableNotificationNotificationPeriod(service))); + fields->Set("notification_timeperiod_object_id", Empty); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); fields->Set("failure_prediction_options", Empty); fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(service)); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 6166691b0..e2aeeb38b 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -354,17 +354,13 @@ int CompatUtility::GetCheckableInCheckPeriod(const Checkable::Ptr& checkable) int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) { BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { - ObjectLock olock(notification); - TimePeriod::Ptr timeperiod = notification->GetPeriod(); - /* first notification wins */ - if (timeperiod) - return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0); + if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) + return 1; } - /* none set means always notified */ - return 1; + return 0; } /* vars attr */ @@ -442,22 +438,6 @@ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkab return notification_interval / 60.0; } -String CompatUtility::GetCheckableNotificationNotificationPeriod(const Checkable::Ptr& checkable) -{ - TimePeriod::Ptr notification_period; - - BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { - - if (notification->GetPeriod()) - notification_period = notification->GetPeriod(); - } - - if (!notification_period) - return Empty; - - return notification_period->GetName(); -} - String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable) { @@ -469,8 +449,8 @@ String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkabl unsigned long notification_state_filter = 0; BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { - notification_type_filter = notification->GetTypeFilter(); - notification_state_filter = notification->GetStateFilter(); + notification_type_filter |= notification->GetTypeFilter(); + notification_state_filter |= notification->GetStateFilter(); } std::vector notification_options; @@ -516,7 +496,7 @@ int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& chec BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { ObjectLock olock(notification); - notification_type_filter = notification->GetTypeFilter(); + notification_type_filter |= notification->GetTypeFilter(); } return notification_type_filter; @@ -529,7 +509,7 @@ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& che BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { ObjectLock olock(notification); - notification_state_filter = notification->GetStateFilter(); + notification_state_filter |= notification->GetStateFilter(); } return notification_state_filter; diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 610fd3da9..1fca4da51 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -88,7 +88,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 GetCheckableNotificationNotificationPeriod(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); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 62da70dd9..a7322547d 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -58,7 +58,7 @@ void HostsTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "check_command", Column(&HostsTable::CheckCommandAccessor, objectAccessor)); table->AddColumn(prefix + "check_command_expanded", Column(&HostsTable::CheckCommandExpandedAccessor, objectAccessor)); table->AddColumn(prefix + "event_handler", Column(&HostsTable::EventHandlerAccessor, objectAccessor)); - table->AddColumn(prefix + "notification_period", Column(&HostsTable::NotificationPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "notification_period", Column(&Table::EmptyStringAccessor, objectAccessor)); table->AddColumn(prefix + "check_period", Column(&HostsTable::CheckPeriodAccessor, objectAccessor)); table->AddColumn(prefix + "notes", Column(&HostsTable::NotesAccessor, objectAccessor)); table->AddColumn(prefix + "notes_expanded", Column(&HostsTable::NotesExpandedAccessor, objectAccessor)); @@ -297,16 +297,6 @@ Value HostsTable::EventHandlerAccessor(const Value& row) return Empty; } -Value HostsTable::NotificationPeriodAccessor(const Value& row) -{ - Host::Ptr host = static_cast(row); - - if (!host) - return Empty; - - return CompatUtility::GetCheckableNotificationNotificationPeriod(host); -} - Value HostsTable::CheckPeriodAccessor(const Value& row) { Host::Ptr host = static_cast(row); diff --git a/lib/livestatus/hoststable.hpp b/lib/livestatus/hoststable.hpp index 2f261d669..03692387f 100644 --- a/lib/livestatus/hoststable.hpp +++ b/lib/livestatus/hoststable.hpp @@ -55,7 +55,6 @@ protected: static Value CheckCommandAccessor(const Value& row); static Value CheckCommandExpandedAccessor(const Value& row); static Value EventHandlerAccessor(const Value& row); - static Value NotificationPeriodAccessor(const Value& row); static Value CheckPeriodAccessor(const Value& row); static Value NotesAccessor(const Value& row); static Value NotesExpandedAccessor(const Value& row); diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 95f05212f..ce707717a 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -61,7 +61,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor)); table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor)); table->AddColumn(prefix + "perf_data", Column(&ServicesTable::PerfDataAccessor, objectAccessor)); - table->AddColumn(prefix + "notification_period", Column(&ServicesTable::NotificationPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "notification_period", Column(&Table::EmptyStringAccessor, objectAccessor)); table->AddColumn(prefix + "check_period", Column(&ServicesTable::CheckPeriodAccessor, objectAccessor)); table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor)); table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor)); @@ -349,16 +349,6 @@ Value ServicesTable::PerfDataAccessor(const Value& row) return perfdata; } -Value ServicesTable::NotificationPeriodAccessor(const Value& row) -{ - Service::Ptr service = static_cast(row); - - if (!service) - return Empty; - - return CompatUtility::GetCheckableNotificationNotificationPeriod(service); -} - Value ServicesTable::CheckPeriodAccessor(const Value& row) { Service::Ptr service = static_cast(row); diff --git a/lib/livestatus/servicestable.hpp b/lib/livestatus/servicestable.hpp index c66ff2e97..92145573a 100644 --- a/lib/livestatus/servicestable.hpp +++ b/lib/livestatus/servicestable.hpp @@ -58,7 +58,6 @@ protected: static Value PluginOutputAccessor(const Value& row); static Value LongPluginOutputAccessor(const Value& row); static Value PerfDataAccessor(const Value& row); - static Value NotificationPeriodAccessor(const Value& row); static Value CheckPeriodAccessor(const Value& row); static Value NotesAccessor(const Value& row); static Value NotesExpandedAccessor(const Value& row); -- 2.40.0