Fix incorrect return values for some of the CompatUtility methods

fixes #12425
This commit is contained in:
Gunnar Beutner 2016-08-14 16:58:46 +02:00
parent 5db2ed90d8
commit fda032c0c4
9 changed files with 12 additions and 55 deletions

View File

@ -431,7 +431,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s
"\t" "notifications_enabled" "\t" << CompatUtility::GetCheckableNotificationsEnabled(service) << "\n" "\t" "notifications_enabled" "\t" << CompatUtility::GetCheckableNotificationsEnabled(service) << "\n"
"\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n" "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n"
"\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(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"; "\t" "event_handler_enabled" "\t" << CompatUtility::GetCheckableEventHandlerEnabled(service) << "\n";
CheckCommand::Ptr checkcommand = service->GetCheckCommand(); CheckCommand::Ptr checkcommand = service->GetCheckCommand();

View File

@ -57,7 +57,7 @@ Dictionary::Ptr HostDbObject::GetConfigFields(void) const
fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(host)); fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(host));
fields->Set("eventhandler_command_object_id", host->GetEventCommand()); fields->Set("eventhandler_command_object_id", host->GetEventCommand());
fields->Set("eventhandler_command_args", Empty); 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("check_timeperiod_object_id", host->GetCheckPeriod());
fields->Set("failure_prediction_options", Empty); fields->Set("failure_prediction_options", Empty);
fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(host)); fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(host));

View File

@ -60,7 +60,7 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields(void) const
fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(service)); fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(service));
fields->Set("eventhandler_command_object_id", service->GetEventCommand()); fields->Set("eventhandler_command_object_id", service->GetEventCommand());
fields->Set("eventhandler_command_args", Empty); 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("check_timeperiod_object_id", service->GetCheckPeriod());
fields->Set("failure_prediction_options", Empty); fields->Set("failure_prediction_options", Empty);
fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(service)); fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(service));

View File

@ -354,17 +354,13 @@ int CompatUtility::GetCheckableInCheckPeriod(const Checkable::Ptr& checkable)
int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable)
{ {
BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
ObjectLock olock(notification);
TimePeriod::Ptr timeperiod = notification->GetPeriod(); TimePeriod::Ptr timeperiod = notification->GetPeriod();
/* first notification wins */ if (!timeperiod || timeperiod->IsInside(Utility::GetTime()))
if (timeperiod) return 1;
return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
} }
/* none set means always notified */ return 0;
return 1;
} }
/* vars attr */ /* vars attr */
@ -442,22 +438,6 @@ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkab
return notification_interval / 60.0; 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) String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable)
{ {
@ -469,8 +449,8 @@ String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkabl
unsigned long notification_state_filter = 0; unsigned long notification_state_filter = 0;
BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
notification_type_filter = notification->GetTypeFilter(); notification_type_filter |= notification->GetTypeFilter();
notification_state_filter = notification->GetStateFilter(); notification_state_filter |= notification->GetStateFilter();
} }
std::vector<String> notification_options; std::vector<String> notification_options;
@ -516,7 +496,7 @@ int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& chec
BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
ObjectLock olock(notification); ObjectLock olock(notification);
notification_type_filter = notification->GetTypeFilter(); notification_type_filter |= notification->GetTypeFilter();
} }
return notification_type_filter; return notification_type_filter;
@ -529,7 +509,7 @@ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& che
BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
ObjectLock olock(notification); ObjectLock olock(notification);
notification_state_filter = notification->GetStateFilter(); notification_state_filter |= notification->GetStateFilter();
} }
return notification_state_filter; return notification_state_filter;

View File

@ -88,7 +88,6 @@ public:
static int GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable); static int GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable);
static int GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable); static int GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable);
static double GetCheckableNotificationNotificationInterval(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 String GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable);
static int GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable); static int GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable);
static int GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable); static int GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable);

View File

@ -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", Column(&HostsTable::CheckCommandAccessor, objectAccessor));
table->AddColumn(prefix + "check_command_expanded", Column(&HostsTable::CheckCommandExpandedAccessor, objectAccessor)); table->AddColumn(prefix + "check_command_expanded", Column(&HostsTable::CheckCommandExpandedAccessor, objectAccessor));
table->AddColumn(prefix + "event_handler", Column(&HostsTable::EventHandlerAccessor, 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 + "check_period", Column(&HostsTable::CheckPeriodAccessor, objectAccessor));
table->AddColumn(prefix + "notes", Column(&HostsTable::NotesAccessor, objectAccessor)); table->AddColumn(prefix + "notes", Column(&HostsTable::NotesAccessor, objectAccessor));
table->AddColumn(prefix + "notes_expanded", Column(&HostsTable::NotesExpandedAccessor, objectAccessor)); table->AddColumn(prefix + "notes_expanded", Column(&HostsTable::NotesExpandedAccessor, objectAccessor));
@ -297,16 +297,6 @@ Value HostsTable::EventHandlerAccessor(const Value& row)
return Empty; return Empty;
} }
Value HostsTable::NotificationPeriodAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
if (!host)
return Empty;
return CompatUtility::GetCheckableNotificationNotificationPeriod(host);
}
Value HostsTable::CheckPeriodAccessor(const Value& row) Value HostsTable::CheckPeriodAccessor(const Value& row)
{ {
Host::Ptr host = static_cast<Host::Ptr>(row); Host::Ptr host = static_cast<Host::Ptr>(row);

View File

@ -55,7 +55,6 @@ protected:
static Value CheckCommandAccessor(const Value& row); static Value CheckCommandAccessor(const Value& row);
static Value CheckCommandExpandedAccessor(const Value& row); static Value CheckCommandExpandedAccessor(const Value& row);
static Value EventHandlerAccessor(const Value& row); static Value EventHandlerAccessor(const Value& row);
static Value NotificationPeriodAccessor(const Value& row);
static Value CheckPeriodAccessor(const Value& row); static Value CheckPeriodAccessor(const Value& row);
static Value NotesAccessor(const Value& row); static Value NotesAccessor(const Value& row);
static Value NotesExpandedAccessor(const Value& row); static Value NotesExpandedAccessor(const Value& row);

View File

@ -61,7 +61,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix,
table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor)); table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor));
table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor)); table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor));
table->AddColumn(prefix + "perf_data", Column(&ServicesTable::PerfDataAccessor, 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 + "check_period", Column(&ServicesTable::CheckPeriodAccessor, objectAccessor));
table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor)); table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor));
table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor)); table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor));
@ -349,16 +349,6 @@ Value ServicesTable::PerfDataAccessor(const Value& row)
return perfdata; return perfdata;
} }
Value ServicesTable::NotificationPeriodAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
return CompatUtility::GetCheckableNotificationNotificationPeriod(service);
}
Value ServicesTable::CheckPeriodAccessor(const Value& row) Value ServicesTable::CheckPeriodAccessor(const Value& row)
{ {
Service::Ptr service = static_cast<Service::Ptr>(row); Service::Ptr service = static_cast<Service::Ptr>(row);

View File

@ -58,7 +58,6 @@ protected:
static Value PluginOutputAccessor(const Value& row); static Value PluginOutputAccessor(const Value& row);
static Value LongPluginOutputAccessor(const Value& row); static Value LongPluginOutputAccessor(const Value& row);
static Value PerfDataAccessor(const Value& row); static Value PerfDataAccessor(const Value& row);
static Value NotificationPeriodAccessor(const Value& row);
static Value CheckPeriodAccessor(const Value& row); static Value CheckPeriodAccessor(const Value& row);
static Value NotesAccessor(const Value& row); static Value NotesAccessor(const Value& row);
static Value NotesExpandedAccessor(const Value& row); static Value NotesExpandedAccessor(const Value& row);