From 88197d216adde18a123f2e29e98b8cf22c065488 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 5 Jul 2013 09:35:49 +0200 Subject: [PATCH] livestatus: add first part of host data providers refs #4372 --- components/livestatus/hoststable.cpp | 995 ++++++++++++++++++++++++--- components/livestatus/hoststable.h | 109 +++ components/livestatus/table.h | 1 + lib/icinga/host.cpp | 115 ++++ lib/icinga/host.h | 17 + lib/icinga/service-check.cpp | 79 ++- lib/icinga/service-downtime.cpp | 19 + lib/icinga/service.cpp | 6 + lib/icinga/service.h | 14 + 9 files changed, 1248 insertions(+), 107 deletions(-) diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 5e1786e3a..35475e726 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -19,8 +19,13 @@ #include "livestatus/hoststable.h" #include "icinga/host.h" +#include "icinga/service.h" +#include "icinga/checkcommand.h" +#include "icinga/eventcommand.h" +#include "icinga/timeperiod.h" #include "base/dynamictype.h" #include +#include using namespace icinga; using namespace livestatus; @@ -35,112 +40,114 @@ void HostsTable::AddColumns(Table *table, const String& prefix, { table->AddColumn(prefix + "name", Column(&HostsTable::NameAccessor, objectAccessor)); table->AddColumn(prefix + "display_name", Column(&HostsTable::DisplayNameAccessor, objectAccessor)); - table->AddColumn(prefix + "alias", Column(&HostsTable::NameAccessor, objectAccessor)); - table->AddColumn(prefix + "address", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "check_command", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "check_command_expanded", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "event_handler", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "notification_period", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "check_period", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "notes", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "notes_expanded", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "notes_url", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "notes_url_expanded", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "action_url", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "action_url_expanded", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "plugin_output", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "perf_data", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "icon_image", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "icon_image_expanded", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "icon_image_alt", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "statusmap_image", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "long_plugin_output", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "initial_state", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "max_check_attempts", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "flap_detection_enabled", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "check_freshness", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "process_performance_data", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "accept_passive_checks", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "event_handler_enabled", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "acknowledgement_type", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "check_type", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_state", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_hard_state", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "current_attempt", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_notification", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "next_notification", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "next_check", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_hard_state_change", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "has_been_checked", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "current_notification_number", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "pending_flex_downtime", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "total_services", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "checks_enabled", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "notifications_enabled", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "acknowledged", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "state", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "state_type", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "no_more_notifications", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "check_flapping_recovery_notification", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_check", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_state_change", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_time_up", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_time_down", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "last_time_unreachable", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "is_flapping", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "scheduled_downtime_depth", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "is_executing", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "active_checks_enabled", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "check_options", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "obsess_over_host", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "modified_attributes", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "modified_attributes_list", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "check_interval", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "retry_interval", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "notification_interval", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "first_notification_delay", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "low_flap_threshold", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "high_flap_threshold", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "x_3d", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "y_3d", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "z_3d", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "latency", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "execution_time", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "percent_state_change", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "in_notification_period", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "in_check_period", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "contacts", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "downtimes", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "downtimes_with_info", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "comments", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "comments_with_info", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "comments_with_extra_info", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "custom_variable_names", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "custom_variable_values", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "custom_variables", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "filename", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "parents", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "childs", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "worst_service_state", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_ok", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_warn", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_crit", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_unknown", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_pending", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "worst_service_hard_state", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_hard_ok", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_hard_warn", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_hard_crit", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services_hard_unknown", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "hard_state", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "pnpgraph_present", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "groups", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "contact_groups", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "services", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "services_with_state", Column(&Table::EmptyDictionaryAccessor, objectAccessor)); - table->AddColumn(prefix + "services_with_info", Column(&Table::EmptyDictionaryAccessor, objectAccessor)); - table->AddColumn(prefix + "groups", Column(&Table::EmptyArrayAccessor, objectAccessor)); + table->AddColumn(prefix + "alias", Column(&HostsTable::DisplayNameAccessor, objectAccessor)); + table->AddColumn(prefix + "address", Column(&HostsTable::AddressAccessor, objectAccessor)); + table->AddColumn(prefix + "address6", Column(&HostsTable::Address6Accessor, objectAccessor)); + 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 + "check_period", Column(&HostsTable::CheckPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "notes", Column(&HostsTable::NotesAccessor, objectAccessor)); + table->AddColumn(prefix + "notes_expanded", Column(&HostsTable::NotesExpandedAccessor, objectAccessor)); + table->AddColumn(prefix + "notes_url", Column(&HostsTable::NotesUrlAccessor, objectAccessor)); + table->AddColumn(prefix + "notes_url_expanded", Column(&HostsTable::NotesUrlExpandedAccessor, objectAccessor)); + table->AddColumn(prefix + "action_url", Column(&HostsTable::ActionUrlAccessor, objectAccessor)); + table->AddColumn(prefix + "action_url_expanded", Column(&HostsTable::ActionUrlExpandedAccessor, objectAccessor)); + table->AddColumn(prefix + "plugin_output", Column(&HostsTable::PluginOutputAccessor, objectAccessor)); + table->AddColumn(prefix + "perf_data", Column(&HostsTable::PerfDataAccessor, objectAccessor)); + table->AddColumn(prefix + "icon_image", Column(&HostsTable::IconImageAccessor, objectAccessor)); + table->AddColumn(prefix + "icon_image_expanded", Column(&HostsTable::IconImageExpandedAccessor, objectAccessor)); + table->AddColumn(prefix + "icon_image_alt", Column(&HostsTable::IconImageAltAccessor, objectAccessor)); + table->AddColumn(prefix + "statusmap_image", Column(&HostsTable::StatusmapImageAccessor, objectAccessor)); + table->AddColumn(prefix + "long_plugin_output", Column(&HostsTable::LongPluginOutputAccessor, objectAccessor)); + table->AddColumn(prefix + "initial_state", Column(&HostsTable::InitialStateAccessor, objectAccessor)); + table->AddColumn(prefix + "max_check_attempts", Column(&HostsTable::MaxCheckAttemptsAccessor, objectAccessor)); + table->AddColumn(prefix + "flap_detection_enabled", Column(&HostsTable::FlapDetectionEnabledAccessor, objectAccessor)); + table->AddColumn(prefix + "check_freshness", Column(&HostsTable::CheckFreshnessAccessor, objectAccessor)); + table->AddColumn(prefix + "process_performance_data", Column(&HostsTable::ProcessPerformanceDataAccessor, objectAccessor)); + table->AddColumn(prefix + "accept_passive_checks", Column(&HostsTable::AcceptPassiveChecksAccessor, objectAccessor)); + table->AddColumn(prefix + "event_handler_enabled", Column(&HostsTable::EventHandlerEnabledAccessor, objectAccessor)); + table->AddColumn(prefix + "acknowledgement_type", Column(&HostsTable::AcknowledgementTypeAccessor, objectAccessor)); + table->AddColumn(prefix + "check_type", Column(&HostsTable::CheckTypeAccessor, objectAccessor)); + table->AddColumn(prefix + "last_state", Column(&HostsTable::LastStateAccessor, objectAccessor)); + table->AddColumn(prefix + "last_hard_state", Column(&HostsTable::LastHardStateAccessor, objectAccessor)); + table->AddColumn(prefix + "current_attempt", Column(&HostsTable::CurrentAttemptAccessor, objectAccessor)); + table->AddColumn(prefix + "last_notification", Column(&HostsTable::LastNotificationAccessor, objectAccessor)); + table->AddColumn(prefix + "next_notification", Column(&HostsTable::NextNotificationAccessor, objectAccessor)); + table->AddColumn(prefix + "next_check", Column(&HostsTable::NextCheckAccessor, objectAccessor)); + table->AddColumn(prefix + "last_hard_state_change", Column(&HostsTable::LastHardStateChangeAccessor, objectAccessor)); + table->AddColumn(prefix + "has_been_checked", Column(&HostsTable::HasBeenCheckedAccessor, objectAccessor)); + table->AddColumn(prefix + "current_notification_number", Column(&HostsTable::CurrentNotificationNumberAccessor, objectAccessor)); + table->AddColumn(prefix + "pending_flex_downtime", Column(&HostsTable::PendingFlexDowntimeAccessor, objectAccessor)); + table->AddColumn(prefix + "total_services", Column(&HostsTable::TotalServicesAccessor, objectAccessor)); + table->AddColumn(prefix + "checks_enabled", Column(&HostsTable::ChecksEnabledAccessor, objectAccessor)); + table->AddColumn(prefix + "notifications_enabled", Column(&HostsTable::NotificationsEnabledAccessor, objectAccessor)); + table->AddColumn(prefix + "acknowledged", Column(&HostsTable::AcknowledgedAccessor, objectAccessor)); + table->AddColumn(prefix + "state", Column(&HostsTable::StateAccessor, objectAccessor)); + table->AddColumn(prefix + "state_type", Column(&HostsTable::StateTypeAccessor, objectAccessor)); + table->AddColumn(prefix + "no_more_notifications", Column(&HostsTable::NoMoreNotificationsAccessor, objectAccessor)); + table->AddColumn(prefix + "check_flapping_recovery_notification", Column(&HostsTable::CheckFlappingRecoveryNotificationAccessor, objectAccessor)); + table->AddColumn(prefix + "last_check", Column(&HostsTable::LastCheckAccessor, objectAccessor)); + table->AddColumn(prefix + "last_state_change", Column(&HostsTable::LastStateChangeAccessor, objectAccessor)); + table->AddColumn(prefix + "last_time_up", Column(&HostsTable::LastTimeUpAccessor, objectAccessor)); + table->AddColumn(prefix + "last_time_down", Column(&HostsTable::LastTimeDownAccessor, objectAccessor)); + table->AddColumn(prefix + "last_time_unreachable", Column(&HostsTable::LastTimeUnreachableAccessor, objectAccessor)); + table->AddColumn(prefix + "is_flapping", Column(&HostsTable::IsFlappingAccessor, objectAccessor)); + table->AddColumn(prefix + "scheduled_downtime_depth", Column(&HostsTable::ScheduledDowntimeDepthAccessor, objectAccessor)); + table->AddColumn(prefix + "is_executing", Column(&HostsTable::IsExecutingAccessor, objectAccessor)); + table->AddColumn(prefix + "active_checks_enabled", Column(&HostsTable::ActiveChecksEnabledAccessor, objectAccessor)); + table->AddColumn(prefix + "check_options", Column(&HostsTable::CheckOptionsAccessor, objectAccessor)); + table->AddColumn(prefix + "obsess_over_host", Column(&HostsTable::ObsessOverHostAccessor, objectAccessor)); + table->AddColumn(prefix + "modified_attributes", Column(&HostsTable::ModifiedAttributesAccessor, objectAccessor)); + table->AddColumn(prefix + "modified_attributes_list", Column(&HostsTable::ModifiedAttributesListAccessor, objectAccessor)); + table->AddColumn(prefix + "check_interval", Column(&HostsTable::CheckIntervalAccessor, objectAccessor)); + table->AddColumn(prefix + "retry_interval", Column(&HostsTable::RetryIntervalAccessor, objectAccessor)); + table->AddColumn(prefix + "notification_interval", Column(&HostsTable::NotificationIntervalAccessor, objectAccessor)); + table->AddColumn(prefix + "first_notification_delay", Column(&HostsTable::FirstNotificationDelayAccessor, objectAccessor)); + table->AddColumn(prefix + "low_flap_threshold", Column(&HostsTable::LowFlapThresholdAccessor, objectAccessor)); + table->AddColumn(prefix + "high_flap_threshold", Column(&HostsTable::HighFlapThresholdAccessor, objectAccessor)); + table->AddColumn(prefix + "x_3d", Column(&HostsTable::X3dAccessor, objectAccessor)); + table->AddColumn(prefix + "y_3d", Column(&HostsTable::Y3dAccessor, objectAccessor)); + table->AddColumn(prefix + "z_3d", Column(&HostsTable::Z3dAccessor, objectAccessor)); + table->AddColumn(prefix + "x_2d", Column(&HostsTable::X2dAccessor, objectAccessor)); + table->AddColumn(prefix + "y_2d", Column(&HostsTable::Y2dAccessor, objectAccessor)); + table->AddColumn(prefix + "latency", Column(&HostsTable::LatencyAccessor, objectAccessor)); + table->AddColumn(prefix + "execution_time", Column(&HostsTable::ExecutionTimeAccessor, objectAccessor)); + table->AddColumn(prefix + "percent_state_change", Column(&HostsTable::PercentStateChangeAccessor, objectAccessor)); + table->AddColumn(prefix + "in_notification_period", Column(&HostsTable::InNotificationPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "in_check_period", Column(&HostsTable::InCheckPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "contacts", Column(&HostsTable::ContactsAccessor, objectAccessor)); + table->AddColumn(prefix + "downtimes", Column(&HostsTable::DowntimesAccessor, objectAccessor)); + table->AddColumn(prefix + "downtimes_with_info", Column(&HostsTable::DowntimesWithInfoAccessor, objectAccessor)); + table->AddColumn(prefix + "comments", Column(&HostsTable::CommentsAccessor, objectAccessor)); + table->AddColumn(prefix + "comments_with_info", Column(&HostsTable::CommentsWithInfoAccessor, objectAccessor)); + table->AddColumn(prefix + "comments_with_extra_info", Column(&HostsTable::CommentsWithExtraInfoAccessor, objectAccessor)); + table->AddColumn(prefix + "custom_variable_names", Column(&HostsTable::CustomVariableNamesAccessor, objectAccessor)); + table->AddColumn(prefix + "custom_variable_values", Column(&HostsTable::CustomVariableValuesAccessor, objectAccessor)); + table->AddColumn(prefix + "custom_variables", Column(&HostsTable::CustomVariablesAccessor, objectAccessor)); + table->AddColumn(prefix + "filename", Column(&HostsTable::FilenameAccessor, objectAccessor)); + table->AddColumn(prefix + "parents", Column(&HostsTable::ParentsAccessor, objectAccessor)); + table->AddColumn(prefix + "childs", Column(&HostsTable::ChildsAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services", Column(&HostsTable::NumServicesAccessor, objectAccessor)); + table->AddColumn(prefix + "worst_service_state", Column(&HostsTable::WorstServiceStateAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_ok", Column(&HostsTable::NumServicesOkAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_warn", Column(&HostsTable::NumServicesWarnAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_crit", Column(&HostsTable::NumServicesCritAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_unknown", Column(&HostsTable::NumServicesUnknownAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_pending", Column(&HostsTable::NumServicesPendingAccessor, objectAccessor)); + table->AddColumn(prefix + "worst_service_hard_state", Column(&HostsTable::WorstServiceHardStateAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_hard_ok", Column(&HostsTable::NumServicesHardOkAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_hard_warn", Column(&HostsTable::NumServicesHardWarnAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_hard_crit", Column(&HostsTable::NumServicesHardCritAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services_hard_unknown", Column(&HostsTable::NumServicesHardUnknownAccessor, objectAccessor)); + table->AddColumn(prefix + "hard_state", Column(&HostsTable::HardStateAccessor, objectAccessor)); + table->AddColumn(prefix + "pnpgraph_present", Column(&HostsTable::PnpgraphPresentAccessor, objectAccessor)); + table->AddColumn(prefix + "groups", Column(&HostsTable::GroupsAccessor, objectAccessor)); + table->AddColumn(prefix + "contact_groups", Column(&HostsTable::ContactGroupsAccessor, objectAccessor)); + table->AddColumn(prefix + "services", Column(&HostsTable::ServicesAccessor, objectAccessor)); + table->AddColumn(prefix + "services_with_state", Column(&HostsTable::ServicesWithStateAccessor, objectAccessor)); + table->AddColumn(prefix + "services_with_info", Column(&HostsTable::ServicesWithInfoAccessor, objectAccessor)); } String HostsTable::GetName(void) const @@ -164,3 +171,779 @@ Value HostsTable::DisplayNameAccessor(const Object::Ptr& object) { return static_pointer_cast(object)->GetDisplayName(); } + +Value HostsTable::AddressAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr macros = static_pointer_cast(object)->GetMacros(); + return macros->Get("address"); +} + +Value HostsTable::Address6Accessor(const Object::Ptr& object) +{ + Dictionary::Ptr macros = static_pointer_cast(object)->GetMacros(); + return macros->Get("address6"); +} + +Value HostsTable::CheckCommandAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + CheckCommand::Ptr checkcommand = hc->GetCheckCommand(); + if (checkcommand) + return checkcommand->GetName(); /* this is the name without '!' args */ + + return Value(); +} + +Value HostsTable::CheckCommandExpandedAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + CheckCommand::Ptr checkcommand = hc->GetCheckCommand(); + if (checkcommand) + return checkcommand->GetName(); /* this is the name without '!' args */ + + return Value(); +} + +Value HostsTable::EventHandlerAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + EventCommand::Ptr eventcommand = hc->GetEventCommand(); + if (eventcommand) + return eventcommand->GetName(); + + return Value(); +} + +Value HostsTable::NotificationPeriodAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + /* TODO hc->GetNotifications->(loop)->GetNotificationPeriod() */ + return Value(); +} + +Value HostsTable::CheckPeriodAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetCheckPeriod()->GetName(); + /* + TimePeriod::Ptr timeperiod = hc->GetCheckPeriod; + if (!timeperiod) + return Value(); + + return timeperiod->GetName(); + */ +} + +Value HostsTable::NotesAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr custom = static_pointer_cast(object)->GetCustom(); + return custom->Get("notes"); +} + +Value HostsTable::NotesExpandedAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NotesUrlAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr custom = static_pointer_cast(object)->GetCustom(); + return custom->Get("notes_url"); +} + +Value HostsTable::NotesUrlExpandedAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::ActionUrlAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr custom = static_pointer_cast(object)->GetCustom(); + return custom->Get("action_url"); +} + +Value HostsTable::ActionUrlExpandedAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::PluginOutputAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + String output; + + if(hc) + output = hc->GetLastCheckOutput(); + + return output; +} + +Value HostsTable::PerfDataAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + String perfdata; + + if (hc) + perfdata = hc->GetLastCheckPerfData(); + + return perfdata; +} + +Value HostsTable::IconImageAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr custom = static_pointer_cast(object)->GetCustom(); + return custom->Get("icon_image"); +} + +Value HostsTable::IconImageAltAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr custom = static_pointer_cast(object)->GetCustom(); + return custom->Get("icon_image_alt"); +} + +Value HostsTable::StatusmapImageAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr custom = static_pointer_cast(object)->GetCustom(); + return custom->Get("statusmap_image"); +} + +Value HostsTable::LongPluginOutputAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + String long_output; + + if (hc) + long_output = hc->GetLastCheckLongOutput(); + + return long_output; +} + +Value HostsTable::MaxCheckAttemptsAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetMaxCheckAttempts(); +} + +Value HostsTable::FlapDetectionEnabledAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->GetEnableFlapping() ? 1 : 0); +} + +Value HostsTable::CheckFreshnessAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::ProcessPerformanceDataAccessor(const Object::Ptr& object) +{ + /* TODO always enabled */ + return Value(1); +} + +Value HostsTable::AcceptPassiveChecksAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->GetEnablePassiveChecks() ? 1 : 0); +} + +Value HostsTable::EventHandlerEnabledAccessor(const Object::Ptr& object) +{ + /* TODO always enabled */ + return Value(1); +} + +Value HostsTable::AcknowledgementTypeAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return static_cast(hc->GetAcknowledgement()); +} + +Value HostsTable::CheckTypeAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->GetEnableActiveChecks() ? 1 : 0); +} + +Value HostsTable::LastStateAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetLastState(); +} + +Value HostsTable::LastHardStateAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetLastHardState(); +} + +Value HostsTable::CurrentAttemptAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetCurrentCheckAttempt(); +} + +Value HostsTable::LastNotificationAccessor(const Object::Ptr& object) +{ + /* TODO Host->Service->GetNotifications->(loop)->GetLastNotification() */ + return Value(); +} + +Value HostsTable::NextNotificationAccessor(const Object::Ptr& object) +{ + /* TODO Host->Service->GetNotifications->(loop)->GetNextNotification() */ + return Value(); +} + +Value HostsTable::NextCheckAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetNextCheck(); +} + +Value HostsTable::LastHardStateChangeAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetLastHardStateChange(); +} + +Value HostsTable::HasBeenCheckedAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->HasBeenChecked() ? 1 : 0); +} + +Value HostsTable::CurrentNotificationNumberAccessor(const Object::Ptr& object) +{ + /* TODO Host->Service->GetNotifications->(loop) new attribute */ + return Value(); +} + +Value HostsTable::PendingFlexDowntimeAccessor(const Object::Ptr& object) +{ + /* TODO Host->Service->GetDowntimes->(loop) type flexible? */ + return Value(); +} + +Value HostsTable::TotalServicesAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetTotalServices(); +} + +Value HostsTable::ChecksEnabledAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->GetEnableActiveChecks() ? 1 : 0); +} + +Value HostsTable::NotificationsEnabledAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->GetEnableNotifications() ? 1 : 0); +} + +Value HostsTable::AcknowledgedAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->IsAcknowledged() ? 1 : 0); +} + +Value HostsTable::StateAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetState(); +} + +Value HostsTable::StateTypeAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetStateType(); +} + +Value HostsTable::NoMoreNotificationsAccessor(const Object::Ptr& object) +{ + /* TODO: notification_interval == 0, volatile == false */ + return Value(0); +} + +Value HostsTable::CheckFlappingRecoveryNotificationAccessor(const Object::Ptr& object) +{ + /* TODO: if we're flapping, state != OK && notified once, set to true */ + return Value(0); +} + +Value HostsTable::LastCheckAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetLastCheck(); +} + +Value HostsTable::LastStateChangeAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetLastStateChange(); +} + +Value HostsTable::LastTimeUpAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::LastTimeDownAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::LastTimeUnreachableAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::IsFlappingAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->IsFlapping(); +} + +Value HostsTable::ScheduledDowntimeDepthAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetDowntimeDepth(); +} + +Value HostsTable::IsExecutingAccessor(const Object::Ptr& object) +{ + /* TODO does that make sense with Icinga2? */ + return Value(); +} + +Value HostsTable::ActiveChecksEnabledAccessor(const Object::Ptr& object) +{ + /* duplicate of ChecksEnableAccessor */ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->GetEnableActiveChecks() ? 1 : 0); +} + +Value HostsTable::CheckOptionsAccessor(const Object::Ptr& object) +{ + /* TODO - forcexec, freshness, orphan, none */ + return Value(); +} + +Value HostsTable::ObsessOverHostAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value HostsTable::ModifiedAttributesAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value HostsTable::ModifiedAttributesListAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value HostsTable::CheckIntervalAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->GetCheckInterval() / 60.0); +} + +Value HostsTable::RetryIntervalAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (hc->GetRetryInterval() / 60.0); +} + +Value HostsTable::NotificationIntervalAccessor(const Object::Ptr& object) +{ + /* TODO Host->Services->GetNotifications->(loop)->GetNotificationInterval() */ + return Value(); +} + +Value HostsTable::FirstNotificationDelayAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value HostsTable::LowFlapThresholdAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::HighFlapThresholdAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::X3dAccessor(const Object::Ptr& object) +{ + /* not supported - removed in Icinga 1.x */ + return Value(); +} + +Value HostsTable::Y3dAccessor(const Object::Ptr& object) +{ + /* not supported - removed in Icinga 1.x */ + return Value(); +} + +Value HostsTable::Z3dAccessor(const Object::Ptr& object) +{ + /* not supported - removed in Icinga 1.x */ + return Value(); +} + +Value HostsTable::X2dAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::Y2dAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::LatencyAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (Service::CalculateLatency(hc->GetLastCheckResult())); +} + +Value HostsTable::ExecutionTimeAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return (Service::CalculateExecutionTime(hc->GetLastCheckResult())); +} + +Value HostsTable::PercentStateChangeAccessor(const Object::Ptr& object) +{ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetFlappingCurrent(); +} + +Value HostsTable::InNotificationPeriodAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::InCheckPeriodAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::ContactsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::DowntimesWithInfoAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::CommentsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::CommentsWithInfoAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::CommentsWithExtraInfoAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::CustomVariableNamesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::CustomVariableValuesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::CustomVariablesAccessor(const Object::Ptr& object) +{ + /* TODO Dictionary */ + return Value(); +} +Value HostsTable::FilenameAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::ParentsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::ChildsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::WorstServiceStateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesOkAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesWarnAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesCritAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesUnknownAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesPendingAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::WorstServiceHardStateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesHardOkAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesHardWarnAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesHardCritAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::NumServicesHardUnknownAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::HardStateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::PnpgraphPresentAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::StalenessAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::GroupsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::ContactGroupsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::ServicesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +/* dictionary */ +Value HostsTable::ServicesWithStateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value HostsTable::ServicesWithInfoAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + diff --git a/components/livestatus/hoststable.h b/components/livestatus/hoststable.h index e299c63d5..6c8fdd692 100644 --- a/components/livestatus/hoststable.h +++ b/components/livestatus/hoststable.h @@ -48,6 +48,115 @@ protected: static Value NameAccessor(const Object::Ptr& object); static Value DisplayNameAccessor(const Object::Ptr& object); + static Value AddressAccessor(const Object::Ptr& object); + static Value Address6Accessor(const Object::Ptr& object); + static Value CheckCommandAccessor(const Object::Ptr& object); + static Value CheckCommandExpandedAccessor(const Object::Ptr& object); + static Value EventHandlerAccessor(const Object::Ptr& object); + static Value NotificationPeriodAccessor(const Object::Ptr& object); + static Value CheckPeriodAccessor(const Object::Ptr& object); + static Value NotesAccessor(const Object::Ptr& object); + static Value NotesExpandedAccessor(const Object::Ptr& object); + static Value NotesUrlAccessor(const Object::Ptr& object); + static Value NotesUrlExpandedAccessor(const Object::Ptr& object); + static Value ActionUrlAccessor(const Object::Ptr& object); + static Value ActionUrlExpandedAccessor(const Object::Ptr& object); + static Value PluginOutputAccessor(const Object::Ptr& object); + static Value PerfDataAccessor(const Object::Ptr& object); + static Value IconImageAccessor(const Object::Ptr& object); + static Value IconImageExpandedAccessor(const Object::Ptr& object); + static Value IconImageAltAccessor(const Object::Ptr& object); + static Value StatusmapImageAccessor(const Object::Ptr& object); + static Value LongPluginOutputAccessor(const Object::Ptr& object); + static Value InitialStateAccessor(const Object::Ptr& object); + static Value MaxCheckAttemptsAccessor(const Object::Ptr& object); + static Value FlapDetectionEnabledAccessor(const Object::Ptr& object); + static Value CheckFreshnessAccessor(const Object::Ptr& object); + static Value ProcessPerformanceDataAccessor(const Object::Ptr& object); + static Value AcceptPassiveChecksAccessor(const Object::Ptr& object); + static Value EventHandlerEnabledAccessor(const Object::Ptr& object); + static Value AcknowledgementTypeAccessor(const Object::Ptr& object); + static Value CheckTypeAccessor(const Object::Ptr& object); + static Value LastStateAccessor(const Object::Ptr& object); + static Value LastHardStateAccessor(const Object::Ptr& object); + static Value CurrentAttemptAccessor(const Object::Ptr& object); + static Value LastNotificationAccessor(const Object::Ptr& object); + static Value NextNotificationAccessor(const Object::Ptr& object); + static Value NextCheckAccessor(const Object::Ptr& object); + static Value LastHardStateChangeAccessor(const Object::Ptr& object); + static Value HasBeenCheckedAccessor(const Object::Ptr& object); + static Value CurrentNotificationNumberAccessor(const Object::Ptr& object); + static Value PendingFlexDowntimeAccessor(const Object::Ptr& object); + static Value TotalServicesAccessor(const Object::Ptr& object); + static Value ChecksEnabledAccessor(const Object::Ptr& object); + static Value NotificationsEnabledAccessor(const Object::Ptr& object); + static Value AcknowledgedAccessor(const Object::Ptr& object); + static Value StateAccessor(const Object::Ptr& object); + static Value StateTypeAccessor(const Object::Ptr& object); + static Value NoMoreNotificationsAccessor(const Object::Ptr& object); + static Value CheckFlappingRecoveryNotificationAccessor(const Object::Ptr& object); + static Value LastCheckAccessor(const Object::Ptr& object); + static Value LastStateChangeAccessor(const Object::Ptr& object); + static Value LastTimeUpAccessor(const Object::Ptr& object); + static Value LastTimeDownAccessor(const Object::Ptr& object); + static Value LastTimeUnreachableAccessor(const Object::Ptr& object); + static Value IsFlappingAccessor(const Object::Ptr& object); + static Value ScheduledDowntimeDepthAccessor(const Object::Ptr& object); + static Value IsExecutingAccessor(const Object::Ptr& object); + static Value ActiveChecksEnabledAccessor(const Object::Ptr& object); + static Value CheckOptionsAccessor(const Object::Ptr& object); + static Value ObsessOverHostAccessor(const Object::Ptr& object); + static Value ModifiedAttributesAccessor(const Object::Ptr& object); + static Value ModifiedAttributesListAccessor(const Object::Ptr& object); + static Value CheckIntervalAccessor(const Object::Ptr& object); + static Value RetryIntervalAccessor(const Object::Ptr& object); + static Value NotificationIntervalAccessor(const Object::Ptr& object); + static Value FirstNotificationDelayAccessor(const Object::Ptr& object); + static Value LowFlapThresholdAccessor(const Object::Ptr& object); + static Value HighFlapThresholdAccessor(const Object::Ptr& object); + static Value X3dAccessor(const Object::Ptr& object); + static Value Y3dAccessor(const Object::Ptr& object); + static Value Z3dAccessor(const Object::Ptr& object); + static Value X2dAccessor(const Object::Ptr& object); + static Value Y2dAccessor(const Object::Ptr& object); + static Value LatencyAccessor(const Object::Ptr& object); + static Value ExecutionTimeAccessor(const Object::Ptr& object); + static Value PercentStateChangeAccessor(const Object::Ptr& object); + static Value InNotificationPeriodAccessor(const Object::Ptr& object); + static Value InCheckPeriodAccessor(const Object::Ptr& object); + static Value ContactsAccessor(const Object::Ptr& object); + static Value DowntimesAccessor(const Object::Ptr& object); + static Value DowntimesWithInfoAccessor(const Object::Ptr& object); + static Value CommentsAccessor(const Object::Ptr& object); + static Value CommentsWithInfoAccessor(const Object::Ptr& object); + static Value CommentsWithExtraInfoAccessor(const Object::Ptr& object); + static Value CustomVariableNamesAccessor(const Object::Ptr& object); + static Value CustomVariableValuesAccessor(const Object::Ptr& object); + static Value CustomVariablesAccessor(const Object::Ptr& object); + static Value FilenameAccessor(const Object::Ptr& object); + static Value ParentsAccessor(const Object::Ptr& object); + static Value ChildsAccessor(const Object::Ptr& object); + static Value NumServicesAccessor(const Object::Ptr& object); + static Value WorstServiceStateAccessor(const Object::Ptr& object); + static Value NumServicesOkAccessor(const Object::Ptr& object); + static Value NumServicesWarnAccessor(const Object::Ptr& object); + static Value NumServicesCritAccessor(const Object::Ptr& object); + static Value NumServicesUnknownAccessor(const Object::Ptr& object); + static Value NumServicesPendingAccessor(const Object::Ptr& object); + static Value WorstServiceHardStateAccessor(const Object::Ptr& object); + static Value NumServicesHardOkAccessor(const Object::Ptr& object); + static Value NumServicesHardWarnAccessor(const Object::Ptr& object); + static Value NumServicesHardCritAccessor(const Object::Ptr& object); + static Value NumServicesHardUnknownAccessor(const Object::Ptr& object); + static Value HardStateAccessor(const Object::Ptr& object); + static Value PnpgraphPresentAccessor(const Object::Ptr& object); + static Value StalenessAccessor(const Object::Ptr& object); + static Value GroupsAccessor(const Object::Ptr& object); + static Value ContactGroupsAccessor(const Object::Ptr& object); + static Value ServicesAccessor(const Object::Ptr& object); + + static Value ServicesWithStateAccessor(const Object::Ptr& object); + static Value ServicesWithInfoAccessor(const Object::Ptr& object); }; } diff --git a/components/livestatus/table.h b/components/livestatus/table.h index 109189a5a..78beb1a7a 100644 --- a/components/livestatus/table.h +++ b/components/livestatus/table.h @@ -22,6 +22,7 @@ #include "livestatus/column.h" #include "base/object.h" +#include "base/dictionary.h" #include namespace livestatus diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 2119a72d7..6d56ba8b6 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -20,6 +20,7 @@ #include "icinga/host.h" #include "icinga/service.h" #include "icinga/hostgroup.h" +#include "icinga/icingaapplication.h" #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" @@ -50,6 +51,7 @@ Host::Host(const Dictionary::Ptr& serializedUpdate) RegisterAttribute("display_name", Attribute_Config, &m_DisplayName); RegisterAttribute("hostgroups", Attribute_Config, &m_HostGroups); RegisterAttribute("macros", Attribute_Config, &m_Macros); + RegisterAttribute("custom", Attribute_Config, &m_Custom); RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies); RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies); RegisterAttribute("hostcheck", Attribute_Config, &m_HostCheck); @@ -103,6 +105,11 @@ Dictionary::Ptr Host::GetMacros(void) const return m_Macros; } +Dictionary::Ptr Host::GetCustom(void) const +{ + return m_Custom; +} + Array::Ptr Host::GetHostDependencies(void) const { return m_HostDependencies;; @@ -303,6 +310,10 @@ std::set Host::GetServices(void) const return services; } +int Host::GetTotalServices(void) const +{ + return GetServices().size(); +} void Host::InvalidateServicesCache(void) { { @@ -494,6 +505,28 @@ HostState Host::CalculateState(ServiceState state, bool reachable) } } +HostState Host::GetState(void) const +{ + ASSERT(!OwnsLock()); + + if (!IsReachable()) + return HostUnreachable; + + Service::Ptr hc = GetHostCheckService(); + + if (!hc) + return HostUp; + + switch (hc->GetState()) { + case StateOK: + case StateWarning: + return HostUp; + default: + return HostDown; + } + +} + HostState Host::GetLastState(void) const { ASSERT(!OwnsLock()); @@ -515,6 +548,48 @@ HostState Host::GetLastState(void) const } } +HostState Host::GetLastHardState(void) const +{ + ASSERT(!OwnsLock()); + + if (!IsReachable()) + return HostUnreachable; + + Service::Ptr hc = GetHostCheckService(); + + if (!hc) + return HostUp; + + switch (hc->GetLastHardState()) { + case StateOK: + case StateWarning: + return HostUp; + default: + return HostDown; + } +} + +double Host::GetLastStateChange(void) const +{ + Service::Ptr hc = GetHostCheckService(); + + if (!hc) + return IcingaApplication::GetInstance()->GetStartTime(); + + return hc->GetLastStateChange(); +} + + +double Host::GetLastHardStateChange(void) const +{ + Service::Ptr hc = GetHostCheckService(); + + if (!hc) + return IcingaApplication::GetInstance()->GetStartTime(); + + return hc->GetLastHardStateChange(); +} + StateType Host::GetLastStateType(void) const { Service::Ptr hc = GetHostCheckService(); @@ -525,6 +600,46 @@ StateType Host::GetLastStateType(void) const return hc->GetLastStateType(); } +StateType Host::GetStateType(void) const +{ + Service::Ptr hc = GetHostCheckService(); + + if (!hc) + return StateTypeHard; + + return hc->GetStateType(); +} + +double Host::GetLastCheck(void) const +{ + Service::Ptr hc = GetHostCheckService(); + + if (!hc) + return -1; + + return hc->GetLastCheck(); +} + +bool Host::IsFlapping(void) const +{ + Service::Ptr hc = GetHostCheckService(); + + if (!hc) + return false; + + return hc->IsFlapping(); +} + +int Host::GetDowntimeDepth() const +{ + Service::Ptr hc = GetHostCheckService(); + + if (!hc) + return 0; + + return hc->GetDowntimeDepth(); +} + String Host::StateToString(HostState state) { switch (state) { diff --git a/lib/icinga/host.h b/lib/icinga/host.h index 5ca9931bc..2ef1a46a8 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -22,6 +22,7 @@ #include "icinga/i2-icinga.h" #include "icinga/macroresolver.h" +//#include "base/i2-base.h" #include "base/array.h" #include "base/dynamicobject.h" #include "base/dictionary.h" @@ -88,6 +89,7 @@ public: Array::Ptr GetGroups(void) const; Dictionary::Ptr GetMacros(void) const; + Dictionary::Ptr GetCustom(void) const; Array::Ptr GetHostDependencies(void) const; Array::Ptr GetServiceDependencies(void) const; String GetHostCheck(void) const; @@ -101,19 +103,33 @@ public: shared_ptr GetServiceByShortName(const Value& name) const; std::set > GetServices(void) const; + int GetTotalServices(void) const; static void InvalidateServicesCache(void); static Value ValidateServiceDictionary(const String& location, const Dictionary::Ptr& attrs); static HostState CalculateState(ServiceState state, bool reachable); + HostState GetState(void) const; + StateType GetStateType(void) const; HostState GetLastState(void) const; + HostState GetLastHardState(void) const; StateType GetLastStateType(void) const; + double GetLastStateChange(void) const; + double GetLastHardStateChange(void) const; + + bool IsFlapping(void) const; static String StateToString(HostState state); virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + /* Virtual Checks */ + double GetLastCheck(void) const; + + /* Virtual Downtime */ + int GetDowntimeDepth(void) const; + protected: virtual void OnRegistrationCompleted(void); virtual void OnAttributeChanged(const String& name); @@ -122,6 +138,7 @@ private: Attribute m_DisplayName; Attribute m_HostGroups; Attribute m_Macros; + Attribute m_Custom; Attribute m_HostDependencies; Attribute m_ServiceDependencies; Attribute m_HostCheck; diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index a9701ffde..58600d332 100644 --- a/lib/icinga/service-check.cpp +++ b/lib/icinga/service-check.cpp @@ -178,6 +178,22 @@ ServiceState Service::GetLastState(void) const return static_cast(ivalue); } +void Service::SetLastHardState(ServiceState state) +{ + m_LastHardState = static_cast(state); + + Touch("last_hard_state"); +} + +ServiceState Service::GetLastHardState(void) const +{ + if (m_LastHardState.IsEmpty()) + return StateUnknown; + + int ivalue = static_cast(m_LastHardState); + return static_cast(ivalue); +} + void Service::SetStateType(StateType type) { m_StateType = static_cast(type); @@ -233,6 +249,65 @@ Dictionary::Ptr Service::GetLastCheckResult(void) const return m_LastResult; } +bool Service::HasBeenChecked(void) const +{ + return GetLastCheckResult(); +} + +double Service::GetLastCheck(void) const +{ + Dictionary::Ptr cr = GetLastCheckResult(); + double schedule_end = -1; + + if (cr) { + schedule_end = cr->Get("schedule_end"); + } + + return schedule_end; +} + +String Service::GetLastCheckOutput(void) const +{ + Dictionary::Ptr cr = GetLastCheckResult(); + String output; + + if (cr) { + String raw_output = cr->Get("output"); + size_t line_end = raw_output.Find("\n"); + output = raw_output.SubStr(0, line_end); + } + + return output; +} + +String Service::GetLastCheckLongOutput(void) const +{ + Dictionary::Ptr cr = GetLastCheckResult(); + String long_output; + + if (cr) { + String raw_output = cr->Get("output"); + size_t line_end = raw_output.Find("\n"); + + if (line_end > 0 && line_end != String::NPos) { + long_output = raw_output.SubStr(line_end + 1, raw_output.GetLength()); + boost::algorithm::replace_all(long_output, "\n", "\\n"); + } + } + + return long_output; +} + +String Service::GetLastCheckPerfData(void) const +{ + Dictionary::Ptr cr = GetLastCheckResult(); + String perfdata = cr->Get("performance_data_raw"); + + boost::algorithm::replace_all(perfdata, "\n", "\\n"); + + return perfdata; +} + void Service::SetLastStateChange(double ts) { m_LastStateChange = ts; @@ -413,8 +488,10 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr) if (IsVolatile()) hardChange = true; - if (hardChange) + if (hardChange) { + SetLastHardState(GetState()); SetLastHardStateChange(now); + } if (GetState() != StateOK) TriggerDowntimes(); diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index 1552d0243..c40ef94ce 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -425,3 +425,22 @@ bool Service::IsInDowntime(void) const return false; } + +int Service::GetDowntimeDepth(void) const +{ + int downtime_depth = 0; + Dictionary::Ptr downtimes = GetDowntimes(); + + if (!downtimes) + return 0; + + ObjectLock olock(downtimes); + + Dictionary::Ptr downtime; + BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) { + if (Service::IsDowntimeActive(downtime)) + downtime_depth++; + } + + return downtime_depth; +} diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 3abc6655e..fb5577e37 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -44,6 +44,7 @@ Service::Service(const Dictionary::Ptr& serializedObject) RegisterAttribute("display_name", Attribute_Config, &m_DisplayName); RegisterAttribute("macros", Attribute_Config, &m_Macros); + RegisterAttribute("custom", Attribute_Config, &m_Custom); RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies); RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies); RegisterAttribute("servicegroups", Attribute_Config, &m_ServiceGroups); @@ -165,6 +166,11 @@ Dictionary::Ptr Service::GetMacros(void) const return m_Macros; } +Dictionary::Ptr Service::GetCustom(void) const +{ + return m_Custom; +} + Array::Ptr Service::GetHostDependencies(void) const { return m_HostDependencies; diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 7ee41897f..420303780 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -113,6 +113,7 @@ public: String GetDisplayName(void) const; Host::Ptr GetHost(void) const; Dictionary::Ptr GetMacros(void) const; + Dictionary::Ptr GetCustom(void) const; Array::Ptr GetHostDependencies(void) const; Array::Ptr GetServiceDependencies(void) const; Array::Ptr GetGroups(void) const; @@ -161,11 +162,21 @@ public: void SetLastState(ServiceState state); ServiceState GetLastState(void) const; + void SetLastHardState(ServiceState state); + ServiceState GetLastHardState(void) const; + void SetLastStateType(StateType type); StateType GetLastStateType(void) const; void SetLastCheckResult(const Dictionary::Ptr& result); Dictionary::Ptr GetLastCheckResult(void) const; + bool HasBeenChecked(void) const; + + double GetLastCheck(void) const; + + String GetLastCheckOutput(void) const; + String GetLastCheckLongOutput(void) const; + String GetLastCheckPerfData(void) const; void SetLastStateChange(double ts); double GetLastStateChange(void) const; @@ -217,6 +228,7 @@ public: static int GetNextDowntimeID(void); Dictionary::Ptr GetDowntimes(void) const; + int GetDowntimeDepth(void) const; String AddDowntime(const String& author, const String& comment, double startTime, double endTime, bool fixed, @@ -298,6 +310,7 @@ private: Attribute m_DisplayName; Attribute m_Macros; + Attribute m_Custom; Attribute m_HostDependencies; Attribute m_ServiceDependencies; Attribute m_ServiceGroups; @@ -320,6 +333,7 @@ private: Attribute m_State; Attribute m_StateType; Attribute m_LastState; + Attribute m_LastHardState; Attribute m_LastStateType; Attribute m_LastReachable; Attribute m_LastResult;