diff --git a/lib/compat/compatlogger.cpp b/lib/compat/compatlogger.cpp index 498b434f3..253a557e2 100644 --- a/lib/compat/compatlogger.cpp +++ b/lib/compat/compatlogger.cpp @@ -142,7 +142,7 @@ void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const Che msgbuf << "HOST ALERT: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << attempt_after << ";" << output << "" @@ -258,7 +258,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification if (service) notification_type_str = Service::StateToString(service->GetState()); else - notification_type_str = CompatUtility::GetHostStateString(host); + notification_type_str = GetHostStateString(host); } String author_comment = ""; @@ -290,7 +290,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification << user->GetName() << ";" << host->GetName() << ";" << notification_type_str << " " - << "(" << CompatUtility::GetHostStateString(host) << ");" + << "(" << GetHostStateString(host) << ");" << command_name << ";" << output << ";" << author_comment @@ -422,7 +422,7 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable) } else { msgbuf << "HOST EVENT HANDLER: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << current_attempt << ";" << event_command_name; @@ -435,6 +435,14 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable) } } +String CompatLogger::GetHostStateString(const Host::Ptr& host) +{ + if (host->GetState() != HostUp && !host->IsReachable()) + return "UNREACHABLE"; /* hardcoded compat state */ + + return Host::StateToString(host->GetState()); +} + void CompatLogger::WriteLine(const String& line) { ASSERT(OwnsLock()); @@ -499,7 +507,7 @@ void CompatLogger::ReopenFile(bool rotate) std::ostringstream msgbuf; msgbuf << "CURRENT HOST STATE: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << host->GetCheckAttempt() << ";" << output << ""; diff --git a/lib/compat/compatlogger.hpp b/lib/compat/compatlogger.hpp index f12ae2e4a..1665b19ab 100644 --- a/lib/compat/compatlogger.hpp +++ b/lib/compat/compatlogger.hpp @@ -62,6 +62,8 @@ private: void ExternalCommandHandler(const String& command, const std::vector<String>& arguments); void EventCommandHandler(const Checkable::Ptr& service); + static String GetHostStateString(const Host::Ptr& host); + Timer::Ptr m_RotationTimer; void RotationTimerHandler(); void ScheduleNextRotation(); diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index d1f39811d..f81a8d5ef 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -28,6 +28,7 @@ #include "icinga/timeperiod.hpp" #include "icinga/notificationcommand.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "icinga/dependency.hpp" #include "base/configtype.hpp" #include "base/objectlock.hpp" @@ -263,15 +264,15 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) ObjectLock olock(host); - fp << "\t" "check_interval" "\t" << CompatUtility::GetCheckableCheckInterval(host) << "\n" - "\t" "retry_interval" "\t" << CompatUtility::GetCheckableRetryInterval(host) << "\n" + fp << "\t" "check_interval" "\t" << (host->GetCheckInterval() / 60.0) << "\n" + "\t" "retry_interval" "\t" << (host->GetRetryInterval() / 60.0) << "\n" "\t" "max_check_attempts" "\t" << host->GetMaxCheckAttempts() << "\n" - "\t" "active_checks_enabled" "\t" << CompatUtility::GetCheckableActiveChecksEnabled(host) << "\n" - "\t" "passive_checks_enabled" "\t" << CompatUtility::GetCheckablePassiveChecksEnabled(host) << "\n" - "\t" "notifications_enabled" "\t" << CompatUtility::GetCheckableNotificationsEnabled(host) << "\n" - "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(host) << "\n" + "\t" "active_checks_enabled" "\t" << Convert::ToLong(host->GetEnableActiveChecks()) << "\n" + "\t" "passive_checks_enabled" "\t" << Convert::ToLong(host->GetEnablePassiveChecks()) << "\n" + "\t" "notifications_enabled" "\t" << Convert::ToLong(host->GetEnableNotifications()) << "\n" + "\t" "notification_options" "\t" << GetNotificationOptions(host) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(host) << "\n" - "\t" "event_handler_enabled" "\t" << CompatUtility::GetCheckableEventHandlerEnabled(host) << "\n"; + "\t" "event_handler_enabled" "\t" << Convert::ToLong(host->GetEnableEventHandler()) << "\n"; CheckCommand::Ptr checkcommand = host->GetCheckCommand(); if (checkcommand) @@ -281,7 +282,9 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) if (eventcommand && host->GetEnableEventHandler()) fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n"; - fp << "\t" "check_period" "\t" << CompatUtility::GetCheckableCheckPeriod(host) << "\n"; + TimePeriod::Ptr checkPeriod = host->GetCheckPeriod(); + if (checkPeriod) + fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; fp << "\t" "contacts" "\t"; DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(host)); @@ -294,7 +297,7 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) fp << "\t" << "initial_state" "\t" "o" "\n" "\t" "low_flap_threshold" "\t" << host->GetFlappingThresholdLow() << "\n" "\t" "high_flap_threshold" "\t" << host->GetFlappingThresholdHigh() << "\n" - "\t" "process_perf_data" "\t" << CompatUtility::GetCheckableProcessPerformanceData(host) << "\n" + "\t" "process_perf_data" "\t" << Convert::ToLong(host->GetEnablePerfdata()) << "\n" "\t" "check_freshness" "\t" "1" "\n"; fp << "\t" "host_groups" "\t"; @@ -335,12 +338,15 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl fp << "\t" << "check_command=" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(checkable) << "\n" "\t" "event_handler=" << CompatUtility::GetCommandName(eventcommand) << "\n" - "\t" "check_period=" << CompatUtility::GetCheckableCheckPeriod(checkable) << "\n" - "\t" "check_interval=" << CompatUtility::GetCheckableCheckInterval(checkable) << "\n" - "\t" "retry_interval=" << CompatUtility::GetCheckableRetryInterval(checkable) << "\n" - "\t" "has_been_checked=" << CompatUtility::GetCheckableHasBeenChecked(checkable) << "\n" + "\t" "check_interval=" << (checkable->GetCheckInterval() / 60.0) << "\n" + "\t" "retry_interval=" << (checkable->GetRetryInterval() / 60.0) << "\n" + "\t" "has_been_checked=" << Convert::ToLong(checkable->HasBeenChecked()) << "\n" "\t" "should_be_scheduled=" << checkable->GetEnableActiveChecks() << "\n" - "\t" "event_handler_enabled=" << CompatUtility::GetCheckableEventHandlerEnabled(checkable) << "\n"; + "\t" "event_handler_enabled=" << Convert::ToLong(checkable->GetEnableEventHandler()) << "\n"; + + TimePeriod::Ptr checkPeriod = checkable->GetCheckPeriod(); + if (checkPeriod) + fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; if (cr) { fp << "\t" << "check_execution_time=" << Convert::ToString(cr->CalculateExecutionTime()) << "\n" @@ -359,20 +365,24 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "last_time_critical=" << static_cast<int>(service->GetLastStateCritical()) << "\n" "\t" "last_time_unknown=" << static_cast<int>(service->GetLastStateUnknown()) << "\n"; } else { - fp << "\t" "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n" + int currentState = host->GetState(); + + if (currentState != HostUp && !host->IsReachable()) + currentState = 2; /* hardcoded compat state */ + + fp << "\t" "current_state=" << currentState << "\n" "\t" "last_hard_state=" << host->GetLastHardState() << "\n" "\t" "last_time_up=" << static_cast<int>(host->GetLastStateUp()) << "\n" "\t" "last_time_down=" << static_cast<int>(host->GetLastStateDown()) << "\n"; } fp << "\t" "state_type=" << checkable->GetStateType() << "\n" - "\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n" - "\t" "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n" - "\t" "performance_data=" << CompatUtility::GetCheckResultPerfdata(cr) << "\n"; + "\t" "last_check=" << static_cast<long>(host->GetLastCheck()) << "\n"; if (cr) { - fp << "\t" << "check_source=" << cr->GetCheckSource() << "\n" - "\t" "last_check=" << static_cast<long>(cr->GetScheduleEnd()) << "\n"; + fp << "\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n" + "\t" "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n" + "\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n"; } fp << "\t" << "next_check=" << static_cast<long>(checkable->GetNextCheck()) << "\n" @@ -380,21 +390,21 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n" "\t" "last_state_change=" << static_cast<long>(checkable->GetLastStateChange()) << "\n" "\t" "last_hard_state_change=" << static_cast<long>(checkable->GetLastHardStateChange()) << "\n" - "\t" "last_update=" << static_cast<long>(time(nullptr)) << "\n" - "\t" "notifications_enabled=" << CompatUtility::GetCheckableNotificationsEnabled(checkable) << "\n" - "\t" "active_checks_enabled=" << CompatUtility::GetCheckableActiveChecksEnabled(checkable) << "\n" - "\t" "passive_checks_enabled=" << CompatUtility::GetCheckablePassiveChecksEnabled(checkable) << "\n" - "\t" "flap_detection_enabled=" << CompatUtility::GetCheckableFlapDetectionEnabled(checkable) << "\n" - "\t" "is_flapping=" << CompatUtility::GetCheckableIsFlapping(checkable) << "\n" - "\t" "percent_state_change=" << CompatUtility::GetCheckablePercentStateChange(checkable) << "\n" - "\t" "problem_has_been_acknowledged=" << CompatUtility::GetCheckableProblemHasBeenAcknowledged(checkable) << "\n" - "\t" "acknowledgement_type=" << CompatUtility::GetCheckableAcknowledgementType(checkable) << "\n" + "\t" "last_update=" << static_cast<long>(Utility::GetTime()) << "\n" + "\t" "notifications_enabled" "\t" << Convert::ToLong(checkable->GetEnableNotifications()) << "\n" + "\t" "active_checks_enabled=" << Convert::ToLong(checkable->GetEnableActiveChecks()) << "\n" + "\t" "passive_checks_enabled=" << Convert::ToLong(checkable->GetEnablePassiveChecks()) << "\n" + "\t" "flap_detection_enabled=" << Convert::ToLong(checkable->GetEnableFlapping()) << "\n" + "\t" "is_flapping=" << Convert::ToLong(checkable->IsFlapping()) << "\n" + "\t" "percent_state_change=" << checkable->GetFlappingCurrent() << "\n" + "\t" "problem_has_been_acknowledged=" << (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n" + "\t" "acknowledgement_type=" << checkable->GetAcknowledgement() << "\n" "\t" "acknowledgement_end_time=" << checkable->GetAcknowledgementExpiry() << "\n" "\t" "scheduled_downtime_depth=" << checkable->GetDowntimeDepth() << "\n" "\t" "last_notification=" << CompatUtility::GetCheckableNotificationLastNotification(checkable) << "\n" "\t" "next_notification=" << CompatUtility::GetCheckableNotificationNextNotification(checkable) << "\n" "\t" "current_notification_number=" << CompatUtility::GetCheckableNotificationNotificationNumber(checkable) << "\n" - "\t" "is_reachable=" << CompatUtility::GetCheckableIsReachable(checkable) << "\n"; + "\t" "is_reachable=" << Convert::ToLong(checkable->IsReachable()) << "\n"; } void StatusDataWriter::DumpServiceStatus(std::ostream& fp, const Service::Ptr& service) @@ -427,19 +437,18 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s "\t" "host_name" "\t" << host->GetName() << "\n" "\t" "service_description" "\t" << service->GetShortName() << "\n" "\t" "display_name" "\t" << service->GetDisplayName() << "\n" - "\t" "check_period" "\t" << CompatUtility::GetCheckableCheckPeriod(service) << "\n" - "\t" "check_interval" "\t" << CompatUtility::GetCheckableCheckInterval(service) << "\n" - "\t" "retry_interval" "\t" << CompatUtility::GetCheckableRetryInterval(service) << "\n" + "\t" "check_interval" "\t" << (service->GetCheckInterval() / 60.0) << "\n" + "\t" "retry_interval" "\t" << (service->GetRetryInterval() / 60.0) << "\n" "\t" "max_check_attempts" "\t" << service->GetMaxCheckAttempts() << "\n" - "\t" "active_checks_enabled" "\t" << CompatUtility::GetCheckableActiveChecksEnabled(service) << "\n" - "\t" "passive_checks_enabled" "\t" << CompatUtility::GetCheckablePassiveChecksEnabled(service) << "\n" - "\t" "flap_detection_enabled" "\t" << CompatUtility::GetCheckableFlapDetectionEnabled(service) << "\n" - "\t" "is_volatile" "\t" << CompatUtility::GetCheckableIsVolatile(service) << "\n" - "\t" "notifications_enabled" "\t" << CompatUtility::GetCheckableNotificationsEnabled(service) << "\n" - "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n" + "\t" "active_checks_enabled" "\t" << Convert::ToLong(service->GetEnableActiveChecks()) << "\n" + "\t" "passive_checks_enabled" "\t" << Convert::ToLong(service->GetEnablePassiveChecks()) << "\n" + "\t" "flap_detection_enabled" "\t" << Convert::ToLong(service->GetEnableFlapping()) << "\n" + "\t" "is_volatile" "\t" << Convert::ToLong(service->GetVolatile()) << "\n" + "\t" "notifications_enabled" "\t" << Convert::ToLong(service->GetEnableNotifications()) << "\n" + "\t" "notification_options" "\t" << GetNotificationOptions(service) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n" "\t" "notification_period" "\t" << "" << "\n" - "\t" "event_handler_enabled" "\t" << CompatUtility::GetCheckableEventHandlerEnabled(service) << "\n"; + "\t" "event_handler_enabled" "\t" << Convert::ToLong(service->GetEnableEventHandler()) << "\n"; CheckCommand::Ptr checkcommand = service->GetCheckCommand(); if (checkcommand) @@ -449,6 +458,10 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s if (eventcommand && service->GetEnableEventHandler()) fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n"; + TimePeriod::Ptr checkPeriod = service->GetCheckPeriod(); + if (checkPeriod) + fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; + fp << "\t" "contacts" "\t"; DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(service)); fp << "\n"; @@ -466,8 +479,9 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s fp << "\t" "initial_state" "\t" "o" "\n" "\t" "low_flap_threshold" "\t" << service->GetFlappingThresholdLow() << "\n" "\t" "high_flap_threshold" "\t" << service->GetFlappingThresholdHigh() << "\n" - "\t" "process_perf_data" "\t" << CompatUtility::GetCheckableProcessPerformanceData(service) << "\n" + "\t" "process_perf_data" "\t" << Convert::ToLong(service->GetEnablePerfdata()) << "\n" "\t" "check_freshness" << "\t" "1" "\n"; + if (!notes.IsEmpty()) fp << "\t" "notes" "\t" << notes << "\n"; if (!notes_url.IsEmpty()) @@ -740,23 +754,23 @@ void StatusDataWriter::UpdateObjectsCache() /* Icinga 1.x only allows host->host, service->service dependencies */ if (!child_service && !parent_service) { objectfp << "define hostdependency {" "\n" - "\t" "dependent_host_name" "\t" << child_host->GetName() << "\n" - "\t" "host_name" "\t" << parent_host->GetName() << "\n" - "\t" "execution_failure_criteria" "\t" << criteria << "\n" - "\t" "notification_failure_criteria" "\t" << criteria << "\n" - "\t" "}" "\n" - "\n"; + "\t" "dependent_host_name" "\t" << child_host->GetName() << "\n" + "\t" "host_name" "\t" << parent_host->GetName() << "\n" + "\t" "execution_failure_criteria" "\t" << criteria << "\n" + "\t" "notification_failure_criteria" "\t" << criteria << "\n" + "\t" "}" "\n" + "\n"; } else if (child_service && parent_service){ objectfp << "define servicedependency {" "\n" - "\t" "dependent_host_name" "\t" << child_service->GetHost()->GetName() << "\n" - "\t" "dependent_service_description" "\t" << child_service->GetShortName() << "\n" - "\t" "host_name" "\t" << parent_service->GetHost()->GetName() << "\n" - "\t" "service_description" "\t" << parent_service->GetShortName() << "\n" - "\t" "execution_failure_criteria" "\t" << criteria << "\n" - "\t" "notification_failure_criteria" "\t" << criteria << "\n" - "\t" "}" "\n" - "\n"; + "\t" "dependent_host_name" "\t" << child_service->GetHost()->GetName() << "\n" + "\t" "dependent_service_description" "\t" << child_service->GetShortName() << "\n" + "\t" "host_name" "\t" << parent_service->GetHost()->GetName() << "\n" + "\t" "service_description" "\t" << parent_service->GetShortName() << "\n" + "\t" "execution_failure_criteria" "\t" << criteria << "\n" + "\t" "notification_failure_criteria" "\t" << criteria << "\n" + "\t" "}" "\n" + "\n"; } } @@ -798,32 +812,32 @@ void StatusDataWriter::StatusTimerHandler() "\n"; statusfp << "info {" "\n" - "\t" "created=" << Utility::GetTime() << "\n" - "\t" "version=" << Application::GetAppVersion() << "\n" - "\t" "}" "\n" - "\n"; + "\t" "created=" << Utility::GetTime() << "\n" + "\t" "version=" << Application::GetAppVersion() << "\n" + "\t" "}" "\n" + "\n"; statusfp << "programstatus {" "\n" - "\t" "icinga_pid=" << Utility::GetPid() << "\n" - "\t" "daemon_mode=1" "\n" - "\t" "program_start=" << static_cast<long>(Application::GetStartTime()) << "\n" - "\t" "active_host_checks_enabled=" << (IcingaApplication::GetInstance()->GetEnableHostChecks() ? 1 : 0) << "\n" - "\t" "passive_host_checks_enabled=1" "\n" - "\t" "active_service_checks_enabled=" << (IcingaApplication::GetInstance()->GetEnableServiceChecks() ? 1 : 0) << "\n" - "\t" "passive_service_checks_enabled=1" "\n" - "\t" "check_service_freshness=1" "\n" - "\t" "check_host_freshness=1" "\n" - "\t" "enable_notifications=" << (IcingaApplication::GetInstance()->GetEnableNotifications() ? 1 : 0) << "\n" - "\t" "enable_event_handlers=" << (IcingaApplication::GetInstance()->GetEnableEventHandlers() ? 1 : 0) << "\n" - "\t" "enable_flap_detection=" << (IcingaApplication::GetInstance()->GetEnableFlapping() ? 1 : 0) << "\n" - "\t" "enable_failure_prediction=0" "\n" - "\t" "process_performance_data=" << (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0) << "\n" - "\t" "active_scheduled_host_check_stats=" << CIB::GetActiveHostChecksStatistics(60) << "," << CIB::GetActiveHostChecksStatistics(5 * 60) << "," << CIB::GetActiveHostChecksStatistics(15 * 60) << "\n" - "\t" "passive_host_check_stats=" << CIB::GetPassiveHostChecksStatistics(60) << "," << CIB::GetPassiveHostChecksStatistics(5 * 60) << "," << CIB::GetPassiveHostChecksStatistics(15 * 60) << "\n" - "\t" "active_scheduled_service_check_stats=" << CIB::GetActiveServiceChecksStatistics(60) << "," << CIB::GetActiveServiceChecksStatistics(5 * 60) << "," << CIB::GetActiveServiceChecksStatistics(15 * 60) << "\n" - "\t" "passive_service_check_stats=" << CIB::GetPassiveServiceChecksStatistics(60) << "," << CIB::GetPassiveServiceChecksStatistics(5 * 60) << "," << CIB::GetPassiveServiceChecksStatistics(15 * 60) << "\n" - "\t" "next_downtime_id=" << Downtime::GetNextDowntimeID() << "\n" - "\t" "next_comment_id=" << Comment::GetNextCommentID() << "\n"; + "\t" "icinga_pid=" << Utility::GetPid() << "\n" + "\t" "daemon_mode=1" "\n" + "\t" "program_start=" << static_cast<long>(Application::GetStartTime()) << "\n" + "\t" "active_host_checks_enabled=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableHostChecks()) << "\n" + "\t" "passive_host_checks_enabled=1" "\n" + "\t" "active_service_checks_enabled=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableServiceChecks()) << "\n" + "\t" "passive_service_checks_enabled=1" "\n" + "\t" "check_service_freshness=1" "\n" + "\t" "check_host_freshness=1" "\n" + "\t" "enable_notifications=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableNotifications()) << "\n" + "\t" "enable_event_handlers=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableEventHandlers()) << "\n" + "\t" "enable_flap_detection=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableFlapping()) << "\n" + "\t" "enable_failure_prediction=0" "\n" + "\t" "process_performance_data=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnablePerfdata()) << "\n" + "\t" "active_scheduled_host_check_stats=" << CIB::GetActiveHostChecksStatistics(60) << "," << CIB::GetActiveHostChecksStatistics(5 * 60) << "," << CIB::GetActiveHostChecksStatistics(15 * 60) << "\n" + "\t" "passive_host_check_stats=" << CIB::GetPassiveHostChecksStatistics(60) << "," << CIB::GetPassiveHostChecksStatistics(5 * 60) << "," << CIB::GetPassiveHostChecksStatistics(15 * 60) << "\n" + "\t" "active_scheduled_service_check_stats=" << CIB::GetActiveServiceChecksStatistics(60) << "," << CIB::GetActiveServiceChecksStatistics(5 * 60) << "," << CIB::GetActiveServiceChecksStatistics(15 * 60) << "\n" + "\t" "passive_service_check_stats=" << CIB::GetPassiveServiceChecksStatistics(60) << "," << CIB::GetPassiveServiceChecksStatistics(5 * 60) << "," << CIB::GetPassiveServiceChecksStatistics(15 * 60) << "\n" + "\t" "next_downtime_id=" << Downtime::GetNextDowntimeID() << "\n" + "\t" "next_comment_id=" << Comment::GetNextCommentID() << "\n"; statusfp << "\t" "}" "\n" "\n"; @@ -863,3 +877,53 @@ void StatusDataWriter::ObjectHandler() { m_ObjectsCacheOutdated = true; } + +String StatusDataWriter::GetNotificationOptions(const Checkable::Ptr& checkable) +{ + Host::Ptr host; + Service::Ptr service; + tie(host, service) = GetHostService(checkable); + + unsigned long notification_type_filter = 0; + unsigned long notification_state_filter = 0; + + for (const Notification::Ptr& notification : checkable->GetNotifications()) { + notification_type_filter |= notification->GetTypeFilter(); + notification_state_filter |= notification->GetStateFilter(); + } + + std::vector<String> notification_options; + + /* notification state filters */ + if (service) { + if (notification_state_filter & ServiceWarning) { + notification_options.push_back("w"); + } + if (notification_state_filter & ServiceUnknown) { + notification_options.push_back("u"); + } + if (notification_state_filter & ServiceCritical) { + notification_options.push_back("c"); + } + } else { + if (notification_state_filter & HostDown) { + notification_options.push_back("d"); + } + } + + /* notification type filters */ + if (notification_type_filter & NotificationRecovery) { + notification_options.push_back("r"); + } + if ((notification_type_filter & NotificationFlappingStart) || + (notification_type_filter & NotificationFlappingEnd)) { + notification_options.push_back("f"); + } + if ((notification_type_filter & NotificationDowntimeStart) || + (notification_type_filter & NotificationDowntimeEnd) || + (notification_type_filter & NotificationDowntimeRemoved)) { + notification_options.push_back("s"); + } + + return boost::algorithm::join(notification_options, ","); +} diff --git a/lib/compat/statusdatawriter.hpp b/lib/compat/statusdatawriter.hpp index c19377408..5dd68427f 100644 --- a/lib/compat/statusdatawriter.hpp +++ b/lib/compat/statusdatawriter.hpp @@ -97,6 +97,8 @@ private: void UpdateObjectsCache(); void StatusTimerHandler(); void ObjectHandler(); + + static String GetNotificationOptions(const Checkable::Ptr& checkable); }; } diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index ab2ba3e2b..1e5ec1bd2 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -32,6 +32,7 @@ #include "icinga/eventcommand.hpp" #include "icinga/externalcommandprocessor.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "icinga/icingaapplication.hpp" #include <boost/algorithm/string/join.hpp> @@ -95,10 +96,15 @@ void DbEvents::NextCheckUpdatedHandler(const Checkable::Ptr& checkable) tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -110,12 +116,6 @@ void DbEvents::NextCheckUpdatedHandler(const Checkable::Ptr& checkable) query1.Fields = fields1; - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - DbObject::OnQuery(query1); } @@ -126,10 +126,15 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable) tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -137,17 +142,10 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable) query1.Object = DbObject::GetOrCreateByObject(checkable); Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(checkable)); - fields1->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(checkable)); + fields1->Set("is_flapping", checkable->IsFlapping()); + fields1->Set("percent_state_change", checkable->GetFlappingCurrent()); query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -155,19 +153,23 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable) void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable) { - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> now_bag = CompatUtility::ConvertTimestamp(now); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(notification->GetNextNotification()); + std::pair<unsigned long, unsigned long> now_bag = ConvertTimestamp(Utility::GetTime()); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(notification->GetNextNotification()); Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -176,17 +178,10 @@ void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notificat Dictionary::Ptr fields1 = new Dictionary(); fields1->Set("last_notification", DbValue::FromTimestamp(now_bag.first)); - fields1->Set("next_notification", DbValue::FromTimestamp(time_bag.first)); + fields1->Set("next_notification", DbValue::FromTimestamp(timeBag.first)); fields1->Set("current_notification_number", notification->GetNotificationNumber()); query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -211,10 +206,15 @@ void DbEvents::ReachabilityChangedHandler(const Checkable::Ptr& checkable, const tie(host, service) = GetHostService(child); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -225,13 +225,6 @@ void DbEvents::ReachabilityChangedHandler(const Checkable::Ptr& checkable, const fields1->Set("is_reachable", is_reachable); query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -271,10 +264,15 @@ void DbEvents::EnableChangedHandlerInternal(const Checkable::Ptr& checkable, con tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -283,14 +281,8 @@ void DbEvents::EnableChangedHandlerInternal(const Checkable::Ptr& checkable, con Dictionary::Ptr fields1 = new Dictionary(); fields1->Set(fieldName, enabled); + query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -329,44 +321,44 @@ void DbEvents::AddCommentInternal(std::vector<DbQuery>& queries, const Comment:: { Checkable::Ptr checkable = comment->GetCheckable(); - unsigned long entry_time = static_cast<long>(comment->GetEntryTime()); - unsigned long entry_time_usec = (comment->GetEntryTime() - entry_time) * 1000 * 1000; + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(comment->GetEntryTime()); Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("entry_time", DbValue::FromTimestamp(entry_time)); - fields1->Set("entry_time_usec", entry_time_usec); + fields1->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("entry_time_usec", timeBag.second); fields1->Set("entry_type", comment->GetEntryType()); fields1->Set("object_id", checkable); - if (checkable->GetReflectionType() == Host::TypeInstance) { - fields1->Set("comment_type", 2); - /* requires idoutils 1.10 schema fix */ - fields1->Set("internal_comment_id", comment->GetLegacyId()); - } else if (checkable->GetReflectionType() == Service::TypeInstance) { - fields1->Set("comment_type", 1); - fields1->Set("internal_comment_id", comment->GetLegacyId()); - } else { + int commentType = 0; + + if (checkable->GetReflectionType() == Host::TypeInstance) + commentType = 2; + else if (checkable->GetReflectionType() == Service::TypeInstance) + commentType = 1; + else { Log(LogDebug, "DbEvents", "unknown object type for adding comment."); return; } + fields1->Set("comment_type", commentType); + fields1->Set("internal_comment_id", comment->GetLegacyId()); fields1->Set("name", comment->GetName()); - fields1->Set("comment_time", DbValue::FromTimestamp(entry_time)); /* same as entry_time */ + fields1->Set("comment_time", DbValue::FromTimestamp(timeBag.first)); /* same as entry_time */ fields1->Set("author_name", comment->GetAuthor()); fields1->Set("comment_data", comment->GetText()); - fields1->Set("is_persistent", comment->GetPersistent() ? 1 : 0); + fields1->Set("is_persistent", comment->GetPersistent()); fields1->Set("comment_source", 1); /* external */ - fields1->Set("expires", (comment->GetExpireTime() > 0) ? 1 : 0); + fields1->Set("expires", (comment->GetExpireTime() > 0)); fields1->Set("expiration_time", DbValue::FromTimestamp(comment->GetExpireTime())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); DbQuery query1; + if (!historical) { query1.Table = "comments"; query1.Type = DbQueryInsert | DbQueryUpdate; @@ -376,11 +368,12 @@ void DbEvents::AddCommentInternal(std::vector<DbQuery>& queries, const Comment:: query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("object_id", checkable); query1.WhereCriteria->Set("name", comment->GetName()); - query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); + query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); } else { query1.Table = "commenthistory"; query1.Type = DbQueryInsert; } + query1.Category = DbCatComment; query1.Fields = fields1; queries.emplace_back(std::move(query1)); @@ -397,22 +390,22 @@ void DbEvents::RemoveCommentInternal(std::vector<DbQuery>& queries, const Commen { Checkable::Ptr checkable = comment->GetCheckable(); - unsigned long entry_time = static_cast<long>(comment->GetEntryTime()); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(comment->GetEntryTime()); /* Status */ DbQuery query1; query1.Table = "comments"; query1.Type = DbQueryDelete; query1.Category = DbCatComment; + query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("object_id", checkable); - query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); + query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); query1.WhereCriteria->Set("name", comment->GetName()); queries.emplace_back(std::move(query1)); /* History - update deletion time for service/host */ - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); + std::pair<unsigned long, unsigned long> timeBagNow = ConvertTimestamp(Utility::GetTime()); DbQuery query2; query2.Table = "commenthistory"; @@ -420,14 +413,15 @@ void DbEvents::RemoveCommentInternal(std::vector<DbQuery>& queries, const Commen query2.Category = DbCatComment; Dictionary::Ptr fields2 = new Dictionary(); - fields2->Set("deletion_time", DbValue::FromTimestamp(time_bag.first)); - fields2->Set("deletion_time_usec", time_bag.second); + fields2->Set("deletion_time", DbValue::FromTimestamp(timeBagNow.first)); + fields2->Set("deletion_time_usec", timeBagNow.second); query2.Fields = fields2; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set("object_id", checkable); - query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); + query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); query2.WhereCriteria->Set("name", comment->GetName()); + queries.emplace_back(std::move(query2)); } @@ -467,22 +461,23 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime fields1->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime())); fields1->Set("object_id", checkable); - if (checkable->GetReflectionType() == Host::TypeInstance) { - fields1->Set("downtime_type", 2); - /* requires idoutils 1.10 schema fix */ - fields1->Set("internal_downtime_id", downtime->GetLegacyId()); - } else if (checkable->GetReflectionType() == Service::TypeInstance) { - fields1->Set("downtime_type", 1); - fields1->Set("internal_downtime_id", downtime->GetLegacyId()); - } else { + int downtimeType = 0; + + if (checkable->GetReflectionType() == Host::TypeInstance) + downtimeType = 2; + else if (checkable->GetReflectionType() == Service::TypeInstance) + downtimeType = 1; + else { Log(LogDebug, "DbEvents", "unknown object type for adding downtime."); return; } + fields1->Set("downtime_type", downtimeType); + fields1->Set("internal_downtime_id", downtime->GetLegacyId()); fields1->Set("author_name", downtime->GetAuthor()); fields1->Set("comment_data", downtime->GetComment()); fields1->Set("triggered_by_id", Downtime::GetByName(downtime->GetTriggeredBy())); - fields1->Set("is_fixed", downtime->GetFixed() ? 1 : 0); + fields1->Set("is_fixed", downtime->GetFixed()); fields1->Set("duration", downtime->GetDuration()); fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); @@ -490,19 +485,19 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime /* flexible downtimes are started at trigger time */ if (downtime->GetFixed()) { - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(downtime->GetStartTime()); - fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("actual_start_time_usec", time_bag.second); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(downtime->GetStartTime()); + + fields1->Set("actual_start_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("actual_start_time_usec", timeBag.second); fields1->Set("was_started", ((downtime->GetStartTime() <= Utility::GetTime()) ? 1 : 0)); } - fields1->Set("is_in_effect", (downtime->IsInEffect() ? 1 : 0)); + fields1->Set("is_in_effect", downtime->IsInEffect()); fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -534,10 +529,15 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime tie(host, service) = GetHostService(checkable); DbQuery query2; - if (service) + query2.WhereCriteria = new Dictionary(); + + if (service) { query2.Table = "servicestatus"; - else + query2.WhereCriteria->Set("service_object_id", service); + } else { query2.Table = "hoststatus"; + query2.WhereCriteria->Set("host_object_id", host); + } query2.Type = DbQueryUpdate; query2.Category = DbCatState; @@ -548,14 +548,8 @@ void DbEvents::AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime fields2->Set("scheduled_downtime_depth", checkable->GetDowntimeDepth()); query2.Fields = fields2; - - query2.WhereCriteria = new Dictionary(); - if (service) - query2.WhereCriteria->Set("service_object_id", service); - else - query2.WhereCriteria->Set("host_object_id", host); - query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ + queries.emplace_back(std::move(query2)); } } @@ -587,8 +581,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt queries.emplace_back(std::move(query1)); /* History - update actual_end_time, was_cancelled for service (and host in case) */ - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query3; query3.Table = "downtimehistory"; @@ -599,8 +592,8 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt fields3->Set("was_cancelled", downtime->GetWasCancelled() ? 1 : 0); if (downtime->GetFixed() || (!downtime->GetFixed() && downtime->GetTriggerTime() > 0)) { - fields3->Set("actual_end_time", DbValue::FromTimestamp(time_bag.first)); - fields3->Set("actual_end_time_usec", time_bag.second); + fields3->Set("actual_end_time", DbValue::FromTimestamp(timeBag.first)); + fields3->Set("actual_end_time_usec", timeBag.second); } fields3->Set("is_in_effect", 0); @@ -621,10 +614,15 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt tie(host, service) = GetHostService(checkable); DbQuery query4; - if (service) + query4.WhereCriteria = new Dictionary(); + + if (service) { query4.Table = "servicestatus"; - else + query4.WhereCriteria->Set("service_object_id", service); + } else { query4.Table = "hoststatus"; + query4.WhereCriteria->Set("host_object_id", host); + } query4.Type = DbQueryUpdate; query4.Category = DbCatState; @@ -635,14 +633,8 @@ void DbEvents::RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downt fields4->Set("scheduled_downtime_depth", checkable->GetDowntimeDepth()); query4.Fields = fields4; - - query4.WhereCriteria = new Dictionary(); - if (service) - query4.WhereCriteria->Set("service_object_id", service); - else - query4.WhereCriteria->Set("host_object_id", host); - query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ + queries.emplace_back(std::move(query4)); } @@ -650,8 +642,7 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) { Checkable::Ptr checkable = downtime->GetCheckable(); - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(Utility::GetTime()); /* Status */ DbQuery query1; @@ -661,8 +652,8 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) Dictionary::Ptr fields1 = new Dictionary(); fields1->Set("was_started", 1); - fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("actual_start_time_usec", time_bag.second); + fields1->Set("actual_start_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("actual_start_time_usec", timeBag.second); fields1->Set("is_in_effect", (downtime->IsInEffect() ? 1 : 0)); fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -687,8 +678,8 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) Dictionary::Ptr fields3 = new Dictionary(); fields3->Set("was_started", 1); fields3->Set("is_in_effect", 1); - fields3->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first)); - fields3->Set("actual_start_time_usec", time_bag.second); + fields3->Set("actual_start_time", DbValue::FromTimestamp(timeBag.first)); + fields3->Set("actual_start_time_usec", timeBag.second); fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); query3.Fields = fields3; @@ -702,10 +693,15 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) tie(host, service) = GetHostService(checkable); DbQuery query4; - if (service) + query4.WhereCriteria = new Dictionary(); + + if (service) { query4.Table = "servicestatus"; - else + query4.WhereCriteria->Set("service_object_id", service); + } else { query4.Table = "hoststatus"; + query4.WhereCriteria->Set("host_object_id", host); + } query4.Type = DbQueryUpdate; query4.Category = DbCatState; @@ -716,13 +712,6 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) fields4->Set("scheduled_downtime_depth", checkable->GetDowntimeDepth()); query4.Fields = fields4; - - query4.WhereCriteria = new Dictionary(); - if (service) - query4.WhereCriteria->Set("service_object_id", service); - else - query4.WhereCriteria->Set("host_object_id", host); - query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query4); @@ -735,10 +724,7 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const Log(LogDebug, "DbEvents") << "add acknowledgement history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); - - unsigned long end_time = static_cast<long>(expiry); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "acknowledgements"; @@ -750,27 +736,26 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const tie(host, service) = GetHostService(checkable); Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("entry_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("entry_time_usec", time_bag.second); + + fields1->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("entry_time_usec", timeBag.second); fields1->Set("acknowledgement_type", type); fields1->Set("object_id", checkable); fields1->Set("author_name", author); fields1->Set("comment_data", comment); - fields1->Set("persistent_comment", 1); //always persistent - fields1->Set("notify_contacts", notify ? 1 : 0); - fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0); - fields1->Set("end_time", DbValue::FromTimestamp(end_time)); + fields1->Set("persistent_comment", 1); + fields1->Set("notify_contacts", notify); + fields1->Set("is_sticky", type == AcknowledgementSticky); + fields1->Set("end_time", DbValue::FromTimestamp(expiry)); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - if (service) { + if (service) fields1->Set("state", service->GetState()); - } else { - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); - } + else + fields1->Set("state", GetHostState(host)); - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -801,10 +786,15 @@ void DbEvents::AddAcknowledgementInternal(const Checkable::Ptr& checkable, Ackno tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -814,14 +804,8 @@ void DbEvents::AddAcknowledgementInternal(const Checkable::Ptr& checkable, Ackno Dictionary::Ptr fields1 = new Dictionary(); fields1->Set("acknowledgement_type", type); fields1->Set("problem_has_been_acknowledged", add ? 1 : 0); + query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -835,8 +819,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con << "add notification history for '" << checkable->GetName() << "'"; /* start and end happen at the same time */ - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "notifications"; @@ -850,18 +833,17 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con Dictionary::Ptr fields1 = new Dictionary(); fields1->Set("notification_type", 1); /* service */ - fields1->Set("notification_reason", CompatUtility::MapNotificationReasonType(type)); + fields1->Set("notification_reason", MapNotificationReasonType(type)); fields1->Set("object_id", checkable); - fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("start_time_usec", time_bag.second); - fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("end_time_usec", time_bag.second); + fields1->Set("start_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("start_time_usec", timeBag.second); + fields1->Set("end_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("end_time_usec", timeBag.second); - if (service) { + if (service) fields1->Set("state", service->GetState()); - } else { - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); - } + else + fields1->Set("state", GetHostState(host)); if (cr) { fields1->Set("output", CompatUtility::GetCheckResultOutput(cr)); @@ -872,9 +854,8 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con fields1->Set("contacts_notified", static_cast<long>(users.size())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -894,10 +875,10 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con Dictionary::Ptr fields2 = new Dictionary(); fields2->Set("contact_object_id", user); - fields2->Set("start_time", DbValue::FromTimestamp(time_bag.first)); - fields2->Set("start_time_usec", time_bag.second); - fields2->Set("end_time", DbValue::FromTimestamp(time_bag.first)); - fields2->Set("end_time_usec", time_bag.second); + fields2->Set("start_time", DbValue::FromTimestamp(timeBag.first)); + fields2->Set("start_time_usec", timeBag.second); + fields2->Set("end_time", DbValue::FromTimestamp(timeBag.first)); + fields2->Set("end_time_usec", timeBag.second); fields2->Set("notification_id", query1.NotificationInsertID); fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -916,7 +897,7 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec << "add state change history for '" << checkable->GetName() << "'"; double ts = cr->GetExecutionEnd(); - std::pair<unsigned long, unsigned long> state_time_bag = CompatUtility::ConvertTimestamp(ts); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(ts); DbQuery query1; query1.Table = "statehistory"; @@ -928,8 +909,8 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec tie(host, service) = GetHostService(checkable); Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("state_time", DbValue::FromTimestamp(state_time_bag.first)); - fields1->Set("state_time_usec", state_time_bag.second); + fields1->Set("state_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("state_time_usec", timeBag.second); fields1->Set("object_id", checkable); fields1->Set("state_change", 1); /* service */ fields1->Set("state_type", checkable->GetStateType()); @@ -941,7 +922,7 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec fields1->Set("last_state", service->GetLastState()); fields1->Set("last_hard_state", service->GetLastHardState()); } else { - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); + fields1->Set("state", GetHostState(host)); fields1->Set("last_state", host->GetLastState()); fields1->Set("last_hard_state", host->GetLastHardState()); } @@ -954,9 +935,8 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -967,31 +947,22 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec /* logentries */ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr) { - Dictionary::Ptr vars_after = cr->GetVarsAfter(); + if (!cr) + return; - long state_after = vars_after->Get("state"); - long stateType_after = vars_after->Get("state_type"); - long attempt_after = vars_after->Get("attempt"); - bool reachable_after = vars_after->Get("reachable"); + Dictionary::Ptr varsBefore = cr->GetVarsBefore(); + Dictionary::Ptr varsAfter = cr->GetVarsAfter(); - Dictionary::Ptr vars_before = cr->GetVarsBefore(); - - if (vars_before) { - long state_before = vars_before->Get("state"); - long stateType_before = vars_before->Get("state_type"); - long attempt_before = vars_before->Get("attempt"); - bool reachable_before = vars_before->Get("reachable"); - - if (state_before == state_after && stateType_before == stateType_after && - attempt_before == attempt_after && reachable_before == reachable_after) + if (varsBefore && varsAfter) { + if (varsBefore->Get("state") == varsAfter->Get("state") && + varsBefore->Get("state_type") == varsAfter->Get("state_type") && + varsBefore->Get("attempt") == varsAfter->Get("attempt") && + varsBefore->Get("reachable") == varsAfter->Get("reachable")) return; /* Nothing changed, ignore this checkresult. */ } LogEntryType type; - String output; - - if (cr) - output = CompatUtility::GetCheckResultOutput(cr); + String output = CompatUtility::GetCheckResultOutput(cr); Host::Ptr host; Service::Ptr service; @@ -1005,7 +976,7 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C << service->GetShortName() << ";" << Service::StateToString(service->GetState()) << ";" << Service::StateTypeToString(service->GetStateType()) << ";" - << attempt_after << ";" + << service->GetCheckAttempt() << ";" << output << "" << ""; @@ -1024,15 +995,15 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C break; default: Log(LogCritical, "DbEvents") - << "Unknown service state: " << state_after; + << "Unknown service state: " << service->GetState(); return; } } else { msgbuf << "HOST ALERT: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" - << attempt_after << ";" + << host->GetCheckAttempt() << ";" << output << "" << ""; @@ -1045,11 +1016,11 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C break; default: Log(LogCritical, "DbEvents") - << "Unknown host state: " << state_after; + << "Unknown host state: " << host->GetState(); return; } - if (!reachable_after) + if (!host->IsReachable()) type = LogEntryTypeHostUnreachable; } @@ -1088,15 +1059,15 @@ void DbEvents::AddRemoveDowntimeLogHistory(const Downtime::Ptr& downtime) { Checkable::Ptr checkable = downtime->GetCheckable(); - String downtime_output; - String downtime_state_str; + String downtimeOutput; + String downtimeStateStr; if (downtime->GetWasCancelled()) { - downtime_output = "Scheduled downtime for service has been cancelled."; - downtime_state_str = "CANCELLED"; + downtimeOutput = "Scheduled downtime for service has been cancelled."; + downtimeStateStr = "CANCELLED"; } else { - downtime_output = "Service has exited from a period of scheduled downtime."; - downtime_state_str = "STOPPED"; + downtimeOutput = "Service has exited from a period of scheduled downtime."; + downtimeStateStr = "STOPPED"; } Host::Ptr host; @@ -1109,14 +1080,14 @@ void DbEvents::AddRemoveDowntimeLogHistory(const Downtime::Ptr& downtime) msgbuf << "SERVICE DOWNTIME ALERT: " << host->GetName() << ";" << service->GetShortName() << ";" - << downtime_state_str << "; " - << downtime_output + << downtimeStateStr << "; " + << downtimeOutput << ""; } else { msgbuf << "HOST DOWNTIME ALERT: " << host->GetName() << ";" - << downtime_state_str << "; " - << downtime_output + << downtimeStateStr << "; " + << downtimeOutput << ""; } @@ -1129,11 +1100,12 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati { CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); - String check_command = ""; - if (commandObj) - check_command = commandObj->GetName(); + String checkCommandName; - String notification_type_str = Notification::NotificationTypeToString(notification_type); + if (commandObj) + checkCommandName = commandObj->GetName(); + + String notificationTypeStr = Notification::NotificationTypeToString(notification_type); String author_comment = ""; if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) { @@ -1143,10 +1115,7 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati if (!cr) return; - String output; - - if (cr) - output = CompatUtility::GetCheckResultOutput(cr); + String output = CompatUtility::GetCheckResultOutput(cr); Host::Ptr host; Service::Ptr service; @@ -1159,18 +1128,18 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati << user->GetName() << ";" << host->GetName() << ";" << service->GetShortName() << ";" - << notification_type_str << " " + << notificationTypeStr << " " << "(" << Service::StateToString(service->GetState()) << ");" - << check_command << ";" + << checkCommandName << ";" << output << author_comment << ""; } else { msgbuf << "HOST NOTIFICATION: " << user->GetName() << ";" << host->GetName() << ";" - << notification_type_str << " " + << notificationTypeStr << " " << "(" << Host::StateToString(host->GetState()) << ");" - << check_command << ";" + << checkCommandName << ";" << output << author_comment << ""; } @@ -1180,15 +1149,15 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati void DbEvents::AddFlappingChangedLogHistory(const Checkable::Ptr& checkable) { - String flapping_state_str; - String flapping_output; + String flappingStateStr; + String flappingOutput; if (checkable->IsFlapping()) { - flapping_output = "Service appears to have started flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change >= " + Convert::ToString(checkable->GetFlappingThresholdHigh()) + "% threshold)"; - flapping_state_str = "STARTED"; + flappingOutput = "Service appears to have started flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change >= " + Convert::ToString(checkable->GetFlappingThresholdHigh()) + "% threshold)"; + flappingStateStr = "STARTED"; } else { - flapping_output = "Service appears to have stopped flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change < " + Convert::ToString(checkable->GetFlappingThresholdLow()) + "% threshold)"; - flapping_state_str = "STOPPED"; + flappingOutput = "Service appears to have stopped flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change < " + Convert::ToString(checkable->GetFlappingThresholdLow()) + "% threshold)"; + flappingStateStr = "STOPPED"; } Host::Ptr host; @@ -1201,14 +1170,14 @@ void DbEvents::AddFlappingChangedLogHistory(const Checkable::Ptr& checkable) msgbuf << "SERVICE FLAPPING ALERT: " << host->GetName() << ";" << service->GetShortName() << ";" - << flapping_state_str << "; " - << flapping_output + << flappingStateStr << "; " + << flappingOutput << ""; } else { msgbuf << "HOST FLAPPING ALERT: " << host->GetName() << ";" - << flapping_state_str << "; " - << flapping_output + << flappingStateStr << "; " + << flappingOutput << ""; } @@ -1220,8 +1189,8 @@ void DbEvents::AddEnableFlappingChangedLogHistory(const Checkable::Ptr& checkabl if (!checkable->GetEnableFlapping()) return; - String flapping_output = "Flap detection has been disabled"; - String flapping_state_str = "DISABLED"; + String flappingOutput = "Flap detection has been disabled"; + String flappingStateStr = "DISABLED"; Host::Ptr host; Service::Ptr service; @@ -1233,14 +1202,14 @@ void DbEvents::AddEnableFlappingChangedLogHistory(const Checkable::Ptr& checkabl msgbuf << "SERVICE FLAPPING ALERT: " << host->GetName() << ";" << service->GetShortName() << ";" - << flapping_state_str << "; " - << flapping_output + << flappingStateStr << "; " + << flappingOutput << ""; } else { msgbuf << "HOST FLAPPING ALERT: " << host->GetName() << ";" - << flapping_state_str << "; " - << flapping_output + << flappingStateStr << "; " + << flappingOutput << ""; } @@ -1252,8 +1221,7 @@ void DbEvents::AddLogHistory(const Checkable::Ptr& checkable, const String& buff Log(LogDebug, "DbEvents") << "add log entry history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "logentries"; @@ -1261,18 +1229,18 @@ void DbEvents::AddLogHistory(const Checkable::Ptr& checkable, const String& buff query1.Category = DbCatLog; Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("logentry_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("entry_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("entry_time_usec", time_bag.second); - fields1->Set("object_id", checkable); // added in 1.10 see #4754 + + fields1->Set("logentry_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("entry_time_usec", timeBag.second); + fields1->Set("object_id", checkable); fields1->Set("logentry_type", type); fields1->Set("logentry_data", buffer); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1286,8 +1254,7 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) Log(LogDebug, "DbEvents") << "add flapping history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "flappinghistory"; @@ -1296,8 +1263,8 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("event_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("event_time_usec", time_bag.second); + fields1->Set("event_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("event_time_usec", timeBag.second); if (checkable->IsFlapping()) fields1->Set("event_type", 1000); @@ -1318,9 +1285,8 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1330,11 +1296,13 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable) { + if (!checkable->GetEnableFlapping()) + return; + Log(LogDebug, "DbEvents") << "add flapping history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "flappinghistory"; @@ -1343,11 +1311,8 @@ void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable) Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("event_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("event_time_usec", time_bag.second); - - if (!checkable->GetEnableFlapping()) - return; + fields1->Set("event_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("event_time_usec", timeBag.second); fields1->Set("event_type", 1001); fields1->Set("reason_type", 2); @@ -1361,12 +1326,10 @@ void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable) fields1->Set("percent_state_change", checkable->GetFlappingCurrent()); fields1->Set("low_threshold", checkable->GetFlappingThresholdLow()); fields1->Set("high_threshold", checkable->GetFlappingThresholdHigh()); - fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1387,41 +1350,37 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C Service::Ptr service; tie(host, service) = GetHostService(checkable); - std::ostringstream msgbuf; - DbQuery query1; query1.Table = service ? "servicechecks" : "hostchecks"; query1.Type = DbQueryInsert; query1.Category = DbCatCheck; Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("check_type", CompatUtility::GetCheckableCheckType(checkable)); + fields1->Set("check_type", !checkable->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */ fields1->Set("current_check_attempt", checkable->GetCheckAttempt()); fields1->Set("max_check_attempts", checkable->GetMaxCheckAttempts()); fields1->Set("state_type", checkable->GetStateType()); double start = cr->GetExecutionStart(); - std::pair<unsigned long, unsigned long> time_bag_start = CompatUtility::ConvertTimestamp(start); - double end = cr->GetExecutionEnd(); - std::pair<unsigned long, unsigned long> time_bag_end = CompatUtility::ConvertTimestamp(end); + double executionTime = cr->CalculateExecutionTime(); - double execution_time = cr->CalculateExecutionTime(); + std::pair<unsigned long, unsigned long> timeBagStart = ConvertTimestamp(start); + std::pair<unsigned long, unsigned long> timeBagEnd = ConvertTimestamp(end); - fields1->Set("start_time", DbValue::FromTimestamp(time_bag_start.first)); - fields1->Set("start_time_usec", time_bag_start.second); - fields1->Set("end_time", DbValue::FromTimestamp(time_bag_end.first)); - fields1->Set("end_time_usec", time_bag_end.second); + fields1->Set("start_time", DbValue::FromTimestamp(timeBagStart.first)); + fields1->Set("start_time_usec", timeBagStart.second); + fields1->Set("end_time", DbValue::FromTimestamp(timeBagEnd.first)); + fields1->Set("end_time_usec", timeBagEnd.second); fields1->Set("command_object_id", checkable->GetCheckCommand()); - fields1->Set("command_args", Empty); - fields1->Set("command_line", CompatUtility::GetCommandLine(checkable->GetCheckCommand())); - fields1->Set("execution_time", Convert::ToString(execution_time)); - fields1->Set("latency", Convert::ToString(cr->CalculateLatency())); + fields1->Set("execution_time", executionTime); + fields1->Set("latency", cr->CalculateLatency()); fields1->Set("return_code", cr->GetExitStatus()); + fields1->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); + fields1->Set("output", CompatUtility::GetCheckResultOutput(cr)); fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); - fields1->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr)); - + fields1->Set("command_line", CompatUtility::GetCommandLine(checkable->GetCheckCommand())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ if (service) { @@ -1429,12 +1388,11 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C fields1->Set("state", service->GetState()); } else { fields1->Set("host_object_id", host); - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); + fields1->Set("state", GetHostState(host)); } - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1448,9 +1406,6 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable) Log(LogDebug, "DbEvents") << "add eventhandler history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now); - DbQuery query1; query1.Table = "eventhandlers"; query1.Type = DbQueryInsert; @@ -1463,28 +1418,27 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable) tie(host, service) = GetHostService(checkable); fields1->Set("object_id", checkable); + fields1->Set("state_type", checkable->GetStateType()); + fields1->Set("command_object_id", checkable->GetEventCommand()); + fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ if (service) { fields1->Set("state", service->GetState()); fields1->Set("eventhandler_type", 1); } else { - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); + fields1->Set("state", GetHostState(host)); fields1->Set("eventhandler_type", 0); } - fields1->Set("state_type", checkable->GetStateType()); + std::pair<unsigned long, unsigned long> timeBag = ConvertTimestamp(Utility::GetTime()); - fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("start_time_usec", time_bag.second); - fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("end_time_usec", time_bag.second); - fields1->Set("command_object_id", checkable->GetEventCommand()); + fields1->Set("start_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("start_time_usec", timeBag.second); + fields1->Set("end_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("end_time_usec", timeBag.second); - fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - String node = IcingaApplication::GetInstance()->GetNodeName(); - - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1504,19 +1458,425 @@ void DbEvents::AddExternalCommandHistory(double time, const String& command, con Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("entry_time", DbValue::FromTimestamp(static_cast<long>(time))); - fields1->Set("command_type", CompatUtility::MapExternalCommandType(command)); + fields1->Set("entry_time", DbValue::FromTimestamp(time)); + fields1->Set("command_type", MapExternalCommandType(command)); fields1->Set("command_name", command); fields1->Set("command_args", boost::algorithm::join(arguments, ";")); - fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); query1.Fields = fields1; DbObject::OnQuery(query1); } + +int DbEvents::GetHostState(const Host::Ptr& host) +{ + int currentState = host->GetState(); + + if (currentState != HostUp && !host->IsReachable()) + currentState = 2; /* hardcoded compat state */ + + return currentState; +} + +String DbEvents::GetHostStateString(const Host::Ptr& host) +{ + if (host->GetState() != HostUp && !host->IsReachable()) + return "UNREACHABLE"; /* hardcoded compat state */ + + return Host::StateToString(host->GetState()); +} + +std::pair<unsigned long, unsigned long> DbEvents::ConvertTimestamp(double time) +{ + unsigned long time_sec = static_cast<long>(time); + unsigned long time_usec = (time - time_sec) * 1000 * 1000; + + return std::make_pair(time_sec, time_usec); +} + +int DbEvents::MapNotificationReasonType(NotificationType type) +{ + switch (type) { + case NotificationDowntimeStart: + return 5; + case NotificationDowntimeEnd: + return 6; + case NotificationDowntimeRemoved: + return 7; + case NotificationCustom: + return 8; + case NotificationAcknowledgement: + return 1; + case NotificationProblem: + return 0; + case NotificationRecovery: + return 0; + case NotificationFlappingStart: + return 2; + case NotificationFlappingEnd: + return 3; + default: + return 0; + } +} + +int DbEvents::MapExternalCommandType(const String& name) +{ + if (name == "NONE") + return 0; + if (name == "ADD_HOST_COMMENT") + return 1; + if (name == "DEL_HOST_COMMENT") + return 2; + if (name == "ADD_SVC_COMMENT") + return 3; + if (name == "DEL_SVC_COMMENT") + return 4; + if (name == "ENABLE_SVC_CHECK") + return 5; + if (name == "DISABLE_SVC_CHECK") + return 6; + if (name == "SCHEDULE_SVC_CHECK") + return 7; + if (name == "DELAY_SVC_NOTIFICATION") + return 9; + if (name == "DELAY_HOST_NOTIFICATION") + return 10; + if (name == "DISABLE_NOTIFICATIONS") + return 11; + if (name == "ENABLE_NOTIFICATIONS") + return 12; + if (name == "RESTART_PROCESS") + return 13; + if (name == "SHUTDOWN_PROCESS") + return 14; + if (name == "ENABLE_HOST_SVC_CHECKS") + return 15; + if (name == "DISABLE_HOST_SVC_CHECKS") + return 16; + if (name == "SCHEDULE_HOST_SVC_CHECKS") + return 17; + if (name == "DELAY_HOST_SVC_NOTIFICATIONS") + return 19; + if (name == "DEL_ALL_HOST_COMMENTS") + return 20; + if (name == "DEL_ALL_SVC_COMMENTS") + return 21; + if (name == "ENABLE_SVC_NOTIFICATIONS") + return 22; + if (name == "DISABLE_SVC_NOTIFICATIONS") + return 23; + if (name == "ENABLE_HOST_NOTIFICATIONS") + return 24; + if (name == "DISABLE_HOST_NOTIFICATIONS") + return 25; + if (name == "ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST") + return 26; + if (name == "DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST") + return 27; + if (name == "ENABLE_HOST_SVC_NOTIFICATIONS") + return 28; + if (name == "DISABLE_HOST_SVC_NOTIFICATIONS") + return 29; + if (name == "PROCESS_SERVICE_CHECK_RESULT") + return 30; + if (name == "SAVE_STATE_INFORMATION") + return 31; + if (name == "READ_STATE_INFORMATION") + return 32; + if (name == "ACKNOWLEDGE_HOST_PROBLEM") + return 33; + if (name == "ACKNOWLEDGE_SVC_PROBLEM") + return 34; + if (name == "START_EXECUTING_SVC_CHECKS") + return 35; + if (name == "STOP_EXECUTING_SVC_CHECKS") + return 36; + if (name == "START_ACCEPTING_PASSIVE_SVC_CHECKS") + return 37; + if (name == "STOP_ACCEPTING_PASSIVE_SVC_CHECKS") + return 38; + if (name == "ENABLE_PASSIVE_SVC_CHECKS") + return 39; + if (name == "DISABLE_PASSIVE_SVC_CHECKS") + return 40; + if (name == "ENABLE_EVENT_HANDLERS") + return 41; + if (name == "DISABLE_EVENT_HANDLERS") + return 42; + if (name == "ENABLE_HOST_EVENT_HANDLER") + return 43; + if (name == "DISABLE_HOST_EVENT_HANDLER") + return 44; + if (name == "ENABLE_SVC_EVENT_HANDLER") + return 45; + if (name == "DISABLE_SVC_EVENT_HANDLER") + return 46; + if (name == "ENABLE_HOST_CHECK") + return 47; + if (name == "DISABLE_HOST_CHECK") + return 48; + if (name == "START_OBSESSING_OVER_SVC_CHECKS") + return 49; + if (name == "STOP_OBSESSING_OVER_SVC_CHECKS") + return 50; + if (name == "REMOVE_HOST_ACKNOWLEDGEMENT") + return 51; + if (name == "REMOVE_SVC_ACKNOWLEDGEMENT") + return 52; + if (name == "SCHEDULE_FORCED_HOST_SVC_CHECKS") + return 53; + if (name == "SCHEDULE_FORCED_SVC_CHECK") + return 54; + if (name == "SCHEDULE_HOST_DOWNTIME") + return 55; + if (name == "SCHEDULE_SVC_DOWNTIME") + return 56; + if (name == "ENABLE_HOST_FLAP_DETECTION") + return 57; + if (name == "DISABLE_HOST_FLAP_DETECTION") + return 58; + if (name == "ENABLE_SVC_FLAP_DETECTION") + return 59; + if (name == "DISABLE_SVC_FLAP_DETECTION") + return 60; + if (name == "ENABLE_FLAP_DETECTION") + return 61; + if (name == "DISABLE_FLAP_DETECTION") + return 62; + if (name == "ENABLE_HOSTGROUP_SVC_NOTIFICATIONS") + return 63; + if (name == "DISABLE_HOSTGROUP_SVC_NOTIFICATIONS") + return 64; + if (name == "ENABLE_HOSTGROUP_HOST_NOTIFICATIONS") + return 65; + if (name == "DISABLE_HOSTGROUP_HOST_NOTIFICATIONS") + return 66; + if (name == "ENABLE_HOSTGROUP_SVC_CHECKS") + return 67; + if (name == "DISABLE_HOSTGROUP_SVC_CHECKS") + return 68; + if (name == "CANCEL_HOST_DOWNTIME") + return 69; + if (name == "CANCEL_SVC_DOWNTIME") + return 70; + if (name == "CANCEL_ACTIVE_HOST_DOWNTIME") + return 71; + if (name == "CANCEL_PENDING_HOST_DOWNTIME") + return 72; + if (name == "CANCEL_ACTIVE_SVC_DOWNTIME") + return 73; + if (name == "CANCEL_PENDING_SVC_DOWNTIME") + return 74; + if (name == "CANCEL_ACTIVE_HOST_SVC_DOWNTIME") + return 75; + if (name == "CANCEL_PENDING_HOST_SVC_DOWNTIME") + return 76; + if (name == "FLUSH_PENDING_COMMANDS") + return 77; + if (name == "DEL_HOST_DOWNTIME") + return 78; + if (name == "DEL_SVC_DOWNTIME") + return 79; + if (name == "ENABLE_FAILURE_PREDICTION") + return 80; + if (name == "DISABLE_FAILURE_PREDICTION") + return 81; + if (name == "ENABLE_PERFORMANCE_DATA") + return 82; + if (name == "DISABLE_PERFORMANCE_DATA") + return 83; + if (name == "SCHEDULE_HOSTGROUP_HOST_DOWNTIME") + return 84; + if (name == "SCHEDULE_HOSTGROUP_SVC_DOWNTIME") + return 85; + if (name == "SCHEDULE_HOST_SVC_DOWNTIME") + return 86; + if (name == "PROCESS_HOST_CHECK_RESULT") + return 87; + if (name == "START_EXECUTING_HOST_CHECKS") + return 88; + if (name == "STOP_EXECUTING_HOST_CHECKS") + return 89; + if (name == "START_ACCEPTING_PASSIVE_HOST_CHECKS") + return 90; + if (name == "STOP_ACCEPTING_PASSIVE_HOST_CHECKS") + return 91; + if (name == "ENABLE_PASSIVE_HOST_CHECKS") + return 92; + if (name == "DISABLE_PASSIVE_HOST_CHECKS") + return 93; + if (name == "START_OBSESSING_OVER_HOST_CHECKS") + return 94; + if (name == "STOP_OBSESSING_OVER_HOST_CHECKS") + return 95; + if (name == "SCHEDULE_HOST_CHECK") + return 96; + if (name == "SCHEDULE_FORCED_HOST_CHECK") + return 98; + if (name == "START_OBSESSING_OVER_SVC") + return 99; + if (name == "STOP_OBSESSING_OVER_SVC") + return 100; + if (name == "START_OBSESSING_OVER_HOST") + return 101; + if (name == "STOP_OBSESSING_OVER_HOST") + return 102; + if (name == "ENABLE_HOSTGROUP_HOST_CHECKS") + return 103; + if (name == "DISABLE_HOSTGROUP_HOST_CHECKS") + return 104; + if (name == "ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS") + return 105; + if (name == "DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS") + return 106; + if (name == "ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS") + return 107; + if (name == "DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS") + return 108; + if (name == "ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS") + return 109; + if (name == "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS") + return 110; + if (name == "ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS") + return 111; + if (name == "DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS") + return 112; + if (name == "ENABLE_SERVICEGROUP_SVC_CHECKS") + return 113; + if (name == "DISABLE_SERVICEGROUP_SVC_CHECKS") + return 114; + if (name == "ENABLE_SERVICEGROUP_HOST_CHECKS") + return 115; + if (name == "DISABLE_SERVICEGROUP_HOST_CHECKS") + return 116; + if (name == "ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS") + return 117; + if (name == "DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS") + return 118; + if (name == "ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS") + return 119; + if (name == "DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS") + return 120; + if (name == "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME") + return 121; + if (name == "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME") + return 122; + if (name == "CHANGE_GLOBAL_HOST_EVENT_HANDLER") + return 123; + if (name == "CHANGE_GLOBAL_SVC_EVENT_HANDLER") + return 124; + if (name == "CHANGE_HOST_EVENT_HANDLER") + return 125; + if (name == "CHANGE_SVC_EVENT_HANDLER") + return 126; + if (name == "CHANGE_HOST_CHECK_COMMAND") + return 127; + if (name == "CHANGE_SVC_CHECK_COMMAND") + return 128; + if (name == "CHANGE_NORMAL_HOST_CHECK_INTERVAL") + return 129; + if (name == "CHANGE_NORMAL_SVC_CHECK_INTERVAL") + return 130; + if (name == "CHANGE_RETRY_SVC_CHECK_INTERVAL") + return 131; + if (name == "CHANGE_MAX_HOST_CHECK_ATTEMPTS") + return 132; + if (name == "CHANGE_MAX_SVC_CHECK_ATTEMPTS") + return 133; + if (name == "SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME") + return 134; + if (name == "ENABLE_HOST_AND_CHILD_NOTIFICATIONS") + return 135; + if (name == "DISABLE_HOST_AND_CHILD_NOTIFICATIONS") + return 136; + if (name == "SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME") + return 137; + if (name == "ENABLE_SERVICE_FRESHNESS_CHECKS") + return 138; + if (name == "DISABLE_SERVICE_FRESHNESS_CHECKS") + return 139; + if (name == "ENABLE_HOST_FRESHNESS_CHECKS") + return 140; + if (name == "DISABLE_HOST_FRESHNESS_CHECKS") + return 141; + if (name == "SET_HOST_NOTIFICATION_NUMBER") + return 142; + if (name == "SET_SVC_NOTIFICATION_NUMBER") + return 143; + if (name == "CHANGE_HOST_CHECK_TIMEPERIOD") + return 144; + if (name == "CHANGE_SVC_CHECK_TIMEPERIOD") + return 145; + if (name == "PROCESS_FILE") + return 146; + if (name == "CHANGE_CUSTOM_HOST_VAR") + return 147; + if (name == "CHANGE_CUSTOM_SVC_VAR") + return 148; + if (name == "CHANGE_CUSTOM_CONTACT_VAR") + return 149; + if (name == "ENABLE_CONTACT_HOST_NOTIFICATIONS") + return 150; + if (name == "DISABLE_CONTACT_HOST_NOTIFICATIONS") + return 151; + if (name == "ENABLE_CONTACT_SVC_NOTIFICATIONS") + return 152; + if (name == "DISABLE_CONTACT_SVC_NOTIFICATIONS") + return 153; + if (name == "ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS") + return 154; + if (name == "DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS") + return 155; + if (name == "ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS") + return 156; + if (name == "DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS") + return 157; + if (name == "CHANGE_RETRY_HOST_CHECK_INTERVAL") + return 158; + if (name == "SEND_CUSTOM_HOST_NOTIFICATION") + return 159; + if (name == "SEND_CUSTOM_SVC_NOTIFICATION") + return 160; + if (name == "CHANGE_HOST_NOTIFICATION_TIMEPERIOD") + return 161; + if (name == "CHANGE_SVC_NOTIFICATION_TIMEPERIOD") + return 162; + if (name == "CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD") + return 163; + if (name == "CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD") + return 164; + if (name == "CHANGE_HOST_MODATTR") + return 165; + if (name == "CHANGE_SVC_MODATTR") + return 166; + if (name == "CHANGE_CONTACT_MODATTR") + return 167; + if (name == "CHANGE_CONTACT_MODHATTR") + return 168; + if (name == "CHANGE_CONTACT_MODSATTR") + return 169; + if (name == "SYNC_STATE_INFORMATION") + return 170; + if (name == "DEL_DOWNTIME_BY_HOST_NAME") + return 171; + if (name == "DEL_DOWNTIME_BY_HOSTGROUP_NAME") + return 172; + if (name == "DEL_DOWNTIME_BY_START_TIME_COMMENT") + return 173; + if (name == "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE") + return 174; + if (name == "ACKNOWLEDGE_SVC_PROBLEM_EXPIRE") + return 175; + if (name == "DISABLE_NOTIFICATIONS_EXPIRE_TIME") + return 176; + if (name == "CUSTOM_COMMAND") + return 999; + + return 0; +} diff --git a/lib/db_ido/dbevents.hpp b/lib/db_ido/dbevents.hpp index db52ccf1b..3e27d2960 100644 --- a/lib/db_ido/dbevents.hpp +++ b/lib/db_ido/dbevents.hpp @@ -132,6 +132,12 @@ private: static void AddDowntimeInternal(std::vector<DbQuery>& queries, const Downtime::Ptr& downtime, bool historical); static void RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downtime::Ptr& downtime); static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled); + + static int GetHostState(const Host::Ptr& host); + static String GetHostStateString(const Host::Ptr& host); + static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time); + static int MapNotificationReasonType(NotificationType type); + static int MapExternalCommandType(const String& name); }; } diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index 7a7fa92ae..b9c14d528 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -227,7 +227,7 @@ void DbObject::SendVarsConfigUpdateHeavy() query2.WhereCriteria->Set("object_id", obj); queries.emplace_back(std::move(query2)); - Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object); + Dictionary::Ptr vars = custom_var_object->GetVars(); if (vars) { ObjectLock olock (vars); @@ -274,7 +274,7 @@ void DbObject::SendVarsStatusUpdate() if (!custom_var_object) return; - Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object); + Dictionary::Ptr vars = custom_var_object->GetVars(); if (vars) { std::vector<DbQuery> queries; diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 0dc0abc3f..e339b5e70 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -29,6 +29,7 @@ #include "icinga/checkcommand.hpp" #include "icinga/eventcommand.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "base/convert.hpp" #include "base/objectlock.hpp" #include "base/logger.hpp" @@ -47,65 +48,52 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const Dictionary::Ptr fields = new Dictionary(); Host::Ptr host = static_pointer_cast<Host>(GetObject()); - fields->Set("alias", CompatUtility::GetHostAlias(host)); - fields->Set("display_name", host->GetDisplayName()); + /* Compatibility fallback. */ + String displayName = host->GetDisplayName(); + + if (!displayName.IsEmpty()) + fields->Set("alias", displayName); + else + fields->Set("alias", host->GetName()); + + 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("check_command_args", CompatUtility::GetCheckableCommandArgs(host)); fields->Set("eventhandler_command_object_id", host->GetEventCommand()); - fields->Set("eventhandler_command_args", Empty); - fields->Set("notification_timeperiod_object_id", Empty); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); - fields->Set("failure_prediction_options", Empty); - fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(host)); - fields->Set("retry_interval", CompatUtility::GetCheckableRetryInterval(host)); + 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("first_notification_delay", Empty); - - fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host)); - fields->Set("notify_on_down", CompatUtility::GetHostNotifyOnDown(host)); - fields->Set("notify_on_unreachable", CompatUtility::GetHostNotifyOnDown(host)); - - fields->Set("notify_on_recovery", CompatUtility::GetCheckableNotifyOnRecovery(host)); - fields->Set("notify_on_flapping", CompatUtility::GetCheckableNotifyOnFlapping(host)); - fields->Set("notify_on_downtime", CompatUtility::GetCheckableNotifyOnDowntime(host)); - - fields->Set("stalk_on_up", Empty); - fields->Set("stalk_on_down", Empty); - fields->Set("stalk_on_unreachable", Empty); - - fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(host)); - fields->Set("flap_detection_on_up", Empty); - fields->Set("flap_detection_on_down", Empty); - fields->Set("flap_detection_on_unreachable", Empty); - fields->Set("low_flap_threshold", CompatUtility::GetCheckableLowFlapThreshold(host)); - fields->Set("high_flap_threshold", CompatUtility::GetCheckableHighFlapThreshold(host)); - - fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(host)); - - fields->Set("freshness_checks_enabled", CompatUtility::GetCheckableFreshnessChecksEnabled(host)); - fields->Set("freshness_threshold", CompatUtility::GetCheckableFreshnessThreshold(host)); - fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(host)); - fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(host)); - fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(host)); - - fields->Set("retain_status_information", 1); - fields->Set("retain_nonstatus_information", 1); - - fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(host)); - - fields->Set("obsess_over_host", 0); - fields->Set("failure_prediction_enabled", 0); - + 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); + + 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. */ + 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; } @@ -119,59 +107,62 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const if (cr) { fields->Set("output", CompatUtility::GetCheckResultOutput(cr)); fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); - fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(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", CompatUtility::GetHostCurrentState(host)); - fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(host)); + int currentState = host->GetState(); + + if (currentState != HostUp && !host->IsReachable()) + currentState = 2; /* hardcoded compat state */ + + fields->Set("current_state", currentState); + fields->Set("has_been_checked", host->HasBeenChecked()); 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", CompatUtility::GetCheckableCheckType(host)); + 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<int>(host->GetLastStateUp()))); - fields->Set("last_time_down", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateDown()))); - fields->Set("last_time_unreachable", DbValue::FromTimestamp(static_cast<int>(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("notifications_enabled", host->GetEnableNotifications()); + fields->Set("problem_has_been_acknowledged", host->GetAcknowledgement() != AcknowledgementNone); + fields->Set("acknowledgement_type", host->GetAcknowledgement()); + 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()); + 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))); - fields->Set("no_more_notifications", Empty); - fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(host)); - fields->Set("problem_has_been_acknowledged", CompatUtility::GetCheckableProblemHasBeenAcknowledged(host)); - fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(host)); - fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host)); - fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(host)); - fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(host)); - fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(host)); - fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(host)); - fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(host)); - fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(host)); - if (cr) { - fields->Set("latency", Convert::ToString(cr->CalculateLatency())); - fields->Set("execution_time", Convert::ToString(cr->CalculateExecutionTime())); - } + EventCommand::Ptr eventCommand = host->GetEventCommand(); - fields->Set("scheduled_downtime_depth", host->GetDowntimeDepth()); - fields->Set("failure_prediction_enabled", Empty); - fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(host)); - fields->Set("obsess_over_host", Empty); - fields->Set("event_handler", CompatUtility::GetCheckableEventHandler(host)); - fields->Set("check_command", CompatUtility::GetCheckableCheckCommand(host)); - fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(host)); - fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(host)); - fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); - fields->Set("is_reachable", CompatUtility::GetCheckableIsReachable(host)); + if (eventCommand) + fields->Set("event_handler", eventCommand->GetName()); - fields->Set("original_attributes", JsonEncode(host->GetOriginalAttributes())); + CheckCommand::Ptr checkCommand = host->GetCheckCommand(); + + if (checkCommand) + fields->Set("check_command", checkCommand->GetName()); return fields; } @@ -275,7 +266,7 @@ void HostDbObject::OnConfigUpdateHeavy() continue; } - int state_filter = dep->GetStateFilter(); + int stateFilter = dep->GetStateFilter(); Log(LogDebug, "HostDbObject") << "parent host: " << parent->GetName(); @@ -285,8 +276,8 @@ void HostDbObject::OnConfigUpdateHeavy() fields2->Set("dependent_host_object_id", host); fields2->Set("inherits_parent", 1); fields2->Set("timeperiod_object_id", dep->GetPeriod()); - fields2->Set("fail_on_up", (state_filter & StateFilterUp) ? 1 : 0); - fields2->Set("fail_on_down", (state_filter & StateFilterDown) ? 1 : 0); + fields2->Set("fail_on_up", stateFilter & StateFilterUp); + fields2->Set("fail_on_down", stateFilter & StateFilterDown); fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbQuery query2; diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 2c82e8b23..93a80d199 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -28,6 +28,7 @@ #include "icinga/eventcommand.hpp" #include "icinga/externalcommandprocessor.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "icinga/icingaapplication.hpp" #include "remote/endpoint.hpp" #include "base/convert.hpp" @@ -56,52 +57,42 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("host_object_id", host); fields->Set("display_name", service->GetDisplayName()); fields->Set("check_command_object_id", service->GetCheckCommand()); - fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(service)); fields->Set("eventhandler_command_object_id", service->GetEventCommand()); - fields->Set("eventhandler_command_args", Empty); - fields->Set("notification_timeperiod_object_id", Empty); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); - fields->Set("failure_prediction_options", Empty); - fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(service)); - fields->Set("retry_interval", CompatUtility::GetCheckableRetryInterval(service)); + 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("first_notification_delay", Empty); - fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service)); - fields->Set("notify_on_warning", CompatUtility::GetCheckableNotifyOnWarning(service)); - fields->Set("notify_on_unknown", CompatUtility::GetCheckableNotifyOnUnknown(service)); - fields->Set("notify_on_critical", CompatUtility::GetCheckableNotifyOnCritical(service)); - fields->Set("notify_on_recovery", CompatUtility::GetCheckableNotifyOnRecovery(service)); - fields->Set("notify_on_flapping", CompatUtility::GetCheckableNotifyOnFlapping(service)); - fields->Set("notify_on_downtime", CompatUtility::GetCheckableNotifyOnDowntime(service)); - 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", CompatUtility::GetCheckableIsVolatile(service)); - fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(service)); - fields->Set("flap_detection_on_ok", Empty); - fields->Set("flap_detection_on_warning", Empty); - fields->Set("flap_detection_on_unknown", Empty); - fields->Set("flap_detection_on_critical", Empty); - fields->Set("low_flap_threshold", CompatUtility::GetCheckableLowFlapThreshold(service)); - fields->Set("high_flap_threshold", CompatUtility::GetCheckableHighFlapThreshold(service)); - fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(service)); - fields->Set("freshness_checks_enabled", CompatUtility::GetCheckableFreshnessChecksEnabled(service)); - fields->Set("freshness_threshold", CompatUtility::GetCheckableFreshnessThreshold(service)); - fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(service)); - fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(service)); - fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(service)); - fields->Set("retain_status_information", Empty); - fields->Set("retain_nonstatus_information", Empty); - fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(service)); - fields->Set("obsess_over_service", Empty); - fields->Set("failure_prediction_enabled", Empty); + fields->Set("is_volatile", service->GetVolatile()); + fields->Set("flap_detection_enabled", service->GetEnableFlapping()); + fields->Set("low_flap_threshold", service->GetFlappingThresholdLow()); + fields->Set("high_flap_threshold", service->GetFlappingThresholdLow()); + fields->Set("process_performance_data", service->GetEnablePerfdata()); + fields->Set("freshness_checks_enabled", 1); + fields->Set("freshness_threshold", Convert::ToLong(service->GetCheckInterval())); + fields->Set("event_handler_enabled", service->GetEnableEventHandler()); + fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks()); + fields->Set("active_checks_enabled", service->GetEnableActiveChecks()); + fields->Set("notifications_enabled", service->GetEnableNotifications()); fields->Set("notes", service->GetNotes()); fields->Set("notes_url", service->GetNotesUrl()); fields->Set("action_url", service->GetActionUrl()); 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; } @@ -114,58 +105,58 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const if (cr) { fields->Set("output", CompatUtility::GetCheckResultOutput(cr)); fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); - fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(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()); - fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(service)); + fields->Set("has_been_checked", service->HasBeenChecked()); 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", CompatUtility::GetCheckableCheckType(service)); + 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<int>(service->GetLastStateOK()))); - fields->Set("last_time_warning", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateWarning()))); - fields->Set("last_time_critical", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateCritical()))); - fields->Set("last_time_unknown", DbValue::FromTimestamp(static_cast<int>(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("notifications_enabled", service->GetEnableNotifications()); + fields->Set("problem_has_been_acknowledged", service->GetAcknowledgement() != AcknowledgementNone); + fields->Set("acknowledgement_type", service->GetAcknowledgement()); + 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()); + 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))); - fields->Set("no_more_notifications", Empty); - fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(service)); - fields->Set("problem_has_been_acknowledged", CompatUtility::GetCheckableProblemHasBeenAcknowledged(service)); - fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(service)); - fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service)); - fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(service)); - fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(service)); - fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(service)); - fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(service)); - fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(service)); - fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(service)); - if (cr) { - fields->Set("latency", Convert::ToString(cr->CalculateLatency())); - fields->Set("execution_time", Convert::ToString(cr->CalculateExecutionTime())); - } + EventCommand::Ptr eventCommand = service->GetEventCommand(); - fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth()); - fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(service)); - fields->Set("event_handler", CompatUtility::GetCheckableEventHandler(service)); - fields->Set("check_command", CompatUtility::GetCheckableCheckCommand(service)); - fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(service)); - fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(service)); - fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); - fields->Set("is_reachable", CompatUtility::GetCheckableIsReachable(service)); + if (eventCommand) + fields->Set("event_handler", eventCommand->GetName()); - fields->Set("original_attributes", JsonEncode(service->GetOriginalAttributes())); + CheckCommand::Ptr checkCommand = service->GetCheckCommand(); + + if (checkCommand) + fields->Set("check_command", checkCommand->GetName()); return fields; } @@ -236,7 +227,7 @@ void ServiceDbObject::OnConfigUpdateHeavy() Log(LogDebug, "ServiceDbObject") << "service parents: " << parent->GetName(); - int state_filter = dep->GetStateFilter(); + int stateFilter = dep->GetStateFilter(); /* service dependencies */ Dictionary::Ptr fields1 = new Dictionary(); @@ -244,10 +235,10 @@ void ServiceDbObject::OnConfigUpdateHeavy() fields1->Set("dependent_service_object_id", service); fields1->Set("inherits_parent", 1); fields1->Set("timeperiod_object_id", dep->GetPeriod()); - fields1->Set("fail_on_ok", (state_filter & StateFilterOK) ? 1 : 0); - fields1->Set("fail_on_warning", (state_filter & StateFilterWarning) ? 1 : 0); - fields1->Set("fail_on_critical", (state_filter & StateFilterCritical) ? 1 : 0); - fields1->Set("fail_on_unknown", (state_filter & StateFilterUnknown) ? 1 : 0); + fields1->Set("fail_on_ok", stateFilter & StateFilterOK); + fields1->Set("fail_on_warning", stateFilter & StateFilterWarning); + fields1->Set("fail_on_critical", stateFilter & StateFilterCritical); + fields1->Set("fail_on_unknown", stateFilter & StateFilterUnknown); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbQuery query1; diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 29eef3dd5..3eb0dc573 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -32,7 +32,7 @@ using namespace icinga; -/* command */ +/* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCommandLine(const Command::Ptr& command) { Value commandLine = command->GetCommandLine(); @@ -56,6 +56,7 @@ String CompatUtility::GetCommandLine(const Command::Ptr& command) } String CompatUtility::GetCommandNamePrefix(const Command::Ptr& command) +/* Helper. */ { if (!command) return Empty; @@ -72,6 +73,7 @@ String CompatUtility::GetCommandNamePrefix(const Command::Ptr& command) } String CompatUtility::GetCommandName(const Command::Ptr& command) +/* Used in DB IDO, StatusDataWriter and Livestatus. */ { if (!command) return Empty; @@ -79,53 +81,7 @@ String CompatUtility::GetCommandName(const Command::Ptr& command) return GetCommandNamePrefix(command) + command->GetName(); } -/* host */ -int CompatUtility::GetHostCurrentState(const Host::Ptr& host) -{ - if (host->GetState() != HostUp && !host->IsReachable()) - return 2; /* hardcoded compat state */ - - return host->GetState(); -} - -String CompatUtility::GetHostStateString(const Host::Ptr& host) -{ - if (host->GetState() != HostUp && !host->IsReachable()) - return "UNREACHABLE"; /* hardcoded compat state */ - - return Host::StateToString(host->GetState()); -} - -String CompatUtility::GetHostAlias(const Host::Ptr& host) -{ - if (!host->GetDisplayName().IsEmpty()) - return host->GetName(); - else - return host->GetDisplayName(); -} - -int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host) -{ - unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); - - if ((notification_state_filter & ServiceCritical) || - (notification_state_filter & ServiceWarning)) - return 1; - - return 0; -} - -int CompatUtility::GetHostNotifyOnUnreachable(const Host::Ptr& host) -{ - unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); - - if (notification_state_filter & ServiceUnknown) - return 1; - - return 0; -} - -/* service */ +/* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) { CheckCommand::Ptr command = checkable->GetCheckCommand(); @@ -191,204 +147,7 @@ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) return Empty; } -int CompatUtility::GetCheckableCheckType(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableActiveChecks() ? 0 : 1); -} - -double CompatUtility::GetCheckableCheckInterval(const Checkable::Ptr& checkable) -{ - return checkable->GetCheckInterval() / 60.0; -} - -double CompatUtility::GetCheckableRetryInterval(const Checkable::Ptr& checkable) -{ - return checkable->GetRetryInterval() / 60.0; -} - -String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) -{ - TimePeriod::Ptr check_period = checkable->GetCheckPeriod(); - if (check_period) - return check_period->GetName(); - else - return "24x7"; -} - -int CompatUtility::GetCheckableHasBeenChecked(const Checkable::Ptr& checkable) -{ - return (checkable->GetLastCheckResult() ? 1 : 0); -} - - -int CompatUtility::GetCheckableProblemHasBeenAcknowledged(const Checkable::Ptr& checkable) -{ - return (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0); -} - -int CompatUtility::GetCheckableAcknowledgementType(const Checkable::Ptr& checkable) -{ - return static_cast<int>(checkable->GetAcknowledgement()); -} - -int CompatUtility::GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnablePassiveChecks() ? 1 : 0); -} - -int CompatUtility::GetCheckableActiveChecksEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableActiveChecks() ? 1 : 0); -} - -int CompatUtility::GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableEventHandler() ? 1 : 0); -} - -int CompatUtility::GetCheckableFlapDetectionEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableFlapping() ? 1 : 0); -} - -int CompatUtility::GetCheckableIsFlapping(const Checkable::Ptr& checkable) -{ - return (checkable->IsFlapping() ? 1 : 0); -} - -int CompatUtility::GetCheckableIsReachable(const Checkable::Ptr& checkable) -{ - return (checkable->IsReachable() ? 1 : 0); -} - -double CompatUtility::GetCheckablePercentStateChange(const Checkable::Ptr& checkable) -{ - return checkable->GetFlappingCurrent(); -} - -int CompatUtility::GetCheckableProcessPerformanceData(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnablePerfdata() ? 1 : 0); -} - -String CompatUtility::GetCheckableEventHandler(const Checkable::Ptr& checkable) -{ - String event_command_str; - EventCommand::Ptr eventcommand = checkable->GetEventCommand(); - - if (eventcommand) - event_command_str = eventcommand->GetName(); - - return event_command_str; -} - -String CompatUtility::GetCheckableCheckCommand(const Checkable::Ptr& checkable) -{ - String check_command_str; - CheckCommand::Ptr checkcommand = checkable->GetCheckCommand(); - - if (checkcommand) - check_command_str = checkcommand->GetName(); - - return check_command_str; -} - -int CompatUtility::GetCheckableIsVolatile(const Checkable::Ptr& checkable) -{ - return (checkable->GetVolatile() ? 1 : 0); -} - -double CompatUtility::GetCheckableLowFlapThreshold(const Checkable::Ptr& checkable) -{ - return checkable->GetFlappingThresholdLow(); -} - -double CompatUtility::GetCheckableHighFlapThreshold(const Checkable::Ptr& checkable) -{ - return checkable->GetFlappingThresholdHigh(); -} - -int CompatUtility::GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetCheckInterval() > 0 ? 1 : 0); -} - -int CompatUtility::GetCheckableFreshnessThreshold(const Checkable::Ptr& checkable) -{ - return static_cast<int>(checkable->GetCheckInterval()); -} - -double CompatUtility::GetCheckableStaleness(const Checkable::Ptr& checkable) -{ - if (checkable->HasBeenChecked() && checkable->GetLastCheck() > 0) - return (Utility::GetTime() - checkable->GetLastCheck()) / (checkable->GetCheckInterval() * 3600); - - return 0.0; -} - -int CompatUtility::GetCheckableIsAcknowledged(const Checkable::Ptr& checkable) -{ - return (checkable->IsAcknowledged() ? 1 : 0); -} - -int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable) -{ - if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile()) - return 1; - - return 0; -} - -int CompatUtility::GetCheckableInCheckPeriod(const Checkable::Ptr& checkable) -{ - TimePeriod::Ptr timeperiod = checkable->GetCheckPeriod(); - - /* none set means always checked */ - if (!timeperiod) - return 1; - - return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0); -} - -int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) -{ - for (const Notification::Ptr& notification : checkable->GetNotifications()) { - TimePeriod::Ptr timeperiod = notification->GetPeriod(); - - if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) - return 1; - } - - return 0; -} - -/* vars attr */ -Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const CustomVarObject::Ptr& object) -{ - Dictionary::Ptr vars = object->GetVars(); - - if (!vars) - return nullptr; - - return vars; -} - -String CompatUtility::GetCustomAttributeConfig(const CustomVarObject::Ptr& object, const String& name) -{ - Dictionary::Ptr vars = object->GetVars(); - - if (!vars) - return Empty; - - return vars->Get(name); -} - -/* notifications */ -int CompatUtility::GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableNotifications() ? 1 : 0); -} - +/* Used in DB IDO, StatusDataWriter and Livestatus. */ int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable) { double last_notification = 0.0; @@ -400,6 +159,7 @@ int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr return static_cast<int>(last_notification); } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ int CompatUtility::GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable) { double next_notification = 0.0; @@ -411,6 +171,7 @@ int CompatUtility::GetCheckableNotificationNextNotification(const Checkable::Ptr return static_cast<int>(next_notification); } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ int CompatUtility::GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable) { int notification_number = 0; @@ -422,6 +183,7 @@ int CompatUtility::GetCheckableNotificationNotificationNumber(const Checkable::P return notification_number; } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable) { double notification_interval = -1; @@ -437,57 +199,7 @@ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkab return notification_interval / 60.0; } -String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable) -{ - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - unsigned long notification_type_filter = 0; - unsigned long notification_state_filter = 0; - - for (const Notification::Ptr& notification : checkable->GetNotifications()) { - notification_type_filter |= notification->GetTypeFilter(); - notification_state_filter |= notification->GetStateFilter(); - } - - std::vector<String> notification_options; - - /* notification state filters */ - if (service) { - if (notification_state_filter & ServiceWarning) { - notification_options.emplace_back("w"); - } - if (notification_state_filter & ServiceUnknown) { - notification_options.emplace_back("u"); - } - if (notification_state_filter & ServiceCritical) { - notification_options.emplace_back("c"); - } - } else { - if (notification_state_filter & HostDown) { - notification_options.emplace_back("d"); - } - } - - /* notification type filters */ - if (notification_type_filter & NotificationRecovery) { - notification_options.emplace_back("r"); - } - if ((notification_type_filter & NotificationFlappingStart) || - (notification_type_filter & NotificationFlappingEnd)) { - notification_options.emplace_back("f"); - } - if ((notification_type_filter & NotificationDowntimeStart) || - (notification_type_filter & NotificationDowntimeEnd) || - (notification_type_filter & NotificationDowntimeRemoved)) { - notification_options.emplace_back("s"); - } - - return boost::algorithm::join(notification_options, ","); -} - +/* Helper. */ int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable) { unsigned long notification_type_filter = 0; @@ -501,6 +213,7 @@ int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& chec return notification_type_filter; } +/* Helper. */ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable) { unsigned long notification_state_filter = 0; @@ -514,61 +227,7 @@ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& che return notification_state_filter; } -int CompatUtility::GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable) -{ - if (GetCheckableNotificationStateFilter(checkable) & ServiceWarning) - return 1; - - return 0; -} - -int CompatUtility::GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable) -{ - if (GetCheckableNotificationStateFilter(checkable) & ServiceCritical) - return 1; - - return 0; -} - -int CompatUtility::GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable) -{ - if (GetCheckableNotificationStateFilter(checkable) & ServiceUnknown) - return 1; - - return 0; -} - -int CompatUtility::GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable) -{ - if (GetCheckableNotificationTypeFilter(checkable) & NotificationRecovery) - return 1; - - return 0; -} - -int CompatUtility::GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable) -{ - unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable); - - if ((notification_type_filter & NotificationFlappingStart) || - (notification_type_filter & NotificationFlappingEnd)) - return 1; - - return 0; -} - -int CompatUtility::GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable) -{ - unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable); - - if ((notification_type_filter & NotificationDowntimeStart) || - (notification_type_filter & NotificationDowntimeEnd) || - (notification_type_filter & NotificationDowntimeRemoved)) - return 1; - - return 0; -} - +/* Used in DB IDO, StatusDataWriter and Livestatus. */ std::set<User::Ptr> CompatUtility::GetCheckableNotificationUsers(const Checkable::Ptr& checkable) { /* Service -> Notifications -> (Users + UserGroups -> Users) */ @@ -591,6 +250,7 @@ std::set<User::Ptr> CompatUtility::GetCheckableNotificationUsers(const Checkable return allUsers; } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ std::set<UserGroup::Ptr> CompatUtility::GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable) { std::set<UserGroup::Ptr> usergroups; @@ -606,6 +266,7 @@ std::set<UserGroup::Ptr> CompatUtility::GetCheckableNotificationUserGroups(const return usergroups; } +/* Used in DB IDO, StatusDataWriter, Livestatus, CompatLogger, GelfWriter. */ String CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr) { if (!cr) @@ -620,6 +281,7 @@ String CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr) return raw_output.SubStr(0, line_end); } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCheckResultLongOutput(const CheckResult::Ptr& cr) { if (!cr) @@ -640,14 +302,7 @@ String CompatUtility::GetCheckResultLongOutput(const CheckResult::Ptr& cr) return Empty; } -String CompatUtility::GetCheckResultPerfdata(const CheckResult::Ptr& cr) -{ - if (!cr) - return String(); - - return PluginUtility::FormatPerfdata(cr->GetPerformanceData()); -} - +/* Helper for DB IDO, StatusDataWriter and Livestatus. Used in StatusDataWriter. */ String CompatUtility::EscapeString(const String& str) { String result = str; @@ -655,399 +310,10 @@ String CompatUtility::EscapeString(const String& str) return result; } +/* Used in ExternalCommandListener and CheckResultReader. */ String CompatUtility::UnEscapeString(const String& str) { String result = str; boost::algorithm::replace_all(result, "\\n", "\n"); return result; } - -std::pair<unsigned long, unsigned long> CompatUtility::ConvertTimestamp(double time) -{ - unsigned long time_sec = static_cast<long>(time); - unsigned long time_usec = (time - time_sec) * 1000 * 1000; - - return std::make_pair(time_sec, time_usec); -} - -int CompatUtility::MapNotificationReasonType(NotificationType type) -{ - switch (type) { - case NotificationDowntimeStart: - return 5; - case NotificationDowntimeEnd: - return 6; - case NotificationDowntimeRemoved: - return 7; - case NotificationCustom: - return 8; - case NotificationAcknowledgement: - return 1; - case NotificationProblem: - return 0; - case NotificationRecovery: - return 0; - case NotificationFlappingStart: - return 2; - case NotificationFlappingEnd: - return 3; - default: - return 0; - } -} - -int CompatUtility::MapExternalCommandType(const String& name) -{ - if (name == "NONE") - return 0; - if (name == "ADD_HOST_COMMENT") - return 1; - if (name == "DEL_HOST_COMMENT") - return 2; - if (name == "ADD_SVC_COMMENT") - return 3; - if (name == "DEL_SVC_COMMENT") - return 4; - if (name == "ENABLE_SVC_CHECK") - return 5; - if (name == "DISABLE_SVC_CHECK") - return 6; - if (name == "SCHEDULE_SVC_CHECK") - return 7; - if (name == "DELAY_SVC_NOTIFICATION") - return 9; - if (name == "DELAY_HOST_NOTIFICATION") - return 10; - if (name == "DISABLE_NOTIFICATIONS") - return 11; - if (name == "ENABLE_NOTIFICATIONS") - return 12; - if (name == "RESTART_PROCESS") - return 13; - if (name == "SHUTDOWN_PROCESS") - return 14; - if (name == "ENABLE_HOST_SVC_CHECKS") - return 15; - if (name == "DISABLE_HOST_SVC_CHECKS") - return 16; - if (name == "SCHEDULE_HOST_SVC_CHECKS") - return 17; - if (name == "DELAY_HOST_SVC_NOTIFICATIONS") - return 19; - if (name == "DEL_ALL_HOST_COMMENTS") - return 20; - if (name == "DEL_ALL_SVC_COMMENTS") - return 21; - if (name == "ENABLE_SVC_NOTIFICATIONS") - return 22; - if (name == "DISABLE_SVC_NOTIFICATIONS") - return 23; - if (name == "ENABLE_HOST_NOTIFICATIONS") - return 24; - if (name == "DISABLE_HOST_NOTIFICATIONS") - return 25; - if (name == "ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST") - return 26; - if (name == "DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST") - return 27; - if (name == "ENABLE_HOST_SVC_NOTIFICATIONS") - return 28; - if (name == "DISABLE_HOST_SVC_NOTIFICATIONS") - return 29; - if (name == "PROCESS_SERVICE_CHECK_RESULT") - return 30; - if (name == "SAVE_STATE_INFORMATION") - return 31; - if (name == "READ_STATE_INFORMATION") - return 32; - if (name == "ACKNOWLEDGE_HOST_PROBLEM") - return 33; - if (name == "ACKNOWLEDGE_SVC_PROBLEM") - return 34; - if (name == "START_EXECUTING_SVC_CHECKS") - return 35; - if (name == "STOP_EXECUTING_SVC_CHECKS") - return 36; - if (name == "START_ACCEPTING_PASSIVE_SVC_CHECKS") - return 37; - if (name == "STOP_ACCEPTING_PASSIVE_SVC_CHECKS") - return 38; - if (name == "ENABLE_PASSIVE_SVC_CHECKS") - return 39; - if (name == "DISABLE_PASSIVE_SVC_CHECKS") - return 40; - if (name == "ENABLE_EVENT_HANDLERS") - return 41; - if (name == "DISABLE_EVENT_HANDLERS") - return 42; - if (name == "ENABLE_HOST_EVENT_HANDLER") - return 43; - if (name == "DISABLE_HOST_EVENT_HANDLER") - return 44; - if (name == "ENABLE_SVC_EVENT_HANDLER") - return 45; - if (name == "DISABLE_SVC_EVENT_HANDLER") - return 46; - if (name == "ENABLE_HOST_CHECK") - return 47; - if (name == "DISABLE_HOST_CHECK") - return 48; - if (name == "START_OBSESSING_OVER_SVC_CHECKS") - return 49; - if (name == "STOP_OBSESSING_OVER_SVC_CHECKS") - return 50; - if (name == "REMOVE_HOST_ACKNOWLEDGEMENT") - return 51; - if (name == "REMOVE_SVC_ACKNOWLEDGEMENT") - return 52; - if (name == "SCHEDULE_FORCED_HOST_SVC_CHECKS") - return 53; - if (name == "SCHEDULE_FORCED_SVC_CHECK") - return 54; - if (name == "SCHEDULE_HOST_DOWNTIME") - return 55; - if (name == "SCHEDULE_SVC_DOWNTIME") - return 56; - if (name == "ENABLE_HOST_FLAP_DETECTION") - return 57; - if (name == "DISABLE_HOST_FLAP_DETECTION") - return 58; - if (name == "ENABLE_SVC_FLAP_DETECTION") - return 59; - if (name == "DISABLE_SVC_FLAP_DETECTION") - return 60; - if (name == "ENABLE_FLAP_DETECTION") - return 61; - if (name == "DISABLE_FLAP_DETECTION") - return 62; - if (name == "ENABLE_HOSTGROUP_SVC_NOTIFICATIONS") - return 63; - if (name == "DISABLE_HOSTGROUP_SVC_NOTIFICATIONS") - return 64; - if (name == "ENABLE_HOSTGROUP_HOST_NOTIFICATIONS") - return 65; - if (name == "DISABLE_HOSTGROUP_HOST_NOTIFICATIONS") - return 66; - if (name == "ENABLE_HOSTGROUP_SVC_CHECKS") - return 67; - if (name == "DISABLE_HOSTGROUP_SVC_CHECKS") - return 68; - if (name == "CANCEL_HOST_DOWNTIME") - return 69; - if (name == "CANCEL_SVC_DOWNTIME") - return 70; - if (name == "CANCEL_ACTIVE_HOST_DOWNTIME") - return 71; - if (name == "CANCEL_PENDING_HOST_DOWNTIME") - return 72; - if (name == "CANCEL_ACTIVE_SVC_DOWNTIME") - return 73; - if (name == "CANCEL_PENDING_SVC_DOWNTIME") - return 74; - if (name == "CANCEL_ACTIVE_HOST_SVC_DOWNTIME") - return 75; - if (name == "CANCEL_PENDING_HOST_SVC_DOWNTIME") - return 76; - if (name == "FLUSH_PENDING_COMMANDS") - return 77; - if (name == "DEL_HOST_DOWNTIME") - return 78; - if (name == "DEL_SVC_DOWNTIME") - return 79; - if (name == "ENABLE_FAILURE_PREDICTION") - return 80; - if (name == "DISABLE_FAILURE_PREDICTION") - return 81; - if (name == "ENABLE_PERFORMANCE_DATA") - return 82; - if (name == "DISABLE_PERFORMANCE_DATA") - return 83; - if (name == "SCHEDULE_HOSTGROUP_HOST_DOWNTIME") - return 84; - if (name == "SCHEDULE_HOSTGROUP_SVC_DOWNTIME") - return 85; - if (name == "SCHEDULE_HOST_SVC_DOWNTIME") - return 86; - if (name == "PROCESS_HOST_CHECK_RESULT") - return 87; - if (name == "START_EXECUTING_HOST_CHECKS") - return 88; - if (name == "STOP_EXECUTING_HOST_CHECKS") - return 89; - if (name == "START_ACCEPTING_PASSIVE_HOST_CHECKS") - return 90; - if (name == "STOP_ACCEPTING_PASSIVE_HOST_CHECKS") - return 91; - if (name == "ENABLE_PASSIVE_HOST_CHECKS") - return 92; - if (name == "DISABLE_PASSIVE_HOST_CHECKS") - return 93; - if (name == "START_OBSESSING_OVER_HOST_CHECKS") - return 94; - if (name == "STOP_OBSESSING_OVER_HOST_CHECKS") - return 95; - if (name == "SCHEDULE_HOST_CHECK") - return 96; - if (name == "SCHEDULE_FORCED_HOST_CHECK") - return 98; - if (name == "START_OBSESSING_OVER_SVC") - return 99; - if (name == "STOP_OBSESSING_OVER_SVC") - return 100; - if (name == "START_OBSESSING_OVER_HOST") - return 101; - if (name == "STOP_OBSESSING_OVER_HOST") - return 102; - if (name == "ENABLE_HOSTGROUP_HOST_CHECKS") - return 103; - if (name == "DISABLE_HOSTGROUP_HOST_CHECKS") - return 104; - if (name == "ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS") - return 105; - if (name == "DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS") - return 106; - if (name == "ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS") - return 107; - if (name == "DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS") - return 108; - if (name == "ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS") - return 109; - if (name == "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS") - return 110; - if (name == "ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS") - return 111; - if (name == "DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS") - return 112; - if (name == "ENABLE_SERVICEGROUP_SVC_CHECKS") - return 113; - if (name == "DISABLE_SERVICEGROUP_SVC_CHECKS") - return 114; - if (name == "ENABLE_SERVICEGROUP_HOST_CHECKS") - return 115; - if (name == "DISABLE_SERVICEGROUP_HOST_CHECKS") - return 116; - if (name == "ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS") - return 117; - if (name == "DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS") - return 118; - if (name == "ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS") - return 119; - if (name == "DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS") - return 120; - if (name == "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME") - return 121; - if (name == "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME") - return 122; - if (name == "CHANGE_GLOBAL_HOST_EVENT_HANDLER") - return 123; - if (name == "CHANGE_GLOBAL_SVC_EVENT_HANDLER") - return 124; - if (name == "CHANGE_HOST_EVENT_HANDLER") - return 125; - if (name == "CHANGE_SVC_EVENT_HANDLER") - return 126; - if (name == "CHANGE_HOST_CHECK_COMMAND") - return 127; - if (name == "CHANGE_SVC_CHECK_COMMAND") - return 128; - if (name == "CHANGE_NORMAL_HOST_CHECK_INTERVAL") - return 129; - if (name == "CHANGE_NORMAL_SVC_CHECK_INTERVAL") - return 130; - if (name == "CHANGE_RETRY_SVC_CHECK_INTERVAL") - return 131; - if (name == "CHANGE_MAX_HOST_CHECK_ATTEMPTS") - return 132; - if (name == "CHANGE_MAX_SVC_CHECK_ATTEMPTS") - return 133; - if (name == "SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME") - return 134; - if (name == "ENABLE_HOST_AND_CHILD_NOTIFICATIONS") - return 135; - if (name == "DISABLE_HOST_AND_CHILD_NOTIFICATIONS") - return 136; - if (name == "SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME") - return 137; - if (name == "ENABLE_SERVICE_FRESHNESS_CHECKS") - return 138; - if (name == "DISABLE_SERVICE_FRESHNESS_CHECKS") - return 139; - if (name == "ENABLE_HOST_FRESHNESS_CHECKS") - return 140; - if (name == "DISABLE_HOST_FRESHNESS_CHECKS") - return 141; - if (name == "SET_HOST_NOTIFICATION_NUMBER") - return 142; - if (name == "SET_SVC_NOTIFICATION_NUMBER") - return 143; - if (name == "CHANGE_HOST_CHECK_TIMEPERIOD") - return 144; - if (name == "CHANGE_SVC_CHECK_TIMEPERIOD") - return 145; - if (name == "PROCESS_FILE") - return 146; - if (name == "CHANGE_CUSTOM_HOST_VAR") - return 147; - if (name == "CHANGE_CUSTOM_SVC_VAR") - return 148; - if (name == "CHANGE_CUSTOM_CONTACT_VAR") - return 149; - if (name == "ENABLE_CONTACT_HOST_NOTIFICATIONS") - return 150; - if (name == "DISABLE_CONTACT_HOST_NOTIFICATIONS") - return 151; - if (name == "ENABLE_CONTACT_SVC_NOTIFICATIONS") - return 152; - if (name == "DISABLE_CONTACT_SVC_NOTIFICATIONS") - return 153; - if (name == "ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS") - return 154; - if (name == "DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS") - return 155; - if (name == "ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS") - return 156; - if (name == "DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS") - return 157; - if (name == "CHANGE_RETRY_HOST_CHECK_INTERVAL") - return 158; - if (name == "SEND_CUSTOM_HOST_NOTIFICATION") - return 159; - if (name == "SEND_CUSTOM_SVC_NOTIFICATION") - return 160; - if (name == "CHANGE_HOST_NOTIFICATION_TIMEPERIOD") - return 161; - if (name == "CHANGE_SVC_NOTIFICATION_TIMEPERIOD") - return 162; - if (name == "CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD") - return 163; - if (name == "CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD") - return 164; - if (name == "CHANGE_HOST_MODATTR") - return 165; - if (name == "CHANGE_SVC_MODATTR") - return 166; - if (name == "CHANGE_CONTACT_MODATTR") - return 167; - if (name == "CHANGE_CONTACT_MODHATTR") - return 168; - if (name == "CHANGE_CONTACT_MODSATTR") - return 169; - if (name == "SYNC_STATE_INFORMATION") - return 170; - if (name == "DEL_DOWNTIME_BY_HOST_NAME") - return 171; - if (name == "DEL_DOWNTIME_BY_HOSTGROUP_NAME") - return 172; - if (name == "DEL_DOWNTIME_BY_START_TIME_COMMENT") - return 173; - if (name == "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE") - return 174; - if (name == "ACKNOWLEDGE_SVC_PROBLEM_EXPIRE") - return 175; - if (name == "DISABLE_NOTIFICATIONS_EXPIRE_TIME") - return 176; - if (name == "CUSTOM_COMMAND") - return 999; - - return 0; -} diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 5cfcbe7e3..388cdcb05 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -21,12 +21,8 @@ #define COMPATUTILITY_H #include "icinga/i2-icinga.hpp" -#include "icinga/customvarobject.hpp" #include "icinga/host.hpp" #include "icinga/command.hpp" -#include "base/dictionary.hpp" -#include "base/array.hpp" -#include <vector> namespace icinga { @@ -43,44 +39,8 @@ public: static String GetCommandLine(const Command::Ptr& command); static String GetCommandName(const Command::Ptr& command); - /* host */ - static int GetHostCurrentState(const Host::Ptr& host); - static String GetHostStateString(const Host::Ptr& host); - static String GetHostAlias(const Host::Ptr& host); - static int GetHostNotifyOnDown(const Host::Ptr& host); - static int GetHostNotifyOnUnreachable(const Host::Ptr& host); - /* service */ static String GetCheckableCommandArgs(const Checkable::Ptr& checkable); - static int GetCheckableCheckType(const Checkable::Ptr& checkable); - static double GetCheckableCheckInterval(const Checkable::Ptr& checkable); - static double GetCheckableRetryInterval(const Checkable::Ptr& checkable); - static String GetCheckableCheckPeriod(const Checkable::Ptr& checkable); - static int GetCheckableHasBeenChecked(const Checkable::Ptr& checkable); - static int GetCheckableProblemHasBeenAcknowledged(const Checkable::Ptr& checkable); - static int GetCheckableAcknowledgementType(const Checkable::Ptr& checkable); - static int GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable); - static int GetCheckableActiveChecksEnabled(const Checkable::Ptr& checkable); - static int GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable); - static int GetCheckableFlapDetectionEnabled(const Checkable::Ptr& checkable); - static int GetCheckableIsFlapping(const Checkable::Ptr& checkable); - static int GetCheckableIsReachable(const Checkable::Ptr& checkable); - static double GetCheckablePercentStateChange(const Checkable::Ptr& checkable); - static int GetCheckableProcessPerformanceData(const Checkable::Ptr& checkable); - - static String GetCheckableEventHandler(const Checkable::Ptr& checkable); - static String GetCheckableCheckCommand(const Checkable::Ptr& checkable); - - static int GetCheckableIsVolatile(const Checkable::Ptr& checkable); - static double GetCheckableLowFlapThreshold(const Checkable::Ptr& checkable); - static double GetCheckableHighFlapThreshold(const Checkable::Ptr& checkable); - static int GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable); - static int GetCheckableFreshnessThreshold(const Checkable::Ptr& checkable); - static double GetCheckableStaleness(const Checkable::Ptr& checkable); - static int GetCheckableIsAcknowledged(const Checkable::Ptr& checkable); - static int GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable); - static int GetCheckableInCheckPeriod(const Checkable::Ptr& checkable); - static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable); /* notification */ static int GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable); @@ -88,34 +48,17 @@ public: static int GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable); static int GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable); static double GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable); - static String GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable); static int GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable); static int GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable); - static int GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable); - static int GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable); - static int GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable); - static int GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable); - static int GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable); - static int GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable); static std::set<User::Ptr> GetCheckableNotificationUsers(const Checkable::Ptr& checkable); static std::set<UserGroup::Ptr> GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable); - /* custom attribute */ - static String GetCustomAttributeConfig(const CustomVarObject::Ptr& object, const String& name); - static Dictionary::Ptr GetCustomAttributeConfig(const CustomVarObject::Ptr& object); - /* check result */ static String GetCheckResultOutput(const CheckResult::Ptr& cr); static String GetCheckResultLongOutput(const CheckResult::Ptr& cr); - static String GetCheckResultPerfdata(const CheckResult::Ptr& cr); /* misc */ - static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time); - - static int MapNotificationReasonType(NotificationType type); - static int MapExternalCommandType(const String& name); - static String EscapeString(const String& str); static String UnEscapeString(const String& str); diff --git a/lib/livestatus/commandstable.cpp b/lib/livestatus/commandstable.cpp index 6526486b1..ae5145fc1 100644 --- a/lib/livestatus/commandstable.cpp +++ b/lib/livestatus/commandstable.cpp @@ -99,12 +99,7 @@ Value CommandsTable::CustomVariableNamesAccessor(const Value& row) if (!command) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(command); - vars = CompatUtility::GetCustomAttributeConfig(command); - } + Dictionary::Ptr vars = command->GetVars(); Array::Ptr cv = new Array(); @@ -128,12 +123,7 @@ Value CommandsTable::CustomVariableValuesAccessor(const Value& row) if (!command) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(command); - vars = CompatUtility::GetCustomAttributeConfig(command); - } + Dictionary::Ptr vars = command->GetVars(); Array::Ptr cv = new Array(); @@ -157,12 +147,7 @@ Value CommandsTable::CustomVariablesAccessor(const Value& row) if (!command) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(command); - vars = CompatUtility::GetCustomAttributeConfig(command); - } + Dictionary::Ptr vars = command->GetVars(); Array::Ptr cv = new Array(); diff --git a/lib/livestatus/contactstable.cpp b/lib/livestatus/contactstable.cpp index fe725bc3c..aeca4b04d 100644 --- a/lib/livestatus/contactstable.cpp +++ b/lib/livestatus/contactstable.cpp @@ -203,12 +203,7 @@ Value ContactsTable::CustomVariableNamesAccessor(const Value& row) if (!user) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(user); - vars = CompatUtility::GetCustomAttributeConfig(user); - } + Dictionary::Ptr vars = user->GetVars(); Array::Ptr cv = new Array(); @@ -230,12 +225,7 @@ Value ContactsTable::CustomVariableValuesAccessor(const Value& row) if (!user) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(user); - vars = CompatUtility::GetCustomAttributeConfig(user); - } + Dictionary::Ptr vars = user->GetVars(); Array::Ptr cv = new Array(); @@ -260,12 +250,7 @@ Value ContactsTable::CustomVariablesAccessor(const Value& row) if (!user) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(user); - vars = CompatUtility::GetCustomAttributeConfig(user); - } + Dictionary::Ptr vars = user->GetVars(); Array::Ptr cv = new Array(); @@ -295,12 +280,7 @@ Value ContactsTable::CVIsJsonAccessor(const Value& row) if (!user) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(user); - vars = CompatUtility::GetCustomAttributeConfig(user); - } + Dictionary::Ptr vars = user->GetVars(); if (!vars) return Empty; diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index a3c99d123..795f31b8e 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -29,6 +29,7 @@ #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "base/configtype.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" @@ -76,7 +77,7 @@ void HostsTable::AddColumns(Table *table, const String& prefix, 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(&Table::OneAccessor, objectAccessor)); - table->AddColumn(prefix + "process_performance_data", Column(&Table::ZeroAccessor, 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)); @@ -108,7 +109,7 @@ void HostsTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "scheduled_downtime_depth", Column(&HostsTable::ScheduledDowntimeDepthAccessor, objectAccessor)); table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "active_checks_enabled", Column(&HostsTable::ActiveChecksEnabledAccessor, objectAccessor)); - table->AddColumn(prefix + "check_options", Column(&HostsTable::CheckOptionsAccessor, objectAccessor)); + table->AddColumn(prefix + "check_options", Column(&Table::EmptyStringAccessor, objectAccessor)); table->AddColumn(prefix + "obsess_over_host", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes_list", Column(&Table::ZeroAccessor, objectAccessor)); @@ -303,7 +304,12 @@ Value HostsTable::CheckPeriodAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableCheckPeriod(host); + TimePeriod::Ptr checkPeriod = host->GetCheckPeriod(); + + if (!checkPeriod) + return Empty; + + return checkPeriod->GetName(); } Value HostsTable::NotesAccessor(const Value& row) @@ -407,10 +413,10 @@ Value HostsTable::PerfDataAccessor(const Value& row) String perfdata; CheckResult::Ptr cr = host->GetLastCheckResult(); - if (cr) - perfdata = CompatUtility::GetCheckResultPerfdata(cr); + if (!cr) + return Empty; - return perfdata; + return PluginUtility::FormatPerfdata(cr->GetPerformanceData()); } Value HostsTable::IconImageAccessor(const Value& row) @@ -481,7 +487,7 @@ Value HostsTable::FlapDetectionEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableFlapDetectionEnabled(host); + return Convert::ToLong(host->GetEnableFlapping()); } Value HostsTable::AcceptPassiveChecksAccessor(const Value& row) @@ -491,7 +497,7 @@ Value HostsTable::AcceptPassiveChecksAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckablePassiveChecksEnabled(host); + return Convert::ToLong(host->GetEnablePassiveChecks()); } Value HostsTable::EventHandlerEnabledAccessor(const Value& row) @@ -501,7 +507,7 @@ Value HostsTable::EventHandlerEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableEventHandlerEnabled(host); + return Convert::ToLong(host->GetEnableEventHandler()); } Value HostsTable::AcknowledgementTypeAccessor(const Value& row) @@ -512,7 +518,7 @@ Value HostsTable::AcknowledgementTypeAccessor(const Value& row) return Empty; ObjectLock olock(host); - return CompatUtility::GetCheckableAcknowledgementType(host); + return host->GetAcknowledgement(); } Value HostsTable::CheckTypeAccessor(const Value& row) @@ -522,7 +528,7 @@ Value HostsTable::CheckTypeAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableCheckType(host); + return (host->GetEnableActiveChecks() ? 0 : 1); /* 0 .. active, 1 .. passive */ } Value HostsTable::LastStateAccessor(const Value& row) @@ -602,7 +608,7 @@ Value HostsTable::HasBeenCheckedAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableHasBeenChecked(host); + return Convert::ToLong(host->HasBeenChecked()); } Value HostsTable::CurrentNotificationNumberAccessor(const Value& row) @@ -632,7 +638,7 @@ Value HostsTable::ChecksEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableActiveChecksEnabled(host); + return Convert::ToLong(host->GetEnableActiveChecks()); } Value HostsTable::NotificationsEnabledAccessor(const Value& row) @@ -642,7 +648,17 @@ Value HostsTable::NotificationsEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableNotificationsEnabled(host); + return Convert::ToLong(host->GetEnableNotifications()); +} + +Value HostsTable::ProcessPerformanceDataAccessor(const Value& row) +{ + Host::Ptr host = static_cast<Host::Ptr>(row); + + if (!host) + return Empty; + + return Convert::ToLong(host->GetEnablePerfdata()); } Value HostsTable::AcknowledgedAccessor(const Value& row) @@ -653,7 +669,7 @@ Value HostsTable::AcknowledgedAccessor(const Value& row) return Empty; ObjectLock olock(host); - return CompatUtility::GetCheckableIsAcknowledged(host); + return host->IsAcknowledged(); } Value HostsTable::StateAccessor(const Value& row) @@ -683,7 +699,7 @@ Value HostsTable::NoMoreNotificationsAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableNoMoreNotifications(host); + return (CompatUtility::GetCheckableNotificationNotificationInterval(host) == 0 && !host->GetVolatile()) ? 1 : 0; } Value HostsTable::LastCheckAccessor(const Value& row) @@ -763,13 +779,7 @@ Value HostsTable::ActiveChecksEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableActiveChecksEnabled(host); -} - -Value HostsTable::CheckOptionsAccessor(const Value&) -{ - /* TODO - forcexec, freshness, orphan, none */ - return Empty; + return Convert::ToLong(host->GetEnableActiveChecks()); } Value HostsTable::CheckIntervalAccessor(const Value& row) @@ -779,7 +789,7 @@ Value HostsTable::CheckIntervalAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableCheckInterval(host); + return host->GetCheckInterval() / 60.0; } Value HostsTable::RetryIntervalAccessor(const Value& row) @@ -789,7 +799,7 @@ Value HostsTable::RetryIntervalAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableRetryInterval(host); + return host->GetRetryInterval() / 60.0; } Value HostsTable::NotificationIntervalAccessor(const Value& row) @@ -809,7 +819,7 @@ Value HostsTable::LowFlapThresholdAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableLowFlapThreshold(host); + return host->GetFlappingThresholdLow(); } Value HostsTable::HighFlapThresholdAccessor(const Value& row) @@ -819,7 +829,7 @@ Value HostsTable::HighFlapThresholdAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableHighFlapThreshold(host); + return host->GetFlappingThresholdHigh(); } Value HostsTable::LatencyAccessor(const Value& row) @@ -859,7 +869,7 @@ Value HostsTable::PercentStateChangeAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckablePercentStateChange(host); + return host->GetFlappingCurrent(); } Value HostsTable::InNotificationPeriodAccessor(const Value& row) @@ -869,7 +879,14 @@ Value HostsTable::InNotificationPeriodAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableInNotificationPeriod(host); + for (const Notification::Ptr& notification : host->GetNotifications()) { + TimePeriod::Ptr timeperiod = notification->GetPeriod(); + + if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) + return 1; + } + + return 0; } Value HostsTable::InCheckPeriodAccessor(const Value& row) @@ -879,7 +896,13 @@ Value HostsTable::InCheckPeriodAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableInCheckPeriod(host); + TimePeriod::Ptr timeperiod = host->GetCheckPeriod(); + + /* none set means always checked */ + if (!timeperiod) + return 1; + + return Convert::ToLong(timeperiod->IsInside(Utility::GetTime())); } Value HostsTable::ContactsAccessor(const Value& row) @@ -1013,12 +1036,7 @@ Value HostsTable::CustomVariableNamesAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(host); - vars = CompatUtility::GetCustomAttributeConfig(host); - } + Dictionary::Ptr vars = host->GetVars(); Array::Ptr cv = new Array(); @@ -1040,12 +1058,7 @@ Value HostsTable::CustomVariableValuesAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(host); - vars = CompatUtility::GetCustomAttributeConfig(host); - } + Dictionary::Ptr vars = host->GetVars(); Array::Ptr cv = new Array(); @@ -1070,12 +1083,7 @@ Value HostsTable::CustomVariablesAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(host); - vars = CompatUtility::GetCustomAttributeConfig(host); - } + Dictionary::Ptr vars = host->GetVars(); Array::Ptr cv = new Array(); @@ -1105,12 +1113,7 @@ Value HostsTable::CVIsJsonAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(host); - vars = CompatUtility::GetCustomAttributeConfig(host); - } + Dictionary::Ptr vars = host->GetVars(); if (!vars) return Empty; @@ -1390,7 +1393,10 @@ Value HostsTable::StalenessAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableStaleness(host); + if (host->HasBeenChecked() && host->GetLastCheck() > 0) + return (Utility::GetTime() - host->GetLastCheck()) / (host->GetCheckInterval() * 3600); + + return 0.0; } Value HostsTable::GroupsAccessor(const Value& row) diff --git a/lib/livestatus/hoststable.hpp b/lib/livestatus/hoststable.hpp index c6e34bb3b..9a08bec0c 100644 --- a/lib/livestatus/hoststable.hpp +++ b/lib/livestatus/hoststable.hpp @@ -99,7 +99,6 @@ protected: static Value IsFlappingAccessor(const Value& row); static Value ScheduledDowntimeDepthAccessor(const Value& row); static Value ActiveChecksEnabledAccessor(const Value& row); - static Value CheckOptionsAccessor(const Value& row); static Value CheckIntervalAccessor(const Value& row); static Value RetryIntervalAccessor(const Value& row); static Value NotificationIntervalAccessor(const Value& row); diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 6c15efe4d..3abffb423 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -31,6 +31,7 @@ #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "base/configtype.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" @@ -103,9 +104,9 @@ void ServicesTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor)); table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor)); - table->AddColumn(prefix + "check_options", Column(&ServicesTable::CheckOptionsAccessor, objectAccessor)); + table->AddColumn(prefix + "check_options", Column(&Table::EmptyStringAccessor, objectAccessor)); table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor)); - table->AddColumn(prefix + "check_freshness", Column(&ServicesTable::CheckFreshnessAccessor, objectAccessor)); + table->AddColumn(prefix + "check_freshness", Column(&Table::OneAccessor, objectAccessor)); table->AddColumn(prefix + "obsess_over_service", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes_list", Column(&Table::ZeroAccessor, objectAccessor)); @@ -342,10 +343,10 @@ Value ServicesTable::PerfDataAccessor(const Value& row) String perfdata; CheckResult::Ptr cr = service->GetLastCheckResult(); - if (cr) - perfdata = CompatUtility::GetCheckResultPerfdata(cr); + if (!cr) + return Empty; - return perfdata; + return PluginUtility::FormatPerfdata(cr->GetPerformanceData()); } Value ServicesTable::CheckPeriodAccessor(const Value& row) @@ -355,7 +356,12 @@ Value ServicesTable::CheckPeriodAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableCheckPeriod(service); + TimePeriod::Ptr checkPeriod = service->GetCheckPeriod(); + + if (!checkPeriod) + return Empty; + + return checkPeriod->GetName(); } Value ServicesTable::NotesAccessor(const Value& row) @@ -509,7 +515,7 @@ Value ServicesTable::HasBeenCheckedAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableHasBeenChecked(service); + return Convert::ToLong(service->HasBeenChecked()); } Value ServicesTable::LastStateAccessor(const Value& row) @@ -549,7 +555,7 @@ Value ServicesTable::CheckTypeAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableCheckType(service); + return (service->GetEnableActiveChecks() ? 0 : 1); /* 0 .. active, 1 .. passive */ } Value ServicesTable::AcknowledgedAccessor(const Value& row) @@ -560,7 +566,7 @@ Value ServicesTable::AcknowledgedAccessor(const Value& row) return Empty; ObjectLock olock(service); - return CompatUtility::GetCheckableIsAcknowledged(service); + return service->IsAcknowledged(); } Value ServicesTable::AcknowledgementTypeAccessor(const Value& row) @@ -571,7 +577,7 @@ Value ServicesTable::AcknowledgementTypeAccessor(const Value& row) return Empty; ObjectLock olock(service); - return CompatUtility::GetCheckableAcknowledgementType(service); + return service->GetAcknowledgement(); } Value ServicesTable::NoMoreNotificationsAccessor(const Value& row) @@ -581,7 +587,7 @@ Value ServicesTable::NoMoreNotificationsAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableNoMoreNotifications(service); + return (CompatUtility::GetCheckableNotificationNotificationInterval(service) == 0 && !service->GetVolatile()) ? 1 : 0; } Value ServicesTable::LastTimeOkAccessor(const Value& row) @@ -721,7 +727,7 @@ Value ServicesTable::ChecksEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableActiveChecksEnabled(service); + return Convert::ToLong(service->GetEnableActiveChecks()); } Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row) @@ -731,7 +737,7 @@ Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckablePassiveChecksEnabled(service); + return Convert::ToLong(service->GetEnablePassiveChecks()); } Value ServicesTable::EventHandlerEnabledAccessor(const Value& row) @@ -741,7 +747,7 @@ Value ServicesTable::EventHandlerEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableEventHandlerEnabled(service); + return Convert::ToLong(service->GetEnableEventHandler()); } Value ServicesTable::NotificationsEnabledAccessor(const Value& row) @@ -751,7 +757,7 @@ Value ServicesTable::NotificationsEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableNotificationsEnabled(service); + return Convert::ToLong(service->GetEnableNotifications()); } Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row) @@ -761,7 +767,7 @@ Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableProcessPerformanceData(service); + return Convert::ToLong(service->GetEnablePerfdata()); } Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row) @@ -771,13 +777,7 @@ Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableActiveChecksEnabled(service); -} - -Value ServicesTable::CheckOptionsAccessor(const Value& row) -{ - /* TODO - forcexec, freshness, orphan, none */ - return Empty; + return Convert::ToLong(service->GetEnableActiveChecks()); } Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row) @@ -787,17 +787,7 @@ Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableFlapDetectionEnabled(service); -} - -Value ServicesTable::CheckFreshnessAccessor(const Value& row) -{ - Service::Ptr service = static_cast<Service::Ptr>(row); - - if (!service) - return Empty; - - return CompatUtility::GetCheckableFreshnessChecksEnabled(service); + return Convert::ToLong(service->GetEnableFlapping()); } Value ServicesTable::StalenessAccessor(const Value& row) @@ -807,7 +797,10 @@ Value ServicesTable::StalenessAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableStaleness(service); + if (service->HasBeenChecked() && service->GetLastCheck() > 0) + return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600); + + return 0.0; } Value ServicesTable::CheckIntervalAccessor(const Value& row) @@ -817,7 +810,7 @@ Value ServicesTable::CheckIntervalAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableCheckInterval(service); + return service->GetCheckInterval() / 60.0; } Value ServicesTable::RetryIntervalAccessor(const Value& row) @@ -827,7 +820,7 @@ Value ServicesTable::RetryIntervalAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableRetryInterval(service); + return service->GetRetryInterval() / 60.0; } Value ServicesTable::NotificationIntervalAccessor(const Value& row) @@ -847,7 +840,7 @@ Value ServicesTable::LowFlapThresholdAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableLowFlapThreshold(service); + return service->GetFlappingThresholdLow(); } Value ServicesTable::HighFlapThresholdAccessor(const Value& row) @@ -857,7 +850,7 @@ Value ServicesTable::HighFlapThresholdAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableHighFlapThreshold(service); + return service->GetFlappingThresholdHigh(); } Value ServicesTable::LatencyAccessor(const Value& row) @@ -897,7 +890,7 @@ Value ServicesTable::PercentStateChangeAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckablePercentStateChange(service); + return service->GetFlappingCurrent(); } Value ServicesTable::InCheckPeriodAccessor(const Value& row) @@ -907,7 +900,13 @@ Value ServicesTable::InCheckPeriodAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableInCheckPeriod(service); + TimePeriod::Ptr timeperiod = service->GetCheckPeriod(); + + /* none set means always checked */ + if (!timeperiod) + return 1; + + return Convert::ToLong(timeperiod->IsInside(Utility::GetTime())); } Value ServicesTable::InNotificationPeriodAccessor(const Value& row) @@ -917,7 +916,14 @@ Value ServicesTable::InNotificationPeriodAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableInNotificationPeriod(service); + for (const Notification::Ptr& notification : service->GetNotifications()) { + TimePeriod::Ptr timeperiod = notification->GetPeriod(); + + if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) + return 1; + } + + return 0; } Value ServicesTable::ContactsAccessor(const Value& row) @@ -1052,12 +1058,7 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row) if (!service) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(service); - vars = CompatUtility::GetCustomAttributeConfig(service); - } + Dictionary::Ptr vars = service->GetVars(); Array::Ptr cv = new Array(); @@ -1079,12 +1080,7 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row) if (!service) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(service); - vars = CompatUtility::GetCustomAttributeConfig(service); - } + Dictionary::Ptr vars = service->GetVars(); Array::Ptr cv = new Array(); @@ -1109,12 +1105,7 @@ Value ServicesTable::CustomVariablesAccessor(const Value& row) if (!service) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(service); - vars = CompatUtility::GetCustomAttributeConfig(service); - } + Dictionary::Ptr vars = service->GetVars(); Array::Ptr cv = new Array(); @@ -1144,12 +1135,7 @@ Value ServicesTable::CVIsJsonAccessor(const Value& row) if (!service) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(service); - vars = CompatUtility::GetCustomAttributeConfig(service); - } + Dictionary::Ptr vars = service->GetVars(); if (!vars) return Empty; diff --git a/lib/livestatus/servicestable.hpp b/lib/livestatus/servicestable.hpp index 665557236..17ff49a3a 100644 --- a/lib/livestatus/servicestable.hpp +++ b/lib/livestatus/servicestable.hpp @@ -98,9 +98,7 @@ protected: static Value NotificationsEnabledAccessor(const Value& row); static Value ProcessPerformanceDataAccessor(const Value& row); static Value ActiveChecksEnabledAccessor(const Value& row); - static Value CheckOptionsAccessor(const Value& row); static Value FlapDetectionEnabledAccessor(const Value& row); - static Value CheckFreshnessAccessor(const Value& row); static Value StalenessAccessor(const Value& row); static Value CheckIntervalAccessor(const Value& row); static Value RetryIntervalAccessor(const Value& row); diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index 6742a11da..0394befa1 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -325,8 +325,7 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti fields->Set("short_message", output); } else { fields->Set("_type", "HOST NOTIFICATION"); - //TODO: why? - fields->Set("short_message", "(" + CompatUtility::GetHostStateString(host) + ")"); + fields->Set("short_message", output); } fields->Set("_state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));