]> granicus.if.org Git - icinga2/commitdiff
ido: Fix hosts without hostcheck service not being dumped to config table.
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 2 Aug 2013 12:12:07 +0000 (14:12 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 2 Aug 2013 12:13:27 +0000 (14:13 +0200)
still, the status update must be triggered by icinga2 which does not
happen currently.

fixes #4500

lib/icinga/compatutility.cpp
lib/icinga/compatutility.h
lib/ido/hostdbobject.cpp

index 303f8769410fbb7d7f7a372b3a0043ad27f57601..4d046792730a2bf1b048d573076f7341dc37c28a 100644 (file)
 
 using namespace icinga;
 
+Dictionary::Ptr CompatUtility::GetHostConfigAttributes(const Host::Ptr& host)
+{
+       Dictionary::Ptr attr = boost::make_shared<Dictionary>();
+       Dictionary::Ptr service_attr = boost::make_shared<Dictionary>();
+
+       ASSERT(host->OwnsLock());
+
+       /* host config attributes */
+       Dictionary::Ptr custom;
+       Dictionary::Ptr macros;
+       std::vector<String> notification_options;
+
+       /* dicts */
+       macros = host->GetMacros();
+       custom = host->GetCustom();
+
+       if (macros) {
+               attr->Set("address", macros->Get("address"));
+               attr->Set("address6", macros->Get("address6"));
+       }
+
+       if (custom) {
+               attr->Set("notes", custom->Get("notes"));
+               attr->Set("notes_url", custom->Get("notes_url"));
+               attr->Set("action_url", custom->Get("action_url"));
+               attr->Set("icon_image", custom->Get("icon_image"));
+               attr->Set("icon_image_alt", custom->Get("icon_image_alt"));
+
+               attr->Set("statusmap_image", custom->Get("statusmap_image"));
+               attr->Set("2d_coords", custom->Get("2d_coords"));
+
+               if (!custom->Get("2d_coords").IsEmpty()) {
+                       std::vector<String> tokens;
+                       String coords = custom->Get("2d_coords");
+                       boost::algorithm::split(tokens, coords, boost::is_any_of(","));
+
+                       if (tokens.size() == 2) {
+                               attr->Set("have_2d_coords", 1);
+                               attr->Set("x_2d", tokens[0]);
+                               attr->Set("y_2d", tokens[1]);
+                       }
+                       else
+                               attr->Set("have_2d_coords", 0);
+               }
+               else
+                       attr->Set("have_2d_coords", 0);
+
+               /* deprecated in 1.x, but empty */
+               attr->Set("vrml_image", Empty);
+               attr->Set("3d_coords", Empty);
+               attr->Set("have_3d_coords", 0);
+               attr->Set("x_3d", Empty);
+               attr->Set("y_3d", Empty);
+               attr->Set("z_3d", Empty);
+       }
+
+       /* alias */
+       if (!host->GetDisplayName().IsEmpty())
+               attr->Set("alias", host->GetName());
+       else
+               attr->Set("alias", host->GetDisplayName());
+
+       /* get additonal attributes from hostcheck service */
+       Service::Ptr service = host->GetHostCheckService();
+
+       if (service) {
+               unsigned long notification_type_filter;
+               unsigned long notification_state_filter;
+
+               ObjectLock olock(service);
+
+               BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+                       if (notification->GetNotificationTypeFilter())
+                               notification_type_filter = notification->GetNotificationTypeFilter();
+
+                       if (notification->GetNotificationStateFilter())
+                               notification_state_filter = notification->GetNotificationStateFilter();
+               }
+
+               /* notification state filters */
+               if (notification_state_filter & (1<<StateWarning) ||
+                   notification_state_filter & (1<<StateCritical)) {
+                       attr->Set("notify_on_down", 1);
+                       notification_options.push_back("d");
+               }
+               if (notification_state_filter & (1<<StateUncheckable)) {
+                       attr->Set("notify_on_unreachable", 1);
+                       notification_options.push_back("u");
+               }
+
+               /* notification type filters */
+               if (notification_type_filter & (1<<NotificationRecovery)) {
+                       attr->Set("notify_on_recovery", 1);
+                       notification_options.push_back("r");
+               }
+               if (notification_type_filter & (1<<NotificationFlappingStart) ||
+                   notification_type_filter & (1<<NotificationFlappingEnd)) {
+                       attr->Set("notify_on_flapping", 1);
+                       notification_options.push_back("f");
+               }
+               if (notification_type_filter & (1<<NotificationDowntimeStart) ||
+                   notification_type_filter & (1<<NotificationDowntimeEnd) ||
+                   notification_type_filter & (1<<NotificationDowntimeRemoved)) {
+                       attr->Set("notify_on_downtime", 1);
+                       notification_options.push_back("s");
+               }
+
+               service_attr = CompatUtility::GetServiceConfigAttributes(service, CompatTypeService);
+
+               attr->Set("check_period", service_attr->Get("check_period"));
+               attr->Set("check_interval", service_attr->Get("check_interval"));
+               attr->Set("retry_interval", service_attr->Get("retry_interval"));
+               attr->Set("max_check_attempts", service_attr->Get("max_check_attempts"));
+               attr->Set("active_checks_enabled", service_attr->Get("active_checks_enabled"));
+               attr->Set("passive_checks_enabled", service_attr->Get("passive_checks_enabled"));
+               attr->Set("flap_detection_enabled", service_attr->Get("flap_detection_enabled"));
+               attr->Set("low_flap_threshold", service_attr->Get("low_flap_threshold"));
+               attr->Set("high_flap_threshold", service_attr->Get("high_flap_threshold"));
+               attr->Set("notifications_enabled", service_attr->Get("notifications_enabled"));
+               attr->Set("eventhandler_enabled", service_attr->Get("eventhandler_enabled"));
+               attr->Set("is_volatile", service_attr->Get("is_volatile"));
+               attr->Set("notifications_enabled", service_attr->Get("notifications_enabled"));
+               attr->Set("notification_options", boost::algorithm::join(notification_options, ","));
+               attr->Set("notification_interval", service_attr->Get("notification_interval"));
+               attr->Set("process_performance_data", service_attr->Get("process_performance_data"));
+               attr->Set("notification_period", service_attr->Get("notification_period"));
+               attr->Set("check_freshness", service_attr->Get("check_freshness"));
+               attr->Set("check_command", service_attr->Get("check_command"));
+               attr->Set("event_handler", service_attr->Get("event_handler"));
+       }
+
+       return attr;
+}
+
 Dictionary::Ptr CompatUtility::GetServiceStatusAttributes(const Service::Ptr& service, CompatObjectType type)
 {
        Dictionary::Ptr attr = boost::make_shared<Dictionary>();
index 96d495917bf1027495a6070a5f160a62fb9e3b85..bbed811900f4e0081a89d7f7903b1d408f18be0c 100644 (file)
@@ -46,6 +46,8 @@ enum CompatObjectType
 class I2_ICINGA_API CompatUtility
 {
 public:
+       static Dictionary::Ptr GetHostConfigAttributes(const Host::Ptr& host);
+
        static Dictionary::Ptr GetServiceStatusAttributes(const Service::Ptr& service, CompatObjectType type);
        static Dictionary::Ptr GetServiceConfigAttributes(const Service::Ptr& service, CompatObjectType type);
 
index 7699f9922c5e906a5caaa6194b814f685827e462..815f45a189fb32452bc641d9cb021b1af0fda76d 100644 (file)
@@ -44,14 +44,11 @@ Dictionary::Ptr HostDbObject::GetConfigFields(void) const
 
        Service::Ptr service = host->GetHostCheckService();
 
-       if (!service)
-               return Empty;
-
        Dictionary::Ptr attrs;
 
        {
-               ObjectLock olock(service);
-               attrs = CompatUtility::GetServiceConfigAttributes(service, CompatTypeHost);
+               ObjectLock olock(host);
+               attrs = CompatUtility::GetHostConfigAttributes(host);
        }
 
        fields->Set("alias", attrs->Get("alias"));
@@ -60,12 +57,18 @@ Dictionary::Ptr HostDbObject::GetConfigFields(void) const
        fields->Set("address", attrs->Get("address"));
        fields->Set("address6", attrs->Get("address6"));
 
-       fields->Set("check_command_object_id", service->GetCheckCommand());
-       fields->Set("check_command_args", Empty);
-       fields->Set("eventhandler_command_object_id", service->GetEventCommand());
-       fields->Set("eventhandler_command_args", Empty);
+       if (service) {
+               fields->Set("check_command_object_id", service->GetCheckCommand());
+               fields->Set("check_command_args", Empty);
+               fields->Set("eventhandler_command_object_id", service->GetEventCommand());
+               fields->Set("eventhandler_command_args", Empty);
+       }
+
        fields->Set("notification_timeperiod_object_id", Notification::GetByName(attrs->Get("notification_period")));
-       fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
+
+       if (service)
+               fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
+
        fields->Set("failure_prediction_options", Empty);
 
        fields->Set("check_interval", attrs->Get("check_interval"));
@@ -123,58 +126,63 @@ Dictionary::Ptr HostDbObject::GetStatusFields(void) const
        Host::Ptr host = static_pointer_cast<Host>(GetObject());
        Service::Ptr service = host->GetHostCheckService();
 
-       if (!service)
-               return Empty;
-
        Dictionary::Ptr attrs;
 
-       {
+       /* fetch service status, or dump a pending hoststatus */
+       if (service) {
+
                ObjectLock olock(service);
                attrs = CompatUtility::GetServiceStatusAttributes(service, CompatTypeHost);
-       }
 
-       fields->Set("output", attrs->Get("plugin_output"));
-       fields->Set("long_output", attrs->Get("long_plugin_output"));
-       fields->Set("perfdata", attrs->Get("performance_data"));
-       fields->Set("current_state", attrs->Get("current_state"));
-       fields->Set("has_been_checked", attrs->Get("has_been_checked"));
-       fields->Set("should_be_scheduled", attrs->Get("should_be_scheduled"));
-       fields->Set("current_check_attempt", attrs->Get("current_attempt"));
-       fields->Set("max_check_attempts", attrs->Get("max_attempts"));
-       fields->Set("last_check", DbValue::FromTimestamp(attrs->Get("last_check")));
-       fields->Set("next_check", DbValue::FromTimestamp(attrs->Get("next_check")));
-       fields->Set("check_type", Empty);
-       fields->Set("last_state_change", DbValue::FromTimestamp(attrs->Get("last_state_change")));
-       fields->Set("last_hard_state_change", DbValue::FromTimestamp(attrs->Get("last_hard_state_change")));
-       fields->Set("last_time_up", DbValue::FromTimestamp(attrs->Get("last_time_up")));
-       fields->Set("last_time_down", DbValue::FromTimestamp(attrs->Get("last_time_down")));
-       fields->Set("last_time_unreachable", DbValue::FromTimestamp(attrs->Get("last_time_unreachable")));
-       fields->Set("state_type", attrs->Get("state_type"));
-       fields->Set("last_notification", DbValue::FromTimestamp(attrs->Get("last_notification")));
-       fields->Set("next_notification", DbValue::FromTimestamp(attrs->Get("next_notification")));
-       fields->Set("no_more_notifications", Empty);
-       fields->Set("notifications_enabled", attrs->Get("notifications_enabled"));
-       fields->Set("problem_has_been_acknowledged", attrs->Get("problem_has_been_acknowledged"));
-       fields->Set("acknowledgement_type", attrs->Get("acknowledgement_type"));
-       fields->Set("current_notification_number", attrs->Get("current_notification_number"));
-       fields->Set("passive_checks_enabled", attrs->Get("passive_checks_enabled"));
-       fields->Set("active_checks_enabled", attrs->Get("active_checks_enabled"));
-       fields->Set("eventhandler_enabled", attrs->Get("eventhandler_enabled"));
-       fields->Set("flap_detection_enabled", attrs->Get("flap_detection_enabled"));
-       fields->Set("is_flapping", attrs->Get("is_flapping"));
-       fields->Set("percent_state_change", attrs->Get("percent_state_change"));
-       fields->Set("latency", attrs->Get("check_latency"));
-       fields->Set("execution_time", attrs->Get("check_execution_time"));
-       fields->Set("scheduled_downtime_depth", attrs->Get("scheduled_downtime_depth"));
-       fields->Set("failure_prediction_enabled", Empty);
-       fields->Set("process_performance_data", attrs->Get("process_performance_data"));
-       fields->Set("obsess_over_host", Empty);
-       fields->Set("modified_host_attributes", Empty);
-       fields->Set("event_handler", attrs->Get("event_handler"));
-       fields->Set("check_command", attrs->Get("check_command"));
-       fields->Set("normal_check_interval", attrs->Get("check_interval"));
-       fields->Set("retry_check_interval", attrs->Get("retry_interval"));
-       fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
+               fields->Set("output", attrs->Get("plugin_output"));
+               fields->Set("long_output", attrs->Get("long_plugin_output"));
+               fields->Set("perfdata", attrs->Get("performance_data"));
+               fields->Set("current_state", attrs->Get("current_state"));
+               fields->Set("has_been_checked", attrs->Get("has_been_checked"));
+               fields->Set("should_be_scheduled", attrs->Get("should_be_scheduled"));
+               fields->Set("current_check_attempt", attrs->Get("current_attempt"));
+               fields->Set("max_check_attempts", attrs->Get("max_attempts"));
+               fields->Set("last_check", DbValue::FromTimestamp(attrs->Get("last_check")));
+               fields->Set("next_check", DbValue::FromTimestamp(attrs->Get("next_check")));
+               fields->Set("check_type", Empty);
+               fields->Set("last_state_change", DbValue::FromTimestamp(attrs->Get("last_state_change")));
+               fields->Set("last_hard_state_change", DbValue::FromTimestamp(attrs->Get("last_hard_state_change")));
+               fields->Set("last_time_up", DbValue::FromTimestamp(attrs->Get("last_time_up")));
+               fields->Set("last_time_down", DbValue::FromTimestamp(attrs->Get("last_time_down")));
+               fields->Set("last_time_unreachable", DbValue::FromTimestamp(attrs->Get("last_time_unreachable")));
+               fields->Set("state_type", attrs->Get("state_type"));
+               fields->Set("last_notification", DbValue::FromTimestamp(attrs->Get("last_notification")));
+               fields->Set("next_notification", DbValue::FromTimestamp(attrs->Get("next_notification")));
+               fields->Set("no_more_notifications", Empty);
+               fields->Set("notifications_enabled", attrs->Get("notifications_enabled"));
+               fields->Set("problem_has_been_acknowledged", attrs->Get("problem_has_been_acknowledged"));
+               fields->Set("acknowledgement_type", attrs->Get("acknowledgement_type"));
+               fields->Set("current_notification_number", attrs->Get("current_notification_number"));
+               fields->Set("passive_checks_enabled", attrs->Get("passive_checks_enabled"));
+               fields->Set("active_checks_enabled", attrs->Get("active_checks_enabled"));
+               fields->Set("eventhandler_enabled", attrs->Get("eventhandler_enabled"));
+               fields->Set("flap_detection_enabled", attrs->Get("flap_detection_enabled"));
+               fields->Set("is_flapping", attrs->Get("is_flapping"));
+               fields->Set("percent_state_change", attrs->Get("percent_state_change"));
+               fields->Set("latency", attrs->Get("check_latency"));
+               fields->Set("execution_time", attrs->Get("check_execution_time"));
+               fields->Set("scheduled_downtime_depth", attrs->Get("scheduled_downtime_depth"));
+               fields->Set("failure_prediction_enabled", Empty);
+               fields->Set("process_performance_data", attrs->Get("process_performance_data"));
+               fields->Set("obsess_over_host", Empty);
+               fields->Set("modified_host_attributes", Empty);
+               fields->Set("event_handler", attrs->Get("event_handler"));
+               fields->Set("check_command", attrs->Get("check_command"));
+               fields->Set("normal_check_interval", attrs->Get("check_interval"));
+               fields->Set("retry_check_interval", attrs->Get("retry_interval"));
+               fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
+       }
+       else {
+               fields->Set("has_been_checked", 0);
+               fields->Set("last_check", DbValue::FromTimestamp(0));
+               fields->Set("next_check", DbValue::FromTimestamp(0));
+               fields->Set("active_checks_enabled", 0);
+       }
 
        return fields;
 }