From 112f26dc19dbab452b62fab73a000f752d3e7b05 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 9 Nov 2013 14:22:38 +0100 Subject: [PATCH] Replace check result dictionaries with a class. Refs #5039 --- components/cluster/clusterlistener.cpp | 4 +- components/cluster/clusterlistener.h | 2 +- components/compat/checkresultreader.cpp | 9 +- components/compat/compatlogger.cpp | 14 +- components/compat/compatlogger.h | 12 +- components/livestatus/hoststable.cpp | 30 ++-- components/livestatus/servicestable.cpp | 28 +--- .../notification/notificationcomponent.cpp | 2 +- .../notification/notificationcomponent.h | 2 +- components/perfdata/graphitewriter.cpp | 4 +- components/perfdata/graphitewriter.h | 8 +- components/perfdata/perfdatawriter.cpp | 2 +- components/perfdata/perfdatawriter.h | 2 +- lib/db_ido/servicedbobject.cpp | 91 +++++------ lib/db_ido/servicedbobject.h | 10 +- lib/icinga/CMakeLists.txt | 11 +- lib/icinga/checkcommand.cpp | 2 +- lib/icinga/checkcommand.h | 2 +- lib/icinga/checkresult.cpp | 25 +++ lib/icinga/checkresult.h | 42 ++++++ lib/icinga/checkresult.ti | 54 +++++++ lib/icinga/command.cpp | 2 +- lib/icinga/command.h | 2 +- lib/icinga/compatutility.cpp | 14 +- lib/icinga/compatutility.h | 4 +- lib/icinga/externalcommandprocessor.cpp | 28 ++-- lib/icinga/host.cpp | 10 +- lib/icinga/host.h | 3 +- lib/icinga/host.ti | 26 ---- lib/icinga/icingaapplication.cpp | 2 +- lib/icinga/icingaapplication.h | 2 +- lib/icinga/macroprocessor.cpp | 6 +- lib/icinga/macroprocessor.h | 6 +- lib/icinga/macroresolver.cpp | 2 +- lib/icinga/macroresolver.h | 5 +- lib/icinga/notification.cpp | 6 +- lib/icinga/notification.h | 6 +- lib/icinga/notificationcommand.cpp | 2 +- lib/icinga/notificationcommand.h | 2 +- lib/icinga/pluginutility.cpp | 8 +- lib/icinga/pluginutility.h | 2 +- lib/icinga/service-check.cpp | 142 ++++++++---------- lib/icinga/service-notification.cpp | 6 +- lib/icinga/service.cpp | 8 +- lib/icinga/service.h | 22 +-- lib/icinga/service.ti | 2 +- lib/icinga/user.cpp | 2 +- lib/icinga/user.h | 2 +- lib/methods/nullchecktask.cpp | 10 +- lib/methods/nullchecktask.h | 2 +- lib/methods/pluginchecktask.cpp | 14 +- lib/methods/pluginchecktask.h | 2 +- lib/methods/pluginnotificationtask.cpp | 2 +- lib/methods/pluginnotificationtask.h | 2 +- lib/methods/randomchecktask.cpp | 10 +- lib/methods/randomchecktask.h | 2 +- 56 files changed, 387 insertions(+), 335 deletions(-) create mode 100644 lib/icinga/checkresult.cpp create mode 100644 lib/icinga/checkresult.h create mode 100644 lib/icinga/checkresult.ti diff --git a/components/cluster/clusterlistener.cpp b/components/cluster/clusterlistener.cpp index f064c2bcb..517227578 100644 --- a/components/cluster/clusterlistener.cpp +++ b/components/cluster/clusterlistener.cpp @@ -660,7 +660,7 @@ void ClusterListener::SetSecurityInfo(const Dictionary::Ptr& message, const Dyna message->Set("security", security); } -void ClusterListener::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr, const String& authority) +void ClusterListener::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr, const String& authority) { if (!authority.IsEmpty() && authority != GetIdentity()) return; @@ -1012,7 +1012,7 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona return; } - Dictionary::Ptr cr = params->Get("check_result"); + CheckResult::Ptr cr = params->Get("check_result"); if (!cr) return; diff --git a/components/cluster/clusterlistener.h b/components/cluster/clusterlistener.h index ea6fc6289..74650c621 100644 --- a/components/cluster/clusterlistener.h +++ b/components/cluster/clusterlistener.h @@ -83,7 +83,7 @@ private: Stream::Ptr m_LogFile; size_t m_LogMessageCount; - void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr, const String& authority); + void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr, const String& authority); void NextCheckChangedHandler(const Service::Ptr& service, double nextCheck, const String& authority); void NextNotificationChangedHandler(const Notification::Ptr& notification, double nextCheck, const String& authority); void ForceNextCheckChangedHandler(const Service::Ptr& service, bool forced, const String& authority); diff --git a/components/compat/checkresultreader.cpp b/components/compat/checkresultreader.cpp index 1059314ef..8071c679e 100644 --- a/components/compat/checkresultreader.cpp +++ b/components/compat/checkresultreader.cpp @@ -101,11 +101,10 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const return; } - Dictionary::Ptr result = PluginUtility::ParseCheckOutput(attrs["output"]); - result->Set("state", PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"]))); - result->Set("execution_start", Convert::ToDouble(attrs["start_time"])); - result->Set("execution_end", Convert::ToDouble(attrs["finish_time"])); - result->Set("active", 1); + CheckResult::Ptr result = PluginUtility::ParseCheckOutput(attrs["output"]); + result->SetState(PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"]))); + result->SetExecutionStart(Convert::ToDouble(attrs["start_time"])); + result->SetExecutionEnd(Convert::ToDouble(attrs["finish_time"])); service->ProcessCheckResult(result); diff --git a/components/compat/compatlogger.cpp b/components/compat/compatlogger.cpp index 2574a75fc..a019209b0 100644 --- a/components/compat/compatlogger.cpp +++ b/components/compat/compatlogger.cpp @@ -72,14 +72,14 @@ void CompatLogger::Start(void) /** * @threadsafety Always. */ -void CompatLogger::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr &cr) +void CompatLogger::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr &cr) { Host::Ptr host = service->GetHost(); if (!host) return; - Dictionary::Ptr vars_after = cr->Get("vars_after"); + Dictionary::Ptr vars_after = cr->GetVarsAfter(); long state_after = vars_after->Get("state"); long stateType_after = vars_after->Get("state_type"); @@ -87,7 +87,7 @@ void CompatLogger::CheckResultHandler(const Service::Ptr& service, const Diction bool reachable_after = vars_after->Get("reachable"); bool host_reachable_after = vars_after->Get("host_reachable"); - Dictionary::Ptr vars_before = cr->Get("vars_before"); + Dictionary::Ptr vars_before = cr->GetVarsBefore(); if (vars_before) { long state_before = vars_before->Get("state"); @@ -251,8 +251,8 @@ void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Dict * @threadsafety Always. */ void CompatLogger::NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, - NotificationType const& notification_type, Dictionary::Ptr const& cr, - const String& author, const String& comment_text, const String& command_name) + NotificationType const& notification_type, CheckResult::Ptr const& cr, + const String& author, const String& comment_text, const String& command_name) { Host::Ptr host = service->GetHost(); @@ -505,7 +505,7 @@ void CompatLogger::ReopenFile(bool rotate) ObjectLock olock(hc); String output; - Dictionary::Ptr cr = hc->GetLastCheckResult(); + CheckResult::Ptr cr = hc->GetLastCheckResult(); if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); @@ -530,7 +530,7 @@ void CompatLogger::ReopenFile(bool rotate) continue; String output; - Dictionary::Ptr cr = service->GetLastCheckResult(); + CheckResult::Ptr cr = service->GetLastCheckResult(); if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); diff --git a/components/compat/compatlogger.h b/components/compat/compatlogger.h index 9c280994a..a3f652276 100644 --- a/components/compat/compatlogger.h +++ b/components/compat/compatlogger.h @@ -52,14 +52,14 @@ private: void WriteLine(const String& line); void Flush(void); - void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr); + void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr); void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state); - void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text, const String& command_name); + void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, CheckResult::Ptr const& cr, const String& author, const String& comment_text, const String& command_name); void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state); - void TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime); - void RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime); - void ExternalCommandHandler(const String& command, const std::vector& arguments); - void EventCommandHandler(const Service::Ptr& service); + void TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime); + void RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime); + void ExternalCommandHandler(const String& command, const std::vector& arguments); + void EventCommandHandler(const Service::Ptr& service); Timer::Ptr m_RotationTimer; void RotationTimerHandler(void); diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 72663ee93..efa9f88fb 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -269,7 +269,7 @@ Value HostsTable::CheckCommandExpandedAccessor(const Value& row) resolvers.push_back(commandObj); resolvers.push_back(IcingaApplication::GetInstance()); - Value commandLine = MacroProcessor::ResolveMacros(raw_command, resolvers, Dictionary::Ptr(), Utility::EscapeShellCmd); + Value commandLine = MacroProcessor::ResolveMacros(raw_command, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); String buf; if (commandLine.IsObjectType()) { @@ -403,10 +403,7 @@ Value HostsTable::NotesExpandedAccessor(const Value& row) Value value = custom->Get("notes"); - Dictionary::Ptr cr; - Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd); - - return value_expanded; + return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); } Value HostsTable::NotesUrlAccessor(const Value& row) @@ -451,10 +448,7 @@ Value HostsTable::NotesUrlExpandedAccessor(const Value& row) Value value = custom->Get("notes_url"); - Dictionary::Ptr cr; - Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd); - - return value_expanded; + return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); } Value HostsTable::ActionUrlAccessor(const Value& row) @@ -499,10 +493,7 @@ Value HostsTable::ActionUrlExpandedAccessor(const Value& row) Value value = custom->Get("action_url"); - Dictionary::Ptr cr; - Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd); - - return value_expanded; + return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); } Value HostsTable::PluginOutputAccessor(const Value& row) @@ -518,7 +509,7 @@ Value HostsTable::PluginOutputAccessor(const Value& row) if(hc) { String output; - Dictionary::Ptr cr = hc->GetLastCheckResult(); + CheckResult::Ptr cr = hc->GetLastCheckResult(); if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); @@ -541,7 +532,7 @@ Value HostsTable::PerfDataAccessor(const Value& row) String perfdata; if (hc) { - Dictionary::Ptr cr = hc->GetLastCheckResult(); + CheckResult::Ptr cr = hc->GetLastCheckResult(); if (cr) perfdata = CompatUtility::GetCheckResultPerfdata(cr); @@ -593,10 +584,7 @@ Value HostsTable::IconImageExpandedAccessor(const Value& row) Value value = custom->Get("icon_image"); - Dictionary::Ptr cr; - Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd); - - return value_expanded; + return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); } Value HostsTable::IconImageAltAccessor(const Value& row) @@ -642,7 +630,7 @@ Value HostsTable::LongPluginOutputAccessor(const Value& row) if (hc) { String long_output; - Dictionary::Ptr cr = hc->GetLastCheckResult(); + CheckResult::Ptr cr = hc->GetLastCheckResult(); if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); @@ -2050,7 +2038,7 @@ Value HostsTable::ServicesWithInfoAccessor(const Value& row) svc_add->Add(service->HasBeenChecked() ? 1 : 0); String output; - Dictionary::Ptr cr = service->GetLastCheckResult(); + CheckResult::Ptr cr = service->GetLastCheckResult(); if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index 94a340f4c..f15e7bb88 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -214,7 +214,7 @@ Value ServicesTable::CheckCommandExpandedAccessor(const Value& row) resolvers.push_back(commandObj); resolvers.push_back(IcingaApplication::GetInstance()); - Value commandLine = MacroProcessor::ResolveMacros(raw_command, resolvers, Dictionary::Ptr(), Utility::EscapeShellCmd); + Value commandLine = MacroProcessor::ResolveMacros(raw_command, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); String buf; if (commandLine.IsObjectType()) { @@ -262,7 +262,7 @@ Value ServicesTable::PluginOutputAccessor(const Value& row) return Empty; String output; - Dictionary::Ptr cr = service->GetLastCheckResult(); + CheckResult::Ptr cr = service->GetLastCheckResult(); if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); @@ -280,7 +280,7 @@ Value ServicesTable::LongPluginOutputAccessor(const Value& row) return Empty; String long_output; - Dictionary::Ptr cr = service->GetLastCheckResult(); + CheckResult::Ptr cr = service->GetLastCheckResult(); if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); @@ -298,7 +298,7 @@ Value ServicesTable::PerfDataAccessor(const Value& row) return Empty; String perfdata; - Dictionary::Ptr cr = service->GetLastCheckResult(); + CheckResult::Ptr cr = service->GetLastCheckResult(); if (cr) perfdata = CompatUtility::GetCheckResultPerfdata(cr); @@ -375,10 +375,7 @@ Value ServicesTable::NotesExpandedAccessor(const Value& row) Value value = custom->Get("notes"); - Dictionary::Ptr cr; - Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd); - - return value_expanded; + return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); } Value ServicesTable::NotesUrlAccessor(const Value& row) @@ -415,10 +412,7 @@ Value ServicesTable::NotesUrlExpandedAccessor(const Value& row) Value value = custom->Get("notes_url"); - Dictionary::Ptr cr; - Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd); - - return value_expanded; + return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); } Value ServicesTable::ActionUrlAccessor(const Value& row) @@ -455,10 +449,7 @@ Value ServicesTable::ActionUrlExpandedAccessor(const Value& row) Value value = custom->Get("action_url"); - Dictionary::Ptr cr; - Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd); - - return value_expanded; + return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); } Value ServicesTable::IconImageAccessor(const Value& row) @@ -495,10 +486,7 @@ Value ServicesTable::IconImageExpandedAccessor(const Value& row) Value value = custom->Get("icon_image"); - Dictionary::Ptr cr; - Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd); - - return value_expanded; + return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd); } Value ServicesTable::IconImageAltAccessor(const Value& row) diff --git a/components/notification/notificationcomponent.cpp b/components/notification/notificationcomponent.cpp index b3d3d108f..9d712f34a 100644 --- a/components/notification/notificationcomponent.cpp +++ b/components/notification/notificationcomponent.cpp @@ -105,7 +105,7 @@ void NotificationComponent::NotificationTimerHandler(void) * Processes icinga::SendNotifications messages. */ void NotificationComponent::SendNotificationsHandler(const Service::Ptr& service, NotificationType type, - const Dictionary::Ptr& cr, const String& author, const String& text) + const CheckResult::Ptr& cr, const String& author, const String& text) { service->SendNotifications(static_cast(type), cr, author, text); } diff --git a/components/notification/notificationcomponent.h b/components/notification/notificationcomponent.h index c2217da85..f85dfd803 100644 --- a/components/notification/notificationcomponent.h +++ b/components/notification/notificationcomponent.h @@ -43,7 +43,7 @@ private: void NotificationTimerHandler(void); void SendNotificationsHandler(const Service::Ptr& service, NotificationType type, - const Dictionary::Ptr& cr, const String& author, const String& text); + const CheckResult::Ptr& cr, const String& author, const String& text); }; } diff --git a/components/perfdata/graphitewriter.cpp b/components/perfdata/graphitewriter.cpp index c82c70382..bf53a68d3 100644 --- a/components/perfdata/graphitewriter.cpp +++ b/components/perfdata/graphitewriter.cpp @@ -78,7 +78,7 @@ void GraphiteWriter::ReconnectTimerHandler(void) m_Stream = make_shared(net_stream); } -void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr) +void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr) { if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata()) return; @@ -100,7 +100,7 @@ void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const Dicti SendMetric(prefix, "latency", Service::CalculateLatency(cr)); SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr)); - Value pdv = cr->Get("performance_data"); + Value pdv = cr->GetPerformanceData(); if (!pdv.IsObjectType()) return; diff --git a/components/perfdata/graphitewriter.h b/components/perfdata/graphitewriter.h index 697ce393d..09b3ff079 100644 --- a/components/perfdata/graphitewriter.h +++ b/components/perfdata/graphitewriter.h @@ -45,15 +45,15 @@ protected: virtual void Start(void); private: - Stream::Ptr m_Stream; + Stream::Ptr m_Stream; - Timer::Ptr m_ReconnectTimer; + Timer::Ptr m_ReconnectTimer; - void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr); + void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr); void SendMetric(const String& prefix, const String& name, double value); static void SanitizeMetric(String& str); - void ReconnectTimerHandler(void); + void ReconnectTimerHandler(void); }; } diff --git a/components/perfdata/perfdatawriter.cpp b/components/perfdata/perfdatawriter.cpp index 4a88cd71c..ea7323e0d 100644 --- a/components/perfdata/perfdatawriter.cpp +++ b/components/perfdata/perfdatawriter.cpp @@ -46,7 +46,7 @@ void PerfdataWriter::Start(void) RotateFile(); } -void PerfdataWriter::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr) +void PerfdataWriter::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr) { if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata()) return; diff --git a/components/perfdata/perfdatawriter.h b/components/perfdata/perfdatawriter.h index 00246c06b..cf4dd2d8e 100644 --- a/components/perfdata/perfdatawriter.h +++ b/components/perfdata/perfdatawriter.h @@ -44,7 +44,7 @@ protected: virtual void Start(void); private: - void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr); + void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr); Timer::Ptr m_RotationTimer; void RotationTimerHandler(void); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 24611b8e9..c4ab1f64a 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -856,7 +856,7 @@ void ServiceDbObject::AddContactNotificationHistory(const Service::Ptr& service, } void ServiceDbObject::AddNotificationHistory(const Service::Ptr& service, const std::set& users, NotificationType type, - const Dictionary::Ptr& cr, const String& author, const String& text) + const CheckResult::Ptr& cr, const String& author, const String& text) { Host::Ptr host = service->GetHost(); @@ -907,7 +907,7 @@ void ServiceDbObject::AddNotificationHistory(const Service::Ptr& service, const } /* statehistory */ -void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const Dictionary::Ptr& cr, StateType type) +void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const CheckResult::Ptr& cr, StateType type) { Host::Ptr host = service->GetHost(); @@ -961,14 +961,14 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const D } /* logentries */ -void ServiceDbObject::AddCheckResultLogHistory(const Service::Ptr& service, const Dictionary::Ptr &cr) +void ServiceDbObject::AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr) { Host::Ptr host = service->GetHost(); if (!host) return; - Dictionary::Ptr vars_after = cr->Get("vars_after"); + Dictionary::Ptr vars_after = cr->GetVarsAfter(); long state_after = vars_after->Get("state"); long stateType_after = vars_after->Get("state_type"); @@ -976,7 +976,7 @@ void ServiceDbObject::AddCheckResultLogHistory(const Service::Ptr& service, cons bool reachable_after = vars_after->Get("reachable"); bool host_reachable_after = vars_after->Get("host_reachable"); - Dictionary::Ptr vars_before = cr->Get("vars_before"); + Dictionary::Ptr vars_before = cr->GetVarsBefore(); if (vars_before) { long state_before = vars_before->Get("state"); @@ -1008,12 +1008,12 @@ void ServiceDbObject::AddCheckResultLogHistory(const Service::Ptr& service, cons return; } - String output; + String output; - if (cr) { + if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); output = output_bag->Get("output"); - } + } std::ostringstream msgbuf; msgbuf << "SERVICE ALERT: " @@ -1132,7 +1132,7 @@ void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, c } void ServiceDbObject::AddNotificationSentLogHistory(const Service::Ptr& service, const User::Ptr& user, - NotificationType const& notification_type, Dictionary::Ptr const& cr, + NotificationType notification_type, const CheckResult::Ptr& cr, const String& author, const String& comment_text) { Host::Ptr host = service->GetHost(); @@ -1153,42 +1153,42 @@ void ServiceDbObject::AddNotificationSentLogHistory(const Service::Ptr& service, author_comment = ";" + author + ";" + comment_text; } - if (!cr) - return; + if (!cr) + return; - String output; + String output; - if (cr) { + if (cr) { Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr); output = output_bag->Get("output"); - } + } - std::ostringstream msgbuf; - msgbuf << "SERVICE NOTIFICATION: " - << user->GetName() << ";" - << host->GetName() << ";" - << service->GetShortName() << ";" - << notification_type_str << " " - << "(" << Service::StateToString(service->GetState()) << ");" - << check_command << ";" - << output << author_comment - << ""; + std::ostringstream msgbuf; + msgbuf << "SERVICE NOTIFICATION: " + << user->GetName() << ";" + << host->GetName() << ";" + << service->GetShortName() << ";" + << notification_type_str << " " + << "(" << Service::StateToString(service->GetState()) << ");" + << check_command << ";" + << output << author_comment + << ""; - AddLogHistory(service, msgbuf.str(), LogEntryTypeServiceNotification); + AddLogHistory(service, msgbuf.str(), LogEntryTypeServiceNotification); - if (service == host->GetCheckService()) { - std::ostringstream msgbuf; - msgbuf << "HOST NOTIFICATION: " - << user->GetName() << ";" - << host->GetName() << ";" - << notification_type_str << " " - << "(" << Service::StateToString(service->GetState()) << ");" - << check_command << ";" - << output << author_comment - << ""; + if (service == host->GetCheckService()) { + std::ostringstream msgbuf; + msgbuf << "HOST NOTIFICATION: " + << user->GetName() << ";" + << host->GetName() << ";" + << notification_type_str << " " + << "(" << Service::StateToString(service->GetState()) << ");" + << check_command << ";" + << output << author_comment + << ""; - AddLogHistory(service, msgbuf.str(), LogEntryTypeHostNotification); - } + AddLogHistory(service, msgbuf.str(), LogEntryTypeHostNotification); + } } void ServiceDbObject::AddFlappingLogHistory(const Service::Ptr& service, FlappingState flapping_state) @@ -1338,7 +1338,7 @@ void ServiceDbObject::AddFlappingHistory(const Service::Ptr& service, FlappingSt } /* servicechecks */ -void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const Dictionary::Ptr &cr) +void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const CheckResult::Ptr &cr) { Host::Ptr host = service->GetHost(); @@ -1378,10 +1378,10 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const fields1->Set("end_time_usec", time_bag_end->Get("time_usec")); fields1->Set("command_object_id", service->GetCheckCommand()); fields1->Set("command_args", Empty); - fields1->Set("command_line", cr->Get("command")); + fields1->Set("command_line", cr->GetCommand()); fields1->Set("execution_time", attrs->Get("check_execution_time")); fields1->Set("latency", attrs->Get("check_latency")); - fields1->Set("return_code", cr->Get("exit_state")); + fields1->Set("return_code", cr->GetExitStatus()); fields1->Set("output", attrs->Get("plugin_output")); fields1->Set("long_output", attrs->Get("long_plugin_output")); fields1->Set("perfdata", attrs->Get("performance_data")); @@ -1394,11 +1394,12 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const if (host->GetCheckService() == service) { query1.Table = "hostchecks"; - fields1->Remove("service_object_id"); - fields1->Set("host_object_id", host); - fields1->Set("state", host->GetState()); - fields1->Set("state_type", host->GetStateType()); - query1.Fields = fields1; + Dictionary::Ptr fields2 = fields1->ShallowClone(); + fields2->Remove("service_object_id"); + fields2->Set("host_object_id", host); + fields2->Set("state", host->GetState()); + fields2->Set("state_type", host->GetStateType()); + query1.Fields = fields2; OnQuery(query1); } } diff --git a/lib/db_ido/servicedbobject.h b/lib/db_ido/servicedbobject.h index 6791f9d56..6126591e3 100644 --- a/lib/db_ido/servicedbobject.h +++ b/lib/db_ido/servicedbobject.h @@ -100,17 +100,17 @@ private: static void AddDowntimeHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime); static void AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry); static void AddContactNotificationHistory(const Service::Ptr& service, const User::Ptr& user); - static void AddNotificationHistory(const Service::Ptr& service, const std::set& users, NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text); - static void AddStateChangeHistory(const Service::Ptr& service, const Dictionary::Ptr& cr, StateType type); + static void AddNotificationHistory(const Service::Ptr& service, const std::set& users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text); + static void AddStateChangeHistory(const Service::Ptr& service, const CheckResult::Ptr& cr, StateType type); - static void AddCheckResultLogHistory(const Service::Ptr& service, const Dictionary::Ptr &cr); + static void AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr); static void AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime); static void AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime); - static void AddNotificationSentLogHistory(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text); + static void AddNotificationSentLogHistory(const Service::Ptr& service, const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const String& author, const String& comment_text); static void AddFlappingLogHistory(const Service::Ptr& service, FlappingState flapping_state); static void AddFlappingHistory(const Service::Ptr& service, FlappingState flapping_state); - static void AddServiceCheckHistory(const Service::Ptr& service, const Dictionary::Ptr &cr); + static void AddServiceCheckHistory(const Service::Ptr& service, const CheckResult::Ptr &cr); static void AddEventHandlerHistory(const Service::Ptr& service); static void AddExternalCommandHistory(double time, const String& command, const std::vector& arguments); }; diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index 61f959c25..d7f4bede8 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -16,6 +16,7 @@ # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. mkclass_target(checkcommand.ti checkcommand.th) +mkclass_target(checkresult.ti checkresult.th) mkclass_target(command.ti command.th) mkclass_target(domain.ti domain.th) mkclass_target(eventcommand.ti eventcommand.th) @@ -34,11 +35,11 @@ mkclass_target(user.ti user.th) mkembedconfig_target(icinga-type.conf icinga-type.cpp) add_library(icinga SHARED - api.cpp api.h checkcommand.cpp checkcommand.th cib.cpp command.cpp command.th - compatutility.cpp domain.cpp domain.th eventcommand.cpp eventcommand.th - externalcommandprocessor.cpp host.cpp host.th hostgroup.cpp hostgroup.th - icingaapplication.cpp icingaapplication.th macroprocessor.cpp - macroresolver.cpp notificationcommand.cpp notificationcommand.th + api.cpp api.h checkcommand.cpp checkcommand.th checkresult.cpp checkresult.th + cib.cpp command.cpp command.th compatutility.cpp domain.cpp domain.th + eventcommand.cpp eventcommand.th externalcommandprocessor.cpp host.cpp + host.th hostgroup.cpp hostgroup.th icingaapplication.cpp icingaapplication.th + macroprocessor.cpp macroresolver.cpp notificationcommand.cpp notificationcommand.th notification.cpp notification.th perfdatavalue.cpp perfdatavalue.th pluginutility.cpp service-check.cpp service-comment.cpp service.cpp service-downtime.cpp service-event.cpp service-flapping.cpp service.th diff --git a/lib/icinga/checkcommand.cpp b/lib/icinga/checkcommand.cpp index 6767f91a5..cd5cf918c 100644 --- a/lib/icinga/checkcommand.cpp +++ b/lib/icinga/checkcommand.cpp @@ -24,7 +24,7 @@ using namespace icinga; REGISTER_TYPE(CheckCommand); -Dictionary::Ptr CheckCommand::Execute(const Service::Ptr& service) +CheckResult::Ptr CheckCommand::Execute(const Service::Ptr& service) { std::vector arguments; arguments.push_back(service); diff --git a/lib/icinga/checkcommand.h b/lib/icinga/checkcommand.h index 7c0e14a5f..393523175 100644 --- a/lib/icinga/checkcommand.h +++ b/lib/icinga/checkcommand.h @@ -37,7 +37,7 @@ public: DECLARE_PTR_TYPEDEFS(CheckCommand); DECLARE_TYPENAME(CheckCommand); - virtual Dictionary::Ptr Execute(const Service::Ptr& service); + virtual CheckResult::Ptr Execute(const Service::Ptr& service); }; } diff --git a/lib/icinga/checkresult.cpp b/lib/icinga/checkresult.cpp new file mode 100644 index 000000000..a73d4ce88 --- /dev/null +++ b/lib/icinga/checkresult.cpp @@ -0,0 +1,25 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#include "icinga/checkresult.h" +#include "base/dynamictype.h" + +using namespace icinga; + +REGISTER_TYPE(CheckResult); diff --git a/lib/icinga/checkresult.h b/lib/icinga/checkresult.h new file mode 100644 index 000000000..67a75238c --- /dev/null +++ b/lib/icinga/checkresult.h @@ -0,0 +1,42 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#ifndef CHECKRESULT_H +#define CHECKRESULT_H + +#include "icinga/i2-icinga.h" +#include "icinga/checkresult.th" + +namespace icinga +{ + +/** + * A check result. + * + * @ingroup icinga + */ +class I2_ICINGA_API CheckResult : public ObjectImpl +{ +public: + DECLARE_PTR_TYPEDEFS(CheckResult); +}; + +} + +#endif /* CHECKRESULT_H */ diff --git a/lib/icinga/checkresult.ti b/lib/icinga/checkresult.ti new file mode 100644 index 000000000..6c1473c32 --- /dev/null +++ b/lib/icinga/checkresult.ti @@ -0,0 +1,54 @@ +namespace icinga +{ + +code {{{ +/** + * The state of a service. + * + * @ingroup icinga + */ +enum ServiceState +{ + StateOK = 0, + StateWarning = 1, + StateCritical = 2, + StateUnknown = 3 +}; + +/** + * The state type of a host or service. + * + * @ingroup icinga + */ +enum StateType +{ + StateTypeSoft = 0, + StateTypeHard = 1 +}; +}}} + +class CheckResult +{ + [state] double schedule_start; + [state] double schedule_end; + [state] double execution_start; + [state] double execution_end; + + [state] String command; + [state] int exit_status; + + [state, enum] ServiceState "state"; + [state] String output; + [state] Value performance_data; + + [state] bool active { + default {{{ return true; }}} + }; + + [state] String check_source; + + [state] Dictionary::Ptr vars_before; + [state] Dictionary::Ptr vars_after; +}; + +} diff --git a/lib/icinga/command.cpp b/lib/icinga/command.cpp index c063c140c..9555e869d 100644 --- a/lib/icinga/command.cpp +++ b/lib/icinga/command.cpp @@ -23,7 +23,7 @@ using namespace icinga; REGISTER_TYPE(Command); -bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const +bool Command::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { Dictionary::Ptr macros = GetMacros(); diff --git a/lib/icinga/command.h b/lib/icinga/command.h index a0c8c1073..0df914758 100644 --- a/lib/icinga/command.h +++ b/lib/icinga/command.h @@ -42,7 +42,7 @@ public: //virtual Dictionary::Ptr Execute(const Object::Ptr& context) = 0; - virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; }; } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index f3f540b64..c70f57f82 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -184,17 +184,17 @@ Dictionary::Ptr CompatUtility::GetServiceStatusAttributes(const Service::Ptr& se else check_period_str = "24x7"; - Dictionary::Ptr cr = service->GetLastCheckResult(); + CheckResult::Ptr cr = service->GetLastCheckResult(); if (cr) { Dictionary::Ptr output_bag = GetCheckResultOutput(cr); output = output_bag->Get("output"); long_output = output_bag->Get("long_output"); - check_source = cr->Get("check_source"); + check_source = cr->GetCheckSource(); perfdata = GetCheckResultPerfdata(cr); - schedule_end = cr->Get("schedule_end"); + schedule_end = cr->GetScheduleEnd(); } int state = service->GetState(); @@ -521,7 +521,7 @@ std::set CompatUtility::GetServiceNotificationUserGroups(const S return usergroups; } -Dictionary::Ptr CompatUtility::GetCheckResultOutput(const Dictionary::Ptr& cr) +Dictionary::Ptr CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr) { if (!cr) return Empty; @@ -530,7 +530,7 @@ Dictionary::Ptr CompatUtility::GetCheckResultOutput(const Dictionary::Ptr& cr) String output; Dictionary::Ptr bag = make_shared(); - String raw_output = cr->Get("output"); + String raw_output = cr->GetOutput(); /* * replace semi-colons with colons in output @@ -554,12 +554,12 @@ Dictionary::Ptr CompatUtility::GetCheckResultOutput(const Dictionary::Ptr& cr) return bag; } -String CompatUtility::GetCheckResultPerfdata(const Dictionary::Ptr& cr) +String CompatUtility::GetCheckResultPerfdata(const CheckResult::Ptr& cr) { if (!cr) return String(); - return PluginUtility::FormatPerfdata(cr->Get("performance_data")); + return PluginUtility::FormatPerfdata(cr->GetPerformanceData()); } String CompatUtility::EscapeString(const String& str) diff --git a/lib/icinga/compatutility.h b/lib/icinga/compatutility.h index 533f177da..b20c4d406 100644 --- a/lib/icinga/compatutility.h +++ b/lib/icinga/compatutility.h @@ -59,8 +59,8 @@ public: static std::set GetServiceNotificationUsers(const Service::Ptr& service); static std::set GetServiceNotificationUserGroups(const Service::Ptr& service); - static Dictionary::Ptr GetCheckResultOutput(const Dictionary::Ptr& cr); - static String GetCheckResultPerfdata(const Dictionary::Ptr& cr); + static Dictionary::Ptr GetCheckResultOutput(const CheckResult::Ptr& cr); + static String GetCheckResultPerfdata(const CheckResult::Ptr& cr); static Dictionary::Ptr ConvertTimestamp(double time); diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 2a40a128f..8f46a93a3 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -214,14 +214,14 @@ void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::ve BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled.")); int exitStatus = Convert::ToDouble(arguments[1]); - Dictionary::Ptr result = PluginUtility::ParseCheckOutput(arguments[2]); - result->Set("state", PluginUtility::ExitStatusToState(exitStatus)); + CheckResult::Ptr result = PluginUtility::ParseCheckOutput(arguments[2]); + result->SetState(PluginUtility::ExitStatusToState(exitStatus)); - result->Set("schedule_start", time); - result->Set("schedule_end", time); - result->Set("execution_start", time); - result->Set("execution_end", time); - result->Set("active", 0); + result->SetScheduleStart(time); + result->SetScheduleEnd(time); + result->SetExecutionStart(time); + result->SetExecutionEnd(time); + result->SetActive(false); Log(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'"); hc->ProcessCheckResult(result); @@ -250,14 +250,14 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std: BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled.")); int exitStatus = Convert::ToDouble(arguments[2]); - Dictionary::Ptr result = PluginUtility::ParseCheckOutput(arguments[3]); - result->Set("state", PluginUtility::ExitStatusToState(exitStatus)); + CheckResult::Ptr result = PluginUtility::ParseCheckOutput(arguments[3]); + result->SetState(PluginUtility::ExitStatusToState(exitStatus)); - result->Set("schedule_start", time); - result->Set("schedule_end", time); - result->Set("execution_start", time); - result->Set("execution_end", time); - result->Set("active", 0); + result->SetScheduleStart(time); + result->SetScheduleEnd(time); + result->SetExecutionStart(time); + result->SetExecutionEnd(time); + result->SetActive(false); Log(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'"); service->ProcessCheckResult(result); diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 297c22a5e..8bc79665f 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -542,7 +542,7 @@ String Host::StateTypeToString(StateType type) return "HARD"; } -bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const +bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { if (macro == "HOSTNAME") { *result = GetName(); @@ -554,7 +554,7 @@ bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *res } Service::Ptr hc = GetCheckService(); - Dictionary::Ptr hccr; + CheckResult::Ptr hccr; if (hc) { ServiceState state = hc->GetState(); @@ -618,13 +618,13 @@ bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *res *result = Convert::ToString(Service::CalculateExecutionTime(hccr)); return true; } else if (macro == "HOSTOUTPUT") { - *result = hccr->Get("output"); + *result = hccr->GetOutput(); return true; } else if (macro == "HOSTPERFDATA") { - *result = PluginUtility::FormatPerfdata(hccr->Get("performance_data")); + *result = PluginUtility::FormatPerfdata(hccr->GetPerformanceData()); return true; } else if (macro == "LASTHOSTCHECK") { - *result = Convert::ToString((long)hccr->Get("schedule_start")); + *result = Convert::ToString((long)hccr->GetScheduleStart()); return true; } } diff --git a/lib/icinga/host.h b/lib/icinga/host.h index 0dad2891e..f984c78c1 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -23,6 +23,7 @@ #include "icinga/i2-icinga.h" #include "icinga/host.th" #include "icinga/macroresolver.h" +#include "icinga/checkresult.h" #include "base/array.h" #include "base/dictionary.h" @@ -88,7 +89,7 @@ public: static StateType StateTypeFromString(const String& state); static String StateTypeToString(StateType state); - virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; protected: virtual void Start(void); diff --git a/lib/icinga/host.ti b/lib/icinga/host.ti index a190c03a2..edb4d4526 100644 --- a/lib/icinga/host.ti +++ b/lib/icinga/host.ti @@ -3,32 +3,6 @@ namespace icinga { -code {{{ -/** - * The state of a service. - * - * @ingroup icinga - */ -enum ServiceState -{ - StateOK = 0, - StateWarning = 1, - StateCritical = 2, - StateUnknown = 3 -}; - -/** - * The state type of a host or service. - * - * @ingroup icinga - */ -enum StateType -{ - StateTypeSoft = 0, - StateTypeHard = 1 -}; -}}} - class Host : DynamicObject { [config] String display_name { diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index abbd9da45..58fddf0b9 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -93,7 +93,7 @@ Dictionary::Ptr IcingaApplication::GetMacros(void) const return ScriptVariable::Get("IcingaMacros"); } -bool IcingaApplication::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const +bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { double now = Utility::GetTime(); diff --git a/lib/icinga/icingaapplication.h b/lib/icinga/icingaapplication.h index 120b54825..144407f53 100644 --- a/lib/icinga/icingaapplication.h +++ b/lib/icinga/icingaapplication.h @@ -47,7 +47,7 @@ public: String GetPidPath(void) const; Dictionary::Ptr GetMacros(void) const; - virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; bool GetEnableNotifications(void) const; void SetEnableNotifications(bool enabled); diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index 2fffffb44..6159f9034 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -29,7 +29,7 @@ using namespace icinga; Value MacroProcessor::ResolveMacros(const Value& str, const std::vector& resolvers, - const Dictionary::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn, const Array::Ptr& escapeMacros) + const CheckResult::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn, const Array::Ptr& escapeMacros) { Value result; @@ -58,7 +58,7 @@ Value MacroProcessor::ResolveMacros(const Value& str, const std::vector& resolvers, - const Dictionary::Ptr& cr, String *result) + const CheckResult::Ptr& cr, String *result) { BOOST_FOREACH(const MacroResolver::Ptr& resolver, resolvers) { if (resolver->ResolveMacro(macro, cr, result)) @@ -70,7 +70,7 @@ bool MacroProcessor::ResolveMacro(const String& macro, const std::vector& resolvers, - const Dictionary::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn, const Array::Ptr& escapeMacros) + const CheckResult::Ptr& cr, const MacroProcessor::EscapeCallback& escapeFn, const Array::Ptr& escapeMacros) { size_t offset, pos_first, pos_second; offset = 0; diff --git a/lib/icinga/macroprocessor.h b/lib/icinga/macroprocessor.h index e5c6815ea..b7f012ea8 100644 --- a/lib/icinga/macroprocessor.h +++ b/lib/icinga/macroprocessor.h @@ -41,15 +41,15 @@ public: typedef boost::function EscapeCallback; static Value ResolveMacros(const Value& str, const std::vector& resolvers, - const Dictionary::Ptr& cr, const EscapeCallback& escapeFn = EscapeCallback(), const Array::Ptr& escapeMacros = Array::Ptr()); + const CheckResult::Ptr& cr, const EscapeCallback& escapeFn = EscapeCallback(), const Array::Ptr& escapeMacros = Array::Ptr()); static bool ResolveMacro(const String& macro, const std::vector& resolvers, - const Dictionary::Ptr& cr, String *result); + const CheckResult::Ptr& cr, String *result); private: MacroProcessor(void); static String InternalResolveMacros(const String& str, - const std::vector& resolvers, const Dictionary::Ptr& cr, + const std::vector& resolvers, const CheckResult::Ptr& cr, const EscapeCallback& escapeFn, const Array::Ptr& escapeMacros); }; diff --git a/lib/icinga/macroresolver.cpp b/lib/icinga/macroresolver.cpp index 17a2923a7..9e53e5e57 100644 --- a/lib/icinga/macroresolver.cpp +++ b/lib/icinga/macroresolver.cpp @@ -30,7 +30,7 @@ void StaticMacroResolver::Add(const String& macro, const String& value) m_Macros->Set(macro, value); } -bool StaticMacroResolver::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const +bool StaticMacroResolver::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { if (m_Macros->Contains(macro)) { *result = m_Macros->Get(macro); diff --git a/lib/icinga/macroresolver.h b/lib/icinga/macroresolver.h index 5f559431e..6e7997916 100644 --- a/lib/icinga/macroresolver.h +++ b/lib/icinga/macroresolver.h @@ -21,6 +21,7 @@ #define MACRORESOLVER_H #include "icinga/i2-icinga.h" +#include "icinga/checkresult.h" #include "base/dictionary.h" #include "base/qstring.h" @@ -37,7 +38,7 @@ class I2_ICINGA_API MacroResolver public: DECLARE_PTR_TYPEDEFS(MacroResolver); - virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const = 0; + virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const = 0; }; class I2_ICINGA_API StaticMacroResolver : public Object, public MacroResolver @@ -49,7 +50,7 @@ public: void Add(const String& macro, const String& value); - virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; private: Dictionary::Ptr m_Macros; diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 53e91413a..36a734982 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -169,7 +169,7 @@ String Notification::NotificationTypeToString(NotificationType type) } } -void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force, const String& author, const String& text) +void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author, const String& text) { ASSERT(!OwnsLock()); @@ -240,7 +240,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const Diction Service::OnNotificationSentToAllUsers(GetService(), allUsers, type, cr, author, text); } -void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author, const String& text) +void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author, const String& text) { ASSERT(!OwnsLock()); @@ -297,7 +297,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: } } -bool Notification::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const +bool Notification::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { Dictionary::Ptr macros = GetMacros(); diff --git a/lib/icinga/notification.h b/lib/icinga/notification.h index 5875825f2..87dffd97f 100644 --- a/lib/icinga/notification.h +++ b/lib/icinga/notification.h @@ -74,11 +74,11 @@ public: void UpdateNotificationNumber(void); void ResetNotificationNumber(void); - void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = ""); + void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = ""); static String NotificationTypeToString(NotificationType type); - virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; static boost::signals2::signal OnNextNotificationChanged; @@ -87,7 +87,7 @@ protected: virtual void Stop(void); private: - void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = ""); + void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = ""); }; } diff --git a/lib/icinga/notificationcommand.cpp b/lib/icinga/notificationcommand.cpp index e9968a5b3..795e113e8 100644 --- a/lib/icinga/notificationcommand.cpp +++ b/lib/icinga/notificationcommand.cpp @@ -25,7 +25,7 @@ using namespace icinga; REGISTER_TYPE(NotificationCommand); Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification, - const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type, + const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type, const String& author, const String& comment) { std::vector arguments; diff --git a/lib/icinga/notificationcommand.h b/lib/icinga/notificationcommand.h index 1dbdafb0c..e6fca870b 100644 --- a/lib/icinga/notificationcommand.h +++ b/lib/icinga/notificationcommand.h @@ -40,7 +40,7 @@ public: DECLARE_TYPENAME(NotificationCommand); virtual Dictionary::Ptr Execute(const shared_ptr& notification, - const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type, + const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type, const String& author, const String& comment); }; diff --git a/lib/icinga/pluginutility.cpp b/lib/icinga/pluginutility.cpp index 4e9af85e9..4c333db71 100644 --- a/lib/icinga/pluginutility.cpp +++ b/lib/icinga/pluginutility.cpp @@ -47,9 +47,9 @@ ServiceState PluginUtility::ExitStatusToState(int exitStatus) } } -Dictionary::Ptr PluginUtility::ParseCheckOutput(const String& output) +CheckResult::Ptr PluginUtility::ParseCheckOutput(const String& output) { - Dictionary::Ptr result = make_shared(); + CheckResult::Ptr result = make_shared(); String text; String perfdata; @@ -75,8 +75,8 @@ Dictionary::Ptr PluginUtility::ParseCheckOutput(const String& output) } } - result->Set("output", text); - result->Set("performance_data", ParsePerfdata(perfdata)); + result->SetOutput(text); + result->SetPerformanceData(ParsePerfdata(perfdata)); return result; } diff --git a/lib/icinga/pluginutility.h b/lib/icinga/pluginutility.h index 5c01ceaaa..7e32cd096 100644 --- a/lib/icinga/pluginutility.h +++ b/lib/icinga/pluginutility.h @@ -39,7 +39,7 @@ class I2_ICINGA_API PluginUtility { public: static ServiceState ExitStatusToState(int exitStatus); - static Dictionary::Ptr ParseCheckOutput(const String& output); + static CheckResult::Ptr ParseCheckOutput(const String& output); static Value ParsePerfdata(const String& perfdata); static String FormatPerfdata(const Value& perfdata); diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index 2c84fc052..3a1152a35 100644 --- a/lib/icinga/service-check.cpp +++ b/lib/icinga/service-check.cpp @@ -32,9 +32,9 @@ using namespace icinga; -boost::signals2::signal Service::OnNewCheckResult; -boost::signals2::signal Service::OnStateChange; -boost::signals2::signal Service::OnNotificationsRequested; +boost::signals2::signal Service::OnNewCheckResult; +boost::signals2::signal Service::OnStateChange; +boost::signals2::signal Service::OnNotificationsRequested; boost::signals2::signal Service::OnNextCheckChanged; boost::signals2::signal Service::OnForceNextCheckChanged; boost::signals2::signal Service::OnForceNextNotificationChanged; @@ -129,11 +129,11 @@ bool Service::HasBeenChecked(void) const double Service::GetLastCheck(void) const { - Dictionary::Ptr cr = GetLastCheckResult(); + CheckResult::Ptr cr = GetLastCheckResult(); double schedule_end = -1; if (cr) - schedule_end = cr->Get("schedule_end"); + schedule_end = cr->GetScheduleEnd(); return schedule_end; } @@ -180,26 +180,26 @@ void Service::SetForceNextCheck(bool forced, const String& authority) Utility::QueueAsyncCallback(boost::bind(boost::ref(OnForceNextCheckChanged), GetSelf(), forced, authority)); } -void Service::ProcessCheckResult(const Dictionary::Ptr& cr, const String& authority) +void Service::ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority) { double now = Utility::GetTime(); - if (!cr->Contains("schedule_start")) - cr->Set("schedule_start", now); + if (cr->GetScheduleStart() == 0) + cr->SetScheduleStart(now); - if (!cr->Contains("schedule_end")) - cr->Set("schedule_end", now); + if (cr->GetScheduleEnd() == 0) + cr->SetScheduleEnd(now); - if (!cr->Contains("execution_start")) - cr->Set("execution_start", now); + if (cr->GetExecutionStart() == 0) + cr->SetExecutionStart(now); - if (!cr->Contains("execution_end")) - cr->Set("execution_end", now); + if (cr->GetExecutionEnd() == 0) + cr->SetExecutionEnd(now); - String check_source = cr->Get("check_source"); + String check_source = cr->GetCheckSource(); if (check_source.IsEmpty()) - cr->Set("check_source", authority); + cr->SetCheckSource(authority); bool reachable = IsReachable(); @@ -212,13 +212,13 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr, const String& author ASSERT(!OwnsLock()); ObjectLock olock(this); - Dictionary::Ptr old_cr = GetLastCheckResult(); + CheckResult::Ptr old_cr = GetLastCheckResult(); ServiceState old_state = GetState(); StateType old_stateType = GetStateType(); long old_attempt = GetCheckAttempt(); bool recovery; - if (old_cr && cr->Get("execution_start") < old_cr->Get("execution_start")) + if (old_cr && cr->GetExecutionStart() < old_cr->GetExecutionStart()) return; /* The ExecuteCheck function already sets the old state, but we need to do it again @@ -229,7 +229,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr, const String& author long attempt; - if (cr->Get("state") == StateOK) { + if (cr->GetState() == StateOK) { if (old_state == StateOK && old_stateType == StateTypeSoft) SetStateType(StateTypeHard); // SOFT OK -> HARD OK @@ -250,12 +250,17 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr, const String& author recovery = false; - if (cr->Get("state") == StateWarning) - SetLastStateWarning(Utility::GetTime()); - if (cr->Get("state") == StateCritical) - SetLastStateCritical(Utility::GetTime()); - if (cr->Get("state") == StateUnknown) - SetLastStateUnknown(Utility::GetTime()); + switch (cr->GetState()) { + case StateWarning: + SetLastStateWarning(Utility::GetTime()); + break; + case StateCritical: + SetLastStateCritical(Utility::GetTime()); + break; + case StateUnknown: + SetLastStateUnknown(Utility::GetTime()); + break; + } } if (!reachable) @@ -263,8 +268,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr, const String& author SetCheckAttempt(attempt); - int state = cr->Get("state"); - SetState(static_cast(state)); + SetState(cr->GetState()); bool call_eventhandler = false; bool stateChange = (old_state != GetState()); @@ -341,9 +345,9 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr, const String& author vars_after->Set("host_reachable", host_reachable); if (old_cr) - cr->Set("vars_before", old_cr->Get("vars_after")); + cr->SetVarsBefore(old_cr->GetVarsAfter()); - cr->Set("vars_after", vars_after); + cr->SetVarsAfter(vars_after); olock.Lock(); SetLastCheckResult(cr); @@ -457,13 +461,11 @@ void Service::ExecuteCheck(void) } /* keep track of scheduling info in case the check type doesn't provide its own information */ - Dictionary::Ptr checkInfo = make_shared(); - checkInfo->Set("schedule_start", GetNextCheck()); - checkInfo->Set("execution_start", Utility::GetTime()); + double before_check = Utility::GetTime(); Service::Ptr self = GetSelf(); - Dictionary::Ptr result; + CheckResult::Ptr result; try { CheckCommand::Ptr command = GetCheckCommand(); @@ -482,32 +484,25 @@ void Service::ExecuteCheck(void) Log(LogWarning, "icinga", message); - result = make_shared(); - result->Set("state", StateUnknown); - result->Set("output", message); + result = make_shared(); + result->SetState(StateUnknown); + result->SetOutput(message); } - checkInfo->Set("execution_end", Utility::GetTime()); - checkInfo->Set("schedule_end", Utility::GetTime()); + double after_check = Utility::GetTime(); if (result) { - if (!result->Contains("schedule_start")) - result->Set("schedule_start", checkInfo->Get("schedule_start")); + if (!result->GetScheduleStart() == 0) + result->SetScheduleStart(before_check); - if (!result->Contains("schedule_end")) - result->Set("schedule_end", checkInfo->Get("schedule_end")); + if (!result->GetScheduleEnd() == 0) + result->SetScheduleEnd(after_check); - if (!result->Contains("execution_start")) - result->Set("execution_start", checkInfo->Get("execution_start")); + if (!result->GetExecutionStart() == 0) + result->SetExecutionStart(before_check); - if (!result->Contains("execution_end")) - result->Set("execution_end", checkInfo->Get("execution_end")); - - if (!result->Contains("macros")) - result->Set("macros", checkInfo->Get("macros")); - - if (!result->Contains("active")) - result->Set("active", 1); + if (!result->GetExecutionEnd() == 0) + result->SetExecutionEnd(after_check); } if (result) @@ -524,50 +519,33 @@ void Service::ExecuteCheck(void) } } -void Service::UpdateStatistics(const Dictionary::Ptr& cr) +void Service::UpdateStatistics(const CheckResult::Ptr& cr) { - time_t ts; - Value schedule_end = cr->Get("schedule_end"); - if (!schedule_end.IsEmpty()) - ts = static_cast(schedule_end); - else + time_t ts = cr->GetScheduleEnd(); + + if (ts == 0) ts = static_cast(Utility::GetTime()); - Value active = cr->Get("active"); - if (active.IsEmpty() || static_cast(active)) + if (cr->GetActive()) CIB::UpdateActiveChecksStatistics(ts, 1); else CIB::UpdatePassiveChecksStatistics(ts, 1); } -double Service::CalculateExecutionTime(const Dictionary::Ptr& cr) +double Service::CalculateExecutionTime(const CheckResult::Ptr& cr) { - double execution_start = 0, execution_end = 0; + if (!cr) + return 0; - if (cr) { - if (!cr->Contains("execution_start") || !cr->Contains("execution_end")) - return 0; - - execution_start = cr->Get("execution_start"); - execution_end = cr->Get("execution_end"); - } - - return (execution_end - execution_start); + return cr->GetExecutionEnd() - cr->GetExecutionStart(); } -double Service::CalculateLatency(const Dictionary::Ptr& cr) +double Service::CalculateLatency(const CheckResult::Ptr& cr) { - double schedule_start = 0, schedule_end = 0; + if (!cr) + return 0; - if (cr) { - if (!cr->Contains("schedule_start") || !cr->Contains("schedule_end")) - return 0; - - schedule_start = cr->Get("schedule_start"); - schedule_end = cr->Get("schedule_end"); - } - - double latency = (schedule_end - schedule_start) - CalculateExecutionTime(cr); + double latency = (cr->GetScheduleEnd() - cr->GetScheduleStart()) - CalculateExecutionTime(cr); if (latency < 0) latency = 0; diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 132f97fe5..491345940 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -31,8 +31,8 @@ using namespace icinga; -boost::signals2::signal&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentToAllUsers; -boost::signals2::signal Service::OnNotificationSentToUser; +boost::signals2::signal&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSentToAllUsers; +boost::signals2::signal Service::OnNotificationSentToUser; void Service::ResetNotificationNumbers(void) { @@ -42,7 +42,7 @@ void Service::ResetNotificationNumbers(void) } } -void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text) +void Service::SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text) { bool force = GetForceNextNotification(); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 484c9abda..9d526dc68 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -309,7 +309,7 @@ void Service::SetModifiedAttributes(int flags) SetOverrideRetryInterval(Empty); } -bool Service::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const +bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const { if (macro == "SERVICEDESC") { *result = GetShortName(); @@ -391,13 +391,13 @@ bool Service::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, Strin *result = Convert::ToString(Service::CalculateExecutionTime(cr)); return true; } else if (macro == "SERVICEOUTPUT") { - *result = cr->Get("output"); + *result = cr->GetOutput(); return true; } else if (macro == "SERVICEPERFDATA") { - *result = PluginUtility::FormatPerfdata(cr->Get("performance_data")); + *result = PluginUtility::FormatPerfdata(cr->GetPerformanceData()); return true; } else if (macro == "LASTSERVICECHECK") { - *result = Convert::ToString((long)cr->Get("execution_end")); + *result = Convert::ToString((long)cr->GetExecutionEnd()); return true; } } diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 26e151b19..fed2bc84d 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -172,16 +172,16 @@ public: bool GetForceNextCheck(void) const; void SetForceNextCheck(bool forced, const String& authority = String()); - static void UpdateStatistics(const Dictionary::Ptr& cr); + static void UpdateStatistics(const CheckResult::Ptr& cr); void ExecuteCheck(void); - void ProcessCheckResult(const Dictionary::Ptr& cr, const String& authority = String()); + void ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority = String()); int GetModifiedAttributes(void) const; void SetModifiedAttributes(int flags); - static double CalculateExecutionTime(const Dictionary::Ptr& cr); - static double CalculateLatency(const Dictionary::Ptr& cr); + static double CalculateExecutionTime(const CheckResult::Ptr& cr); + static double CalculateLatency(const CheckResult::Ptr& cr); static ServiceState StateFromString(const String& state); static String StateToString(ServiceState state); @@ -196,11 +196,11 @@ public: static boost::signals2::signal OnEnablePassiveChecksChanged; static boost::signals2::signal OnEnableNotificationsChanged; static boost::signals2::signal OnEnableFlappingChanged; - static boost::signals2::signal OnNewCheckResult; - static boost::signals2::signal OnStateChange; - static boost::signals2::signal OnNotificationsRequested; - static boost::signals2::signal OnNotificationSentToUser; - static boost::signals2::signal&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentToAllUsers; + static boost::signals2::signal OnNewCheckResult; + static boost::signals2::signal OnStateChange; + static boost::signals2::signal OnNotificationsRequested; + static boost::signals2::signal OnNotificationSentToUser; + static boost::signals2::signal&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> OnNotificationSentToAllUsers; static boost::signals2::signal OnCommentAdded; static boost::signals2::signal OnCommentRemoved; static boost::signals2::signal OnDowntimeAdded; @@ -211,7 +211,7 @@ public: static boost::signals2::signal OnAcknowledgementCleared; static boost::signals2::signal OnEventCommandExecuted; - virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; /* Downtimes */ static int GetNextDowntimeID(void); @@ -261,7 +261,7 @@ public: bool GetEnableNotifications(void) const; void SetEnableNotifications(bool enabled, const String& authority = String()); - void SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = ""); + void SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author = "", const String& text = ""); std::set GetNotifications(void) const; void AddNotification(const Notification::Ptr& notification); diff --git a/lib/icinga/service.ti b/lib/icinga/service.ti index 056a4e165..134a41c61 100644 --- a/lib/icinga/service.ti +++ b/lib/icinga/service.ti @@ -91,7 +91,7 @@ class Service : DynamicObject [state] bool last_reachable { default {{{ return true; }}} }; - [state] Dictionary::Ptr last_check_result; + [state] CheckResult::Ptr last_check_result; [state] double last_state_change { default {{{ return Application::GetStartTime(); }}} }; diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 7a8cddb13..23d92f82f 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -66,7 +66,7 @@ TimePeriod::Ptr User::GetNotificationPeriod(void) const return TimePeriod::GetByName(GetNotificationPeriodRaw()); } -bool User::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const +bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { if (macro == "USERNAME" || macro == "CONTACTNAME") { *result = GetName(); diff --git a/lib/icinga/user.h b/lib/icinga/user.h index 97b34905c..af2732c6d 100644 --- a/lib/icinga/user.h +++ b/lib/icinga/user.h @@ -43,7 +43,7 @@ public: /* Notifications */ TimePeriod::Ptr GetNotificationPeriod(void) const; - virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; protected: virtual void Stop(void); diff --git a/lib/methods/nullchecktask.cpp b/lib/methods/nullchecktask.cpp index 01e80fdca..fba1df3eb 100644 --- a/lib/methods/nullchecktask.cpp +++ b/lib/methods/nullchecktask.cpp @@ -30,7 +30,7 @@ using namespace icinga; REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc); -Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&) +CheckResult::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&) { char name[255]; @@ -43,10 +43,10 @@ Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&) Dictionary::Ptr perfdata = make_shared(); perfdata->Set("time", Utility::GetTime()); - Dictionary::Ptr cr = make_shared(); - cr->Set("output", output); - cr->Set("performance_data", perfdata); - cr->Set("state", StateOK); + CheckResult::Ptr cr = make_shared(); + cr->SetOutput(output); + cr->SetPerformanceData(perfdata); + cr->SetState(StateOK); return cr; } diff --git a/lib/methods/nullchecktask.h b/lib/methods/nullchecktask.h index 8b7b42d1c..236a0755e 100644 --- a/lib/methods/nullchecktask.h +++ b/lib/methods/nullchecktask.h @@ -35,7 +35,7 @@ namespace icinga class I2_METHODS_API NullCheckTask { public: - static Dictionary::Ptr ScriptFunc(const Service::Ptr& service); + static CheckResult::Ptr ScriptFunc(const Service::Ptr& service); private: NullCheckTask(void); diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index a99dd1b0b..79177335e 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -35,7 +35,7 @@ using namespace icinga; REGISTER_SCRIPTFUNCTION(PluginCheck, &PluginCheckTask::ScriptFunc); -Dictionary::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service) +CheckResult::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service) { CheckCommand::Ptr commandObj = service->GetCheckCommand(); Value raw_command = commandObj->GetCommandLine(); @@ -73,12 +73,12 @@ Dictionary::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service) String output = pr.Output; output.Trim(); - Dictionary::Ptr result = PluginUtility::ParseCheckOutput(output); - result->Set("command", command); - result->Set("state", PluginUtility::ExitStatusToState(pr.ExitStatus)); - result->Set("exit_state", pr.ExitStatus); - result->Set("execution_start", pr.ExecutionStart); - result->Set("execution_end", pr.ExecutionEnd); + CheckResult::Ptr result = PluginUtility::ParseCheckOutput(output); + result->SetCommand(command); + result->SetState(PluginUtility::ExitStatusToState(pr.ExitStatus)); + result->SetExitStatus(pr.ExitStatus); + result->SetExecutionStart(pr.ExecutionStart); + result->SetExecutionEnd(pr.ExecutionEnd); return result; } diff --git a/lib/methods/pluginchecktask.h b/lib/methods/pluginchecktask.h index 8b178593f..35869f12d 100644 --- a/lib/methods/pluginchecktask.h +++ b/lib/methods/pluginchecktask.h @@ -34,7 +34,7 @@ namespace icinga class I2_METHODS_API PluginCheckTask { public: - static Dictionary::Ptr ScriptFunc(const Service::Ptr& service); + static CheckResult::Ptr ScriptFunc(const Service::Ptr& service); private: PluginCheckTask(void); diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 6247499fc..b12fe3d95 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -33,7 +33,7 @@ using namespace icinga; REGISTER_SCRIPTFUNCTION(PluginNotification, &PluginNotificationTask::ScriptFunc); -void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, const User::Ptr& user, const Dictionary::Ptr& cr, int itype, +void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, const User::Ptr& user, const CheckResult::Ptr& cr, int itype, const String& author, const String& comment) { NotificationCommand::Ptr commandObj = notification->GetNotificationCommand(); diff --git a/lib/methods/pluginnotificationtask.h b/lib/methods/pluginnotificationtask.h index b899ef5a3..ec364d004 100644 --- a/lib/methods/pluginnotificationtask.h +++ b/lib/methods/pluginnotificationtask.h @@ -35,7 +35,7 @@ class I2_METHODS_API PluginNotificationTask { public: static void ScriptFunc(const Notification::Ptr& notification, - const User::Ptr& user, const Dictionary::Ptr& cr, int itype, + const User::Ptr& user, const CheckResult::Ptr& cr, int itype, const String& author, const String& comment); private: diff --git a/lib/methods/randomchecktask.cpp b/lib/methods/randomchecktask.cpp index 2ca8c4b70..a7b24e6bc 100644 --- a/lib/methods/randomchecktask.cpp +++ b/lib/methods/randomchecktask.cpp @@ -30,7 +30,7 @@ using namespace icinga; REGISTER_SCRIPTFUNCTION(RandomCheck, &RandomCheckTask::ScriptFunc); -Dictionary::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&) +CheckResult::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&) { char name[255]; @@ -43,10 +43,10 @@ Dictionary::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&) Dictionary::Ptr perfdata = make_shared(); perfdata->Set("time", Utility::GetTime()); - Dictionary::Ptr cr = make_shared(); - cr->Set("output", output); - cr->Set("performance_data", perfdata); - cr->Set("state", static_cast(Utility::Random() % 4)); + CheckResult::Ptr cr = make_shared(); + cr->SetOutput(output); + cr->SetPerformanceData(perfdata); + cr->SetState(static_cast(Utility::Random() % 4)); return cr; } diff --git a/lib/methods/randomchecktask.h b/lib/methods/randomchecktask.h index 95592492d..854d64235 100644 --- a/lib/methods/randomchecktask.h +++ b/lib/methods/randomchecktask.h @@ -34,7 +34,7 @@ namespace icinga class RandomCheckTask { public: - static Dictionary::Ptr ScriptFunc(const Service::Ptr& service); + static CheckResult::Ptr ScriptFunc(const Service::Ptr& service); private: RandomCheckTask(void);