From 636cf62d3a5126e2b6d7da202e13b5ae6600099e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 10:32:39 +0100 Subject: [PATCH] DB IDO: Clean up code and group CompatUtility calls --- lib/db_ido/hostdbobject.cpp | 73 +++++++++++++--------------------- lib/db_ido/servicedbobject.cpp | 61 ++++++++++++---------------- 2 files changed, 52 insertions(+), 82 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 62fcefe09..9136ed58a 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -60,18 +60,32 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("display_name", displayName); fields->Set("address", host->GetAddress()); fields->Set("address6", host->GetAddress6()); - fields->Set("check_command_object_id", host->GetCheckCommand()); fields->Set("eventhandler_command_object_id", host->GetEventCommand()); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); fields->Set("check_interval", (host->GetCheckInterval() / 60.0)); fields->Set("retry_interval", (host->GetRetryInterval() / 60.0)); fields->Set("max_check_attempts", host->GetMaxCheckAttempts()); + fields->Set("flap_detection_enabled", host->GetEnableFlapping()); + fields->Set("low_flap_threshold", host->GetFlappingThresholdLow()); + fields->Set("high_flap_threshold", host->GetFlappingThresholdLow()); + fields->Set("process_performance_data", host->GetEnablePerfdata()); + fields->Set("freshness_checks_enabled", 1); + fields->Set("freshness_threshold", Convert::ToLong(host->GetCheckInterval())); + fields->Set("event_handler_enabled", host->GetEnableEventHandler()); + fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks()); + fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); + fields->Set("notifications_enabled", host->GetEnableNotifications()); + fields->Set("notes", host->GetNotes()); + fields->Set("notes_url", host->GetNotesUrl()); + fields->Set("action_url", host->GetActionUrl()); + fields->Set("icon_image", host->GetIconImage()); + fields->Set("icon_image_alt", host->GetIconImageAlt()); fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host)); - unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(host); - unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(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. */ @@ -81,32 +95,6 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved)); - fields->Set("flap_detection_enabled", host->GetEnableFlapping()); - fields->Set("low_flap_threshold", host->GetFlappingThresholdLow()); - fields->Set("high_flap_threshold", host->GetFlappingThresholdLow()); - - fields->Set("process_performance_data", host->GetEnablePerfdata()); - - fields->Set("freshness_checks_enabled", 1); - fields->Set("freshness_threshold", Convert::ToLong(host->GetCheckInterval())); - fields->Set("event_handler_enabled", host->GetEnableEventHandler()); - fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks()); - fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); - - fields->Set("retain_status_information", 1); - fields->Set("retain_nonstatus_information", 1); - - fields->Set("notifications_enabled", host->GetEnableNotifications()); - - fields->Set("obsess_over_host", 0); - fields->Set("failure_prediction_enabled", 0); - - fields->Set("notes", host->GetNotes()); - fields->Set("notes_url", host->GetNotesUrl()); - fields->Set("action_url", host->GetActionUrl()); - fields->Set("icon_image", host->GetIconImage()); - fields->Set("icon_image_alt", host->GetIconImageAlt()); - return fields; } @@ -122,6 +110,8 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); fields->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); fields->Set("check_source", cr->GetCheckSource()); + fields->Set("latency", cr->CalculateLatency()); + fields->Set("execution_time", cr->CalculateExecutionTime()); } int currentState = host->GetState(); @@ -134,46 +124,37 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("should_be_scheduled", host->GetEnableActiveChecks()); fields->Set("current_check_attempt", host->GetCheckAttempt()); fields->Set("max_check_attempts", host->GetMaxCheckAttempts()); - - if (cr) - fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd())); - + fields->Set("last_check", DbValue::FromTimestamp(host->GetLastCheck())); fields->Set("next_check", DbValue::FromTimestamp(host->GetNextCheck())); fields->Set("check_type", !host->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */ fields->Set("last_state_change", DbValue::FromTimestamp(host->GetLastStateChange())); fields->Set("last_hard_state_change", DbValue::FromTimestamp(host->GetLastHardStateChange())); fields->Set("last_hard_state", host->GetLastHardState()); - fields->Set("last_time_up", DbValue::FromTimestamp(static_cast(host->GetLastStateUp()))); - fields->Set("last_time_down", DbValue::FromTimestamp(static_cast(host->GetLastStateDown()))); - fields->Set("last_time_unreachable", DbValue::FromTimestamp(static_cast(host->GetLastStateUnreachable()))); + fields->Set("last_time_up", DbValue::FromTimestamp(host->GetLastStateUp())); + fields->Set("last_time_down", DbValue::FromTimestamp(host->GetLastStateDown())); + fields->Set("last_time_unreachable", DbValue::FromTimestamp(host->GetLastStateUnreachable())); fields->Set("state_type", host->GetStateType()); - fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(host))); - fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(host))); fields->Set("notifications_enabled", host->GetEnableNotifications()); fields->Set("problem_has_been_acknowledged", host->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", host->GetAcknowledgement()); - fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host)); fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks()); fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); fields->Set("event_handler_enabled", host->GetEnableEventHandler()); fields->Set("flap_detection_enabled", host->GetEnableFlapping()); fields->Set("is_flapping", host->IsFlapping()); fields->Set("percent_state_change", host->GetFlappingCurrent()); - - if (cr) { - fields->Set("latency", Convert::ToString(cr->CalculateLatency())); - fields->Set("execution_time", Convert::ToString(cr->CalculateExecutionTime())); - } - fields->Set("scheduled_downtime_depth", host->GetDowntimeDepth()); fields->Set("process_performance_data", host->GetEnablePerfdata()); fields->Set("normal_check_interval", (host->GetCheckInterval() / 60.0)); fields->Set("retry_check_interval", (host->GetRetryInterval() / 60.0)); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); fields->Set("is_reachable", host->IsReachable()); - fields->Set("original_attributes", JsonEncode(host->GetOriginalAttributes())); + fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host)); + fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(host))); + fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(host))); + EventCommand::Ptr eventCommand = host->GetEventCommand(); if (eventCommand) diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index e6f674d84..b48cbf757 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -62,24 +62,6 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("check_interval", (service->GetCheckInterval() / 60.0)); fields->Set("retry_interval", (service->GetRetryInterval() / 60.0)); fields->Set("max_check_attempts", service->GetMaxCheckAttempts()); - fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(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); - fields->Set("stalk_on_critical", 0); fields->Set("is_volatile", service->GetVolatile()); fields->Set("flap_detection_enabled", service->GetEnableFlapping()); fields->Set("low_flap_threshold", service->GetFlappingThresholdLow()); @@ -97,6 +79,20 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("icon_image", service->GetIconImage()); fields->Set("icon_image_alt", service->GetIconImageAlt()); + fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(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)); + return fields; } @@ -111,6 +107,8 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); fields->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); fields->Set("check_source", cr->GetCheckSource()); + fields->Set("latency", cr->CalculateLatency()); + fields->Set("execution_time", cr->CalculateExecutionTime()); } fields->Set("current_state", service->GetState()); @@ -118,47 +116,38 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("should_be_scheduled", service->GetEnableActiveChecks()); fields->Set("current_check_attempt", service->GetCheckAttempt()); fields->Set("max_check_attempts", service->GetMaxCheckAttempts()); - - if (cr) - fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd())); - + fields->Set("last_check", DbValue::FromTimestamp(service->GetLastCheck())); fields->Set("next_check", DbValue::FromTimestamp(service->GetNextCheck())); fields->Set("check_type", !service->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */ fields->Set("last_state_change", DbValue::FromTimestamp(service->GetLastStateChange())); fields->Set("last_hard_state_change", DbValue::FromTimestamp(service->GetLastHardStateChange())); fields->Set("last_hard_state", service->GetLastHardState()); - fields->Set("last_time_ok", DbValue::FromTimestamp(static_cast(service->GetLastStateOK()))); - fields->Set("last_time_warning", DbValue::FromTimestamp(static_cast(service->GetLastStateWarning()))); - fields->Set("last_time_critical", DbValue::FromTimestamp(static_cast(service->GetLastStateCritical()))); - fields->Set("last_time_unknown", DbValue::FromTimestamp(static_cast(service->GetLastStateUnknown()))); + fields->Set("last_time_ok", DbValue::FromTimestamp(service->GetLastStateOK())); + fields->Set("last_time_warning", DbValue::FromTimestamp(service->GetLastStateWarning())); + fields->Set("last_time_critical", DbValue::FromTimestamp(service->GetLastStateCritical())); + fields->Set("last_time_unknown", DbValue::FromTimestamp(service->GetLastStateUnknown())); fields->Set("state_type", service->GetStateType()); - fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(service))); - fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(service))); fields->Set("notifications_enabled", service->GetEnableNotifications()); fields->Set("problem_has_been_acknowledged", service->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", service->GetAcknowledgement()); - fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service)); fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks()); fields->Set("active_checks_enabled", service->GetEnableActiveChecks()); fields->Set("event_handler_enabled", service->GetEnableEventHandler()); fields->Set("flap_detection_enabled", service->GetEnableFlapping()); fields->Set("is_flapping", service->IsFlapping()); fields->Set("percent_state_change", service->GetFlappingCurrent()); - - if (cr) { - fields->Set("latency", Convert::ToString(cr->CalculateLatency())); - fields->Set("execution_time", Convert::ToString(cr->CalculateExecutionTime())); - } - fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth()); fields->Set("process_performance_data", service->GetEnablePerfdata()); fields->Set("normal_check_interval", (service->GetCheckInterval() / 60.0)); fields->Set("retry_check_interval", (service->GetRetryInterval() / 60.0)); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); fields->Set("is_reachable", service->IsReachable()); - fields->Set("original_attributes", JsonEncode(service->GetOriginalAttributes())); + fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service)); + fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(service))); + fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(service))); + EventCommand::Ptr eventCommand = service->GetEventCommand(); if (eventCommand)