diff --git a/components/cluster/clusterlistener.cpp b/components/cluster/clusterlistener.cpp index f064c2bcb..82d7e2153 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; @@ -831,7 +831,7 @@ void ClusterListener::EnableFlappingChangedHandler(const Service::Ptr& service, AsyncRelayMessage(Endpoint::Ptr(), message, true); } -void ClusterListener::CommentAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority) +void ClusterListener::CommentAddedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority) { if (!authority.IsEmpty() && authority != GetIdentity()) return; @@ -850,14 +850,14 @@ void ClusterListener::CommentAddedHandler(const Service::Ptr& service, const Dic AsyncRelayMessage(Endpoint::Ptr(), message, true); } -void ClusterListener::CommentRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority) +void ClusterListener::CommentRemovedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority) { if (!authority.IsEmpty() && authority != GetIdentity()) return; Dictionary::Ptr params = make_shared(); params->Set("service", service->GetName()); - params->Set("id", comment->Get("id")); + params->Set("id", comment->GetId()); Dictionary::Ptr message = make_shared(); message->Set("jsonrpc", "2.0"); @@ -869,7 +869,7 @@ void ClusterListener::CommentRemovedHandler(const Service::Ptr& service, const D AsyncRelayMessage(Endpoint::Ptr(), message, true); } -void ClusterListener::DowntimeAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority) +void ClusterListener::DowntimeAddedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority) { if (!authority.IsEmpty() && authority != GetIdentity()) return; @@ -888,14 +888,14 @@ void ClusterListener::DowntimeAddedHandler(const Service::Ptr& service, const Di AsyncRelayMessage(Endpoint::Ptr(), message, true); } -void ClusterListener::DowntimeRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority) +void ClusterListener::DowntimeRemovedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority) { if (!authority.IsEmpty() && authority != GetIdentity()) return; Dictionary::Ptr params = make_shared(); params->Set("service", service->GetName()); - params->Set("id", downtime->Get("id")); + params->Set("id", downtime->GetId()); Dictionary::Ptr message = make_shared(); message->Set("jsonrpc", "2.0"); @@ -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; @@ -1206,11 +1206,10 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona return; } - Dictionary::Ptr comment = params->Get("comment"); + Comment::Ptr comment = params->Get("comment"); - long type = static_cast(comment->Get("entry_type")); - service->AddComment(static_cast(type), comment->Get("author"), - comment->Get("text"), comment->Get("expire_time"), comment->Get("id"), sender->GetName()); + service->AddComment(comment->GetEntryType(), comment->GetAuthor(), + comment->GetText(), comment->GetExpireTime(), comment->GetId(), sender->GetName()); AsyncRelayMessage(sender, message, true); } else if (message->Get("method") == "cluster::RemoveComment") { @@ -1250,12 +1249,12 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona return; } - Dictionary::Ptr downtime = params->Get("downtime"); + Downtime::Ptr downtime = params->Get("downtime"); - service->AddDowntime(downtime->Get("comment_id"), - downtime->Get("start_time"), downtime->Get("end_time"), - downtime->Get("fixed"), downtime->Get("triggered_by"), - downtime->Get("duration"), downtime->Get("id"), sender->GetName()); + service->AddDowntime(downtime->GetAuthor(), downtime->GetComment(), + downtime->GetStartTime(), downtime->GetEndTime(), + downtime->GetFixed(), downtime->GetTriggeredBy(), + downtime->GetDuration(), downtime->GetId(), sender->GetName()); AsyncRelayMessage(sender, message, true); } else if (message->Get("method") == "cluster::RemoveDowntime") { diff --git a/components/cluster/clusterlistener.h b/components/cluster/clusterlistener.h index ea6fc6289..e3fac529c 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); @@ -92,10 +92,10 @@ private: void EnablePassiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority); void EnableNotificationsChangedHandler(const Service::Ptr& service, bool enabled, const String& authority); void EnableFlappingChangedHandler(const Service::Ptr& service, bool enabled, const String& authority); - void CommentAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority); - void CommentRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority); - void DowntimeAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority); - void DowntimeRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority); + void CommentAddedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority); + void CommentRemovedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority); + void DowntimeAddedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority); + void DowntimeRemovedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority); void AcknowledgementSetHandler(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority); void AcknowledgementClearedHandler(const Service::Ptr& service, 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..008e6b96a 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"); @@ -147,7 +147,7 @@ void CompatLogger::CheckResultHandler(const Service::Ptr& service, const Diction /** * @threadsafety Always. */ -void CompatLogger::TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime) +void CompatLogger::TriggerDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime) { Host::Ptr host = service->GetHost(); @@ -193,7 +193,7 @@ void CompatLogger::TriggerDowntimeHandler(const Service::Ptr& service, const Dic /** * @threadsafety Always. */ -void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime) +void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime) { Host::Ptr host = service->GetHost(); @@ -206,7 +206,7 @@ void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Dict String downtime_output; String downtime_state_str; - if (downtime->Get("was_cancelled") == true) { + if (downtime->GetWasCancelled()) { downtime_output = "Scheduled downtime for service has been cancelled."; downtime_state_str = "CANCELLED"; } else { @@ -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..fb99f2639 100644 --- a/components/compat/compatlogger.h +++ b/components/compat/compatlogger.h @@ -52,14 +52,13 @@ private: void WriteLine(const String& line); void Flush(void); - void CheckResultHandler(const Service::Ptr& service, const Dictionary::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 CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr); + 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 Downtime::Ptr& downtime); + void RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::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/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index cb69a0998..a8c384d7a 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -76,9 +76,9 @@ void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; if (type == CompatTypeHost) @@ -88,14 +88,14 @@ void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, << "\t" << "service_description=" << owner->GetShortName() << "\n"; fp << "\t" << "host_name=" << host->GetName() << "\n" - << "\t" << "comment_id=" << static_cast(comment->Get("legacy_id")) << "\n" - << "\t" << "entry_time=" << static_cast(comment->Get("entry_time")) << "\n" - << "\t" << "entry_type=" << static_cast(comment->Get("entry_type")) << "\n" + << "\t" << "comment_id=" << comment->GetLegacyId() << "\n" + << "\t" << "entry_time=" << comment->GetEntryTime() << "\n" + << "\t" << "entry_type=" << comment->GetEntryType() << "\n" << "\t" << "persistent=" << 1 << "\n" - << "\t" << "author=" << static_cast(comment->Get("author")) << "\n" - << "\t" << "comment_data=" << static_cast(comment->Get("text")) << "\n" - << "\t" << "expires=" << (static_cast(comment->Get("expire_time")) != 0 ? 1 : 0) << "\n" - << "\t" << "expire_time=" << static_cast(comment->Get("expire_time")) << "\n" + << "\t" << "author=" << comment->GetAuthor() << "\n" + << "\t" << "comment_data=" << comment->GetText() << "\n" + << "\t" << "expires=" << (comment->GetExpireTime() != 0 ? 1 : 0) << "\n" + << "\t" << "expire_time=" << comment->GetExpireTime() << "\n" << "\t" << "}" << "\n" << "\n"; } @@ -175,9 +175,9 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner ObjectLock olock(downtimes); String id; - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; if (type == CompatTypeHost) @@ -186,23 +186,23 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner fp << "servicedowntime {" << "\n" << "\t" << "service_description=" << owner->GetShortName() << "\n"; - Dictionary::Ptr triggeredByObj = Service::GetDowntimeByID(downtime->Get("triggered_by")); + Downtime::Ptr triggeredByObj = Service::GetDowntimeByID(downtime->GetTriggeredBy()); int triggeredByLegacy = 0; if (triggeredByObj) - triggeredByLegacy = triggeredByObj->Get("legacy_id"); + triggeredByLegacy = triggeredByObj->GetLegacyId(); fp << "\t" << "host_name=" << host->GetName() << "\n" - << "\t" << "downtime_id=" << static_cast(downtime->Get("legacy_id")) << "\n" - << "\t" << "entry_time=" << static_cast(downtime->Get("entry_time")) << "\n" - << "\t" << "start_time=" << static_cast(downtime->Get("start_time")) << "\n" - << "\t" << "end_time=" << static_cast(downtime->Get("end_time")) << "\n" + << "\t" << "downtime_id=" << downtime->GetLegacyId() << "\n" + << "\t" << "entry_time=" << downtime->GetEntryTime() << "\n" + << "\t" << "start_time=" << downtime->GetStartTime() << "\n" + << "\t" << "end_time=" << downtime->GetEndTime() << "\n" << "\t" << "triggered_by=" << triggeredByLegacy << "\n" - << "\t" << "fixed=" << static_cast(downtime->Get("fixed")) << "\n" - << "\t" << "duration=" << static_cast(downtime->Get("duration")) << "\n" - << "\t" << "is_in_effect=" << (Service::IsDowntimeActive(downtime) ? 1 : 0) << "\n" - << "\t" << "author=" << static_cast(downtime->Get("author")) << "\n" - << "\t" << "comment=" << static_cast(downtime->Get("comment")) << "\n" - << "\t" << "trigger_time=" << static_cast(downtime->Get("trigger_time")) << "\n" + << "\t" << "fixed=" << static_cast(downtime->GetFixed()) << "\n" + << "\t" << "duration=" << static_cast(downtime->GetDuration()) << "\n" + << "\t" << "is_in_effect=" << (downtime->IsActive() ? 1 : 0) << "\n" + << "\t" << "author=" << downtime->GetAuthor() << "\n" + << "\t" << "comment=" << downtime->GetComment() << "\n" + << "\t" << "trigger_time=" << downtime->GetTriggerTime() << "\n" << "\t" << "}" << "\n" << "\n"; } diff --git a/components/livestatus/commentstable.cpp b/components/livestatus/commentstable.cpp index f261911f2..f58d55367 100644 --- a/components/livestatus/commentstable.cpp +++ b/components/livestatus/commentstable.cpp @@ -78,42 +78,42 @@ Object::Ptr CommentsTable::ServiceAccessor(const Value& row, const Column::Objec Value CommentsTable::AuthorAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("author"); + return comment->GetAuthor(); } Value CommentsTable::CommentAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("text"); + return comment->GetText(); } Value CommentsTable::IdAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("legacy_id"); + return comment->GetLegacyId(); } Value CommentsTable::EntryTimeAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return static_cast(comment->Get("entry_time")); + return static_cast(comment->GetEntryTime()); } Value CommentsTable::TypeAccessor(const Value& row) @@ -138,30 +138,30 @@ Value CommentsTable::IsServiceAccessor(const Value& row) Value CommentsTable::EntryTypeAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("entry_type"); + return comment->GetEntryType(); } Value CommentsTable::ExpiresAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("expires"); + return comment->GetExpireTime() != 0; } Value CommentsTable::ExpireTimeAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return static_cast(comment->Get("expire_time")); + return static_cast(comment->GetExpireTime()); } diff --git a/components/livestatus/downtimestable.cpp b/components/livestatus/downtimestable.cpp index adb991719..c046a8331 100644 --- a/components/livestatus/downtimestable.cpp +++ b/components/livestatus/downtimestable.cpp @@ -78,37 +78,37 @@ Object::Ptr DowntimesTable::ServiceAccessor(const Value& row, const Column::Obje Value DowntimesTable::AuthorAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return downtime->Get("author"); + return downtime->GetAuthor(); } Value DowntimesTable::CommentAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return downtime->Get("comment"); + return downtime->GetComment(); } Value DowntimesTable::IdAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return downtime->Get("legacy_id"); + return downtime->GetLegacyId(); } Value DowntimesTable::EntryTimeAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return static_cast(downtime->Get("entry_time")); + return static_cast(downtime->GetEntryTime()); } Value DowntimesTable::TypeAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); // 1 .. active, 0 .. pending - return (Service::IsDowntimeActive(downtime) ? 1 : 0); + return (downtime->IsActive() ? 1 : 0); } Value DowntimesTable::IsServiceAccessor(const Value& row) @@ -120,35 +120,35 @@ Value DowntimesTable::IsServiceAccessor(const Value& row) Value DowntimesTable::StartTimeAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return static_cast(downtime->Get("start_time")); + return static_cast(downtime->GetStartTime()); } Value DowntimesTable::EndTimeAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return static_cast(downtime->Get("end_time")); + return static_cast(downtime->GetEndTime()); } Value DowntimesTable::FixedAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return downtime->Get("fixed"); + return downtime->GetFixed(); } Value DowntimesTable::DurationAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return downtime->Get("duration"); + return downtime->GetDuration(); } Value DowntimesTable::TriggeredByAccessor(const Value& row) { - Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + Downtime::Ptr downtime = Service::GetDowntimeByID(row); - return downtime->Get("triggered_by"); + return downtime->GetTriggeredBy(); } diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 72663ee93..f517c2d4f 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); @@ -1431,16 +1419,16 @@ Value HostsTable::DowntimesAccessor(const Value& row) ObjectLock olock(downtimes); String id; - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { if (!downtime) continue; - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; - ids->Add(downtime->Get("legacy_id")); + ids->Add(downtime->GetLegacyId()); } return ids; @@ -1466,19 +1454,19 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row) ObjectLock olock(downtimes); String id; - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { if (!downtime) continue; - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; Array::Ptr downtime_info = make_shared(); - downtime_info->Add(downtime->Get("legacy_id")); - downtime_info->Add(downtime->Get("author")); - downtime_info->Add(downtime->Get("comment")); + downtime_info->Add(downtime->GetLegacyId()); + downtime_info->Add(downtime->GetAuthor()); + downtime_info->Add(downtime->GetComment()); ids->Add(downtime_info); } @@ -1505,16 +1493,16 @@ Value HostsTable::CommentsAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; - ids->Add(comment->Get("legacy_id")); + ids->Add(comment->GetLegacyId()); } return ids; @@ -1540,19 +1528,19 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; Array::Ptr comment_info = make_shared(); - comment_info->Add(comment->Get("legacy_id")); - comment_info->Add(comment->Get("author")); - comment_info->Add(comment->Get("text")); + comment_info->Add(comment->GetLegacyId()); + comment_info->Add(comment->GetAuthor()); + comment_info->Add(comment->GetText()); ids->Add(comment_info); } @@ -1579,21 +1567,21 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; Array::Ptr comment_info = make_shared(); - comment_info->Add(comment->Get("legacy_id")); - comment_info->Add(comment->Get("author")); - comment_info->Add(comment->Get("text")); - comment_info->Add(comment->Get("entry_type")); - comment_info->Add(static_cast(comment->Get("entry_time"))); + comment_info->Add(comment->GetLegacyId()); + comment_info->Add(comment->GetAuthor()); + comment_info->Add(comment->GetText()); + comment_info->Add(comment->GetEntryType()); + comment_info->Add(static_cast(comment->GetEntryTime())); ids->Add(comment_info); } @@ -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..26e0868d8 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) @@ -1056,16 +1044,16 @@ Value ServicesTable::DowntimesAccessor(const Value& row) ObjectLock olock(downtimes); String id; - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { if (!downtime) continue; - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; - ids->Add(downtime->Get("legacy_id")); + ids->Add(downtime->GetLegacyId()); } return ids; @@ -1085,19 +1073,19 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row) ObjectLock olock(downtimes); String id; - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { if (!downtime) continue; - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; Array::Ptr downtime_info = make_shared(); - downtime_info->Add(downtime->Get("legacy_id")); - downtime_info->Add(downtime->Get("author")); - downtime_info->Add(downtime->Get("comment")); + downtime_info->Add(downtime->GetLegacyId()); + downtime_info->Add(downtime->GetAuthor()); + downtime_info->Add(downtime->GetComment()); ids->Add(downtime_info); } @@ -1118,16 +1106,16 @@ Value ServicesTable::CommentsAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; - ids->Add(comment->Get("legacy_id")); + ids->Add(comment->GetLegacyId()); } return ids; @@ -1147,19 +1135,19 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; Array::Ptr comment_info = make_shared(); - comment_info->Add(comment->Get("legacy_id")); - comment_info->Add(comment->Get("author")); - comment_info->Add(comment->Get("text")); + comment_info->Add(comment->GetLegacyId()); + comment_info->Add(comment->GetAuthor()); + comment_info->Add(comment->GetText()); ids->Add(comment_info); } @@ -1180,21 +1168,21 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; Array::Ptr comment_info = make_shared(); - comment_info->Add(comment->Get("legacy_id")); - comment_info->Add(comment->Get("author")); - comment_info->Add(comment->Get("text")); - comment_info->Add(comment->Get("entry_type")); - comment_info->Add(static_cast(comment->Get("entry_time"))); + comment_info->Add(comment->GetLegacyId()); + comment_info->Add(comment->GetAuthor()); + comment_info->Add(comment->GetText()); + comment_info->Add(comment->GetEntryType()); + comment_info->Add(static_cast(comment->GetEntryTime())); ids->Add(comment_info); } 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/base/serializer.cpp b/lib/base/serializer.cpp index 270e6f738..449222ce6 100644 --- a/lib/base/serializer.cpp +++ b/lib/base/serializer.cpp @@ -175,7 +175,11 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary if (!input->Contains(field.Name)) continue; - instance->SetField(i, Deserialize(input->Get(field.Name), attributeTypes)); + try { + instance->SetField(i, Deserialize(input->Get(field.Name), attributeTypes)); + } catch (const std::exception&) { + instance->SetField(i, Empty); + } } return instance; diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 24611b8e9..6c3b95c96 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -371,23 +371,23 @@ void ServiceDbObject::AddComments(const Service::Ptr& service) ObjectLock olock(comments); String comment_id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(comment_id, comment), comments) { AddComment(service, comment); } } -void ServiceDbObject::AddComment(const Service::Ptr& service, const Dictionary::Ptr& comment) +void ServiceDbObject::AddComment(const Service::Ptr& service, const Comment::Ptr& comment) { AddCommentInternal(service, comment, false); } -void ServiceDbObject::AddCommentHistory(const Service::Ptr& service, const Dictionary::Ptr& comment) +void ServiceDbObject::AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment) { AddCommentInternal(service, comment, true); } -void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Dictionary::Ptr& comment, bool historical) +void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical) { Host::Ptr host = service->GetHost(); @@ -399,48 +399,48 @@ void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Dict return; } - Log(LogDebug, "db_ido", "adding service comment (id = " + comment->Get("legacy_id") + ") for '" + service->GetName() + "'"); + Log(LogDebug, "db_ido", "adding service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + service->GetName() + "'"); /* add the service comment */ AddCommentByType(service, comment, historical); /* add the hostcheck service comment to the host as well */ if (host->GetCheckService() == service) { - Log(LogDebug, "db_ido", "adding host comment (id = " + comment->Get("legacy_id") + ") for '" + host->GetName() + "'"); + Log(LogDebug, "db_ido", "adding host comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + host->GetName() + "'"); AddCommentByType(host, comment, historical); } } -void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& comment, bool historical) +void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical) { - unsigned long entry_time = static_cast(comment->Get("entry_time")); - unsigned long entry_time_usec = (comment->Get("entry_time") - entry_time) * 1000 * 1000; + unsigned long entry_time = static_cast(comment->GetEntryTime()); + unsigned long entry_time_usec = (comment->GetEntryTime() - entry_time) * 1000 * 1000; Dictionary::Ptr fields1 = make_shared(); fields1->Set("entry_time", DbValue::FromTimestamp(entry_time)); fields1->Set("entry_time_usec", entry_time_usec); - fields1->Set("entry_type", comment->Get("entry_type")); + fields1->Set("entry_type", comment->GetEntryType()); fields1->Set("object_id", object); if (object->GetType() == DynamicType::GetByName("Host")) { fields1->Set("comment_type", 2); /* requires idoutils 1.10 schema fix */ - fields1->Set("internal_comment_id", comment->Get("legacy_id")); + fields1->Set("internal_comment_id", comment->GetLegacyId()); } else if (object->GetType() == DynamicType::GetByName("Service")) { fields1->Set("comment_type", 1); - fields1->Set("internal_comment_id", comment->Get("legacy_id")); + fields1->Set("internal_comment_id", comment->GetLegacyId()); } else { Log(LogDebug, "db_ido", "unknown object type for adding comment."); return; } fields1->Set("comment_time", DbValue::FromTimestamp(entry_time)); /* same as entry_time */ - fields1->Set("author_name", comment->Get("author")); - fields1->Set("comment_data", comment->Get("text")); + fields1->Set("author_name", comment->GetAuthor()); + fields1->Set("comment_data", comment->GetText()); fields1->Set("is_persistent", 1); fields1->Set("comment_source", 1); /* external */ - fields1->Set("expires", (comment->Get("expire_time") > 0) ? 1 : 0); - fields1->Set("expiration_time", comment->Get("expire_time")); + fields1->Set("expires", (comment->GetExpireTime() > 0) ? 1 : 0); + fields1->Set("expiration_time", comment->GetExpireTime()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbQuery query1; @@ -479,7 +479,7 @@ void ServiceDbObject::RemoveComments(const Service::Ptr& service) } } -void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionary::Ptr& comment) +void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Comment::Ptr& comment) { Host::Ptr host = service->GetHost(); @@ -491,7 +491,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar return; } - Log(LogDebug, "db_ido", "removing service comment (id = " + comment->Get("legacy_id") + ") for '" + service->GetName() + "'"); + Log(LogDebug, "db_ido", "removing service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + service->GetName() + "'"); /* Status */ DbQuery query1; @@ -500,7 +500,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar query1.Category = DbCatComment; query1.WhereCriteria = make_shared(); query1.WhereCriteria->Set("object_id", service); - query1.WhereCriteria->Set("internal_comment_id", comment->Get("legacy_id")); + query1.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId()); OnQuery(query1); /* delete hostcheck service's host comments */ @@ -510,7 +510,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar } /* History - update deletion time for service (and host in case) */ - unsigned long entry_time = static_cast(comment->Get("entry_time")); + unsigned long entry_time = static_cast(comment->GetEntryTime()); double now = Utility::GetTime(); Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now); @@ -526,7 +526,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar query2.Fields = fields2; query2.WhereCriteria = make_shared(); - query2.WhereCriteria->Set("internal_comment_id", comment->Get("legacy_id")); + query2.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId()); query2.WhereCriteria->Set("comment_time", DbValue::FromTimestamp(entry_time)); query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -542,23 +542,23 @@ void ServiceDbObject::AddDowntimes(const Service::Ptr& service) ObjectLock olock(downtimes); String downtime_id; - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(downtime_id, downtime), downtimes) { AddDowntime(service, downtime); } } -void ServiceDbObject::AddDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime) +void ServiceDbObject::AddDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime) { AddDowntimeInternal(service, downtime, false); } -void ServiceDbObject::AddDowntimeHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime) +void ServiceDbObject::AddDowntimeHistory(const Service::Ptr& service, const Downtime::Ptr& downtime) { AddDowntimeInternal(service, downtime, true); } -void ServiceDbObject::AddDowntimeInternal(const Service::Ptr& service, const Dictionary::Ptr& downtime, bool historical) +void ServiceDbObject::AddDowntimeInternal(const Service::Ptr& service, const Downtime::Ptr& downtime, bool historical) { Host::Ptr host = service->GetHost(); @@ -570,47 +570,47 @@ void ServiceDbObject::AddDowntimeInternal(const Service::Ptr& service, const Dic return; } - Log(LogDebug, "db_ido", "adding service downtime (id = " + downtime->Get("legacy_id") + ") for '" + service->GetName() + "'"); + Log(LogDebug, "db_ido", "adding service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'"); /* add the service downtime */ AddDowntimeByType(service, downtime, historical); /* add the hostcheck service downtime to the host as well */ if (host->GetCheckService() == service) { - Log(LogDebug, "db_ido", "adding host downtime (id = " + downtime->Get("legacy_id") + ") for '" + host->GetName() + "'"); + Log(LogDebug, "db_ido", "adding host downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + host->GetName() + "'"); AddDowntimeByType(host, downtime, historical); } } -void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& downtime, bool historical) +void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const Downtime::Ptr& downtime, bool historical) { Dictionary::Ptr fields1 = make_shared(); - fields1->Set("entry_time", DbValue::FromTimestamp(downtime->Get("entry_time"))); + fields1->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime())); fields1->Set("object_id", object); if (object->GetType() == DynamicType::GetByName("Host")) { fields1->Set("downtime_type", 2); /* requires idoutils 1.10 schema fix */ - fields1->Set("internal_downtime_id", downtime->Get("legacy_id")); + fields1->Set("internal_downtime_id", downtime->GetLegacyId()); } else if (object->GetType() == DynamicType::GetByName("Service")) { fields1->Set("downtime_type", 1); - fields1->Set("internal_downtime_id", downtime->Get("legacy_id")); + fields1->Set("internal_downtime_id", downtime->GetLegacyId()); } else { Log(LogDebug, "db_ido", "unknown object type for adding downtime."); return; } - fields1->Set("author_name", downtime->Get("author")); - fields1->Set("triggered_by_id", downtime->Get("triggered_by")); - fields1->Set("is_fixed", downtime->Get("is_fixed")); - fields1->Set("duration", downtime->Get("duration")); - fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->Get("start_time"))); - fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->Get("end_time"))); + fields1->Set("author_name", downtime->GetAuthor()); + fields1->Set("triggered_by_id", downtime->GetTriggeredBy()); + 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())); fields1->Set("was_started", Empty); fields1->Set("actual_start_time", Empty); fields1->Set("actual_start_time_usec", Empty); fields1->Set("is_in_effect", Empty); - fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time"))); + fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbQuery query1; @@ -649,7 +649,7 @@ void ServiceDbObject::RemoveDowntimes(const Service::Ptr& service) } } -void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime) +void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime) { Host::Ptr host = service->GetHost(); @@ -661,7 +661,7 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona return; } - Log(LogDebug, "db_ido", "removing service downtime (id = " + downtime->Get("legacy_id") + ") for '" + service->GetName() + "'"); + Log(LogDebug, "db_ido", "removing service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'"); /* Status */ DbQuery query1; @@ -670,7 +670,7 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona query1.Category = DbCatDowntime; query1.WhereCriteria = make_shared(); query1.WhereCriteria->Set("object_id", service); - query1.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id")); + query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId()); OnQuery(query1); /* delete hostcheck service's host comments */ @@ -689,22 +689,22 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona query3.Category = DbCatDowntime; Dictionary::Ptr fields3 = make_shared(); - fields3->Set("was_cancelled", downtime->Get("was_cancelled") ? 1 : 0); + fields3->Set("was_cancelled", downtime->GetWasCancelled() ? 1 : 0); fields3->Set("actual_end_time", DbValue::FromTimestamp(time_bag->Get("time_sec"))); fields3->Set("actual_end_time_usec", time_bag->Get("time_usec")); query3.Fields = fields3; query3.WhereCriteria = make_shared(); - query3.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id")); - query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->Get("entry_time"))); - query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->Get("start_time"))); - query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->Get("end_time"))); + query3.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId()); + query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime())); + query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); + query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ OnQuery(query3); } -void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime) +void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime) { Host::Ptr host = service->GetHost(); @@ -716,7 +716,7 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction return; } - Log(LogDebug, "db_ido", "updating triggered service downtime (id = " + downtime->Get("legacy_id") + ") for '" + service->GetName() + "'"); + Log(LogDebug, "db_ido", "updating triggered service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'"); double now = Utility::GetTime(); Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now); @@ -732,12 +732,12 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag->Get("time_sec"))); fields1->Set("actual_start_time_usec", time_bag->Get("time_usec")); fields1->Set("is_in_effect", 1); - fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time"))); + fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ query1.WhereCriteria = make_shared(); query1.WhereCriteria->Set("object_id", service); - query1.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id")); + query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId()); query1.Fields = fields1; OnQuery(query1); @@ -759,14 +759,14 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction fields3->Set("is_in_effect", 1); fields3->Set("actual_start_time", DbValue::FromTimestamp(time_bag->Get("time_sec"))); fields3->Set("actual_start_time_usec", time_bag->Get("time_usec")); - fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time"))); + fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); query3.Fields = fields3; query3.WhereCriteria = make_shared(); - query3.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id")); - query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->Get("entry_time"))); - query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->Get("start_time"))); - query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->Get("end_time"))); + query3.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId()); + query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime())); + query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); + query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ OnQuery(query3); @@ -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: " @@ -1056,7 +1056,7 @@ void ServiceDbObject::AddCheckResultLogHistory(const Service::Ptr& service, cons } } -void ServiceDbObject::AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime) +void ServiceDbObject::AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime) { Host::Ptr host = service->GetHost(); @@ -1088,7 +1088,7 @@ void ServiceDbObject::AddTriggerDowntimeLogHistory(const Service::Ptr& service, } } -void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime) +void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime) { Host::Ptr host = service->GetHost(); @@ -1101,7 +1101,7 @@ void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, c String downtime_output; String downtime_state_str; - if (downtime->Get("was_cancelled") == true) { + if (downtime->GetWasCancelled()) { downtime_output = "Scheduled downtime for service has been cancelled."; downtime_state_str = "CANCELLED"; } else { @@ -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..06e3f113a 100644 --- a/lib/db_ido/servicedbobject.h +++ b/lib/db_ido/servicedbobject.h @@ -75,42 +75,42 @@ protected: virtual void OnStatusUpdate(void); private: - static void AddCommentInternal(const Service::Ptr& service, const Dictionary::Ptr& comment, bool historical); - static void AddCommentByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& comment, bool historical); + static void AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical); + static void AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical); static void AddComments(const Service::Ptr& service); static void RemoveComments(const Service::Ptr& service); - static void AddDowntimeInternal(const Service::Ptr& service, const Dictionary::Ptr& downtime, bool historical); - static void AddDowntimeByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& downtime, bool historical); + static void AddDowntimeInternal(const Service::Ptr& service, const Downtime::Ptr& downtime, bool historical); + static void AddDowntimeByType(const DynamicObject::Ptr& object, const Downtime::Ptr& downtime, bool historical); static void AddDowntimes(const Service::Ptr& service); static void RemoveDowntimes(const Service::Ptr& service); static void AddLogHistory(const Service::Ptr& service, String buffer, LogEntryType type); /* Status */ - static void AddComment(const Service::Ptr& service, const Dictionary::Ptr& comment); - static void RemoveComment(const Service::Ptr& service, const Dictionary::Ptr& comment); + static void AddComment(const Service::Ptr& service, const Comment::Ptr& comment); + static void RemoveComment(const Service::Ptr& service, const Comment::Ptr& comment); - static void AddDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime); - static void RemoveDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime); - static void TriggerDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime); + static void AddDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime); + static void RemoveDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime); + static void TriggerDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime); /* History */ - static void AddCommentHistory(const Service::Ptr& service, const Dictionary::Ptr& comment); - static void AddDowntimeHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime); + static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment); + static void AddDowntimeHistory(const Service::Ptr& service, const Downtime::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 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 AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr); + static void AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime); + static void AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime); + 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..853743d32 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -16,8 +16,11 @@ # 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(comment.ti comment.th) mkclass_target(domain.ti domain.th) +mkclass_target(downtime.ti downtime.th) mkclass_target(eventcommand.ti eventcommand.th) mkclass_target(hostgroup.ti hostgroup.th) mkclass_target(host.ti host.th) @@ -34,16 +37,17 @@ 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 + api.cpp api.h checkcommand.cpp checkcommand.th checkresult.cpp checkresult.th + cib.cpp command.cpp command.th comment.cpp comment.th compatutility.cpp + domain.cpp domain.th downtime.cpp downtime.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 - servicegroup.cpp servicegroup.th service-notification.cpp timeperiod.cpp - timeperiod.th user.cpp user.th usergroup.cpp usergroup.th icinga-type.cpp + 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 servicegroup.cpp servicegroup.th + service-notification.cpp timeperiod.cpp timeperiod.th user.cpp user.th + usergroup.cpp usergroup.th icinga-type.cpp ) target_link_libraries(icinga ${Boost_LIBRARIES} base config) 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/comment.cpp b/lib/icinga/comment.cpp new file mode 100644 index 000000000..b6e3f61b4 --- /dev/null +++ b/lib/icinga/comment.cpp @@ -0,0 +1,33 @@ +/****************************************************************************** + * 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/comment.h" +#include "base/utility.h" +#include "base/dynamictype.h" + +using namespace icinga; + +REGISTER_TYPE(Comment); + +bool Comment::IsExpired(void) const +{ + double expire_time = GetExpireTime(); + + return (expire_time != 0 && expire_time < Utility::GetTime()); +} diff --git a/lib/icinga/comment.h b/lib/icinga/comment.h new file mode 100644 index 000000000..0e042c692 --- /dev/null +++ b/lib/icinga/comment.h @@ -0,0 +1,44 @@ +/****************************************************************************** + * 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 COMMENT_H +#define COMMENT_H + +#include "icinga/i2-icinga.h" +#include "icinga/comment.th" + +namespace icinga +{ + +/** + * A service comment. + * + * @ingroup icinga + */ +class I2_ICINGA_API Comment : public ObjectImpl +{ +public: + DECLARE_PTR_TYPEDEFS(Comment); + + bool IsExpired(void) const; +}; + +} + +#endif /* COMMENT_H */ diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti new file mode 100644 index 000000000..955832baf --- /dev/null +++ b/lib/icinga/comment.ti @@ -0,0 +1,30 @@ +namespace icinga +{ + +code {{{ +/** + * The type of a service comment. + * + * @ingroup icinga + */ +enum CommentType +{ + CommentUser = 1, + CommentDowntime = 2, + CommentFlapping = 3, + CommentAcknowledgement = 4 +}; +}}} + +class Comment +{ + [state] String id; + [state] double entry_time; + [state, enum] CommentType entry_type; + [state] String author; + [state] String text; + [state] double expire_time; + [state] int legacy_id; +}; + +} 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/downtime.cpp b/lib/icinga/downtime.cpp new file mode 100644 index 000000000..f6d6175b2 --- /dev/null +++ b/lib/icinga/downtime.cpp @@ -0,0 +1,59 @@ +/****************************************************************************** + * 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/downtime.h" +#include "base/utility.h" +#include "base/dynamictype.h" + +using namespace icinga; + +REGISTER_TYPE(Downtime); + +bool Downtime::IsActive(void) const +{ + double now = Utility::GetTime(); + + if (now < GetStartTime() || + now > GetEndTime()) + return false; + + if (GetFixed()) + return true; + + double triggerTime = GetTriggerTime(); + + if (triggerTime == 0) + return false; + + return (triggerTime + GetDuration() < now); +} + +bool Downtime::IsTriggered(void) const +{ + double now = Utility::GetTime(); + + double triggerTime = GetTriggerTime(); + + return (triggerTime > 0 && triggerTime <= now); +} + +bool Downtime::IsExpired(void) const +{ + return (GetEndTime() < Utility::GetTime()); +} diff --git a/lib/icinga/downtime.h b/lib/icinga/downtime.h new file mode 100644 index 000000000..0f702bba4 --- /dev/null +++ b/lib/icinga/downtime.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * 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 DOWNTIME_H +#define DOWNTIME_H + +#include "icinga/i2-icinga.h" +#include "icinga/downtime.th" + +namespace icinga +{ + +/** + * A service downtime. + * + * @ingroup icinga + */ +class I2_ICINGA_API Downtime : public ObjectImpl +{ +public: + DECLARE_PTR_TYPEDEFS(Downtime); + + bool IsActive(void) const; + bool IsTriggered(void) const; + bool IsExpired(void) const; + +}; + +} + +#endif /* DOWNTIME_H */ diff --git a/lib/icinga/downtime.ti b/lib/icinga/downtime.ti new file mode 100644 index 000000000..e26014a58 --- /dev/null +++ b/lib/icinga/downtime.ti @@ -0,0 +1,23 @@ +namespace icinga +{ + +class Downtime +{ + [state] String id; + [state] double entry_time; + [state] String author; + [state] String comment; + [state] double start_time; + [state] double end_time; + [state] double trigger_time; + [state] bool fixed; + [state] double duration; + [state] String triggered_by; + [state] Dictionary::Ptr triggers { + default {{{ return make_shared(); }}} + }; + [state] int legacy_id; + [state] bool was_cancelled; +}; + +} diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 2a40a128f..dfd22d773 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); @@ -1009,8 +1009,7 @@ void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vectorGetName()); - String comment_id = service->AddComment(CommentDowntime, arguments[7], arguments[8], Convert::ToDouble(arguments[3])); - (void) service->AddDowntime(comment_id, + (void) service->AddDowntime(arguments[7], arguments[8], Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]), Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6])); } @@ -1044,8 +1043,7 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vectorGetName()); Service::Ptr service = host->GetCheckService(); if (service) { - String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2])); - (void) service->AddDowntime(comment_id, + (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } @@ -1079,8 +1077,7 @@ void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); - String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2])); - (void) service->AddDowntime(comment_id, + (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } @@ -1105,8 +1102,7 @@ void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std:: Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName()); Service::Ptr service = host->GetCheckService(); if (service) { - String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2])); - (void) service->AddDowntime(comment_id, + (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } @@ -1142,8 +1138,7 @@ void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::v BOOST_FOREACH(const Service::Ptr& service, services) { Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); - String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2])); - (void) service->AddDowntime(comment_id, + (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } @@ -1179,8 +1174,7 @@ void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const st BOOST_FOREACH(const Service::Ptr& service, services) { Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); - String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2])); - (void) service->AddDowntime(comment_id, + (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } @@ -1203,8 +1197,7 @@ void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); - String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2])); - (void) service->AddDowntime(comment_id, + (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } 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-comment.cpp b/lib/icinga/service-comment.cpp index 775e2ed3b..e07f2a08e 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -34,8 +34,8 @@ static std::map l_LegacyCommentsCache; static std::map l_CommentsCache; static Timer::Ptr l_CommentsExpireTimer; -boost::signals2::signal Service::OnCommentAdded; -boost::signals2::signal Service::OnCommentRemoved; +boost::signals2::signal Service::OnCommentAdded; +boost::signals2::signal Service::OnCommentRemoved; int Service::GetNextCommentID(void) { @@ -54,13 +54,13 @@ String Service::AddComment(CommentType entryType, const String& author, else uid = id; - Dictionary::Ptr comment = make_shared(); - comment->Set("id", uid); - comment->Set("entry_time", Utility::GetTime()); - comment->Set("entry_type", entryType); - comment->Set("author", author); - comment->Set("text", text); - comment->Set("expire_time", expireTime); + Comment::Ptr comment = make_shared(); + comment->SetId(uid);; + comment->SetEntryTime(Utility::GetTime()); + comment->SetEntryType(entryType); + comment->SetAuthor(author); + comment->SetText(text); + comment->SetExpireTime(expireTime); int legacy_id; @@ -69,7 +69,7 @@ String Service::AddComment(CommentType entryType, const String& author, legacy_id = l_NextCommentID++; } - comment->Set("legacy_id", legacy_id); + comment->SetLegacyId(legacy_id); GetComments()->Set(uid, comment); @@ -111,12 +111,12 @@ void Service::RemoveComment(const String& id, const String& authority) ObjectLock olock(owner); - Dictionary::Ptr comment = comments->Get(id); + Comment::Ptr comment = comments->Get(id); if (!comment) return; - int legacy_id = comment->Get("legacy_id"); + int legacy_id = comment->GetLegacyId(); comments->Remove(id); @@ -148,26 +148,19 @@ Service::Ptr Service::GetOwnerByCommentID(const String& id) return l_CommentsCache[id].lock(); } -Dictionary::Ptr Service::GetCommentByID(const String& id) +Comment::Ptr Service::GetCommentByID(const String& id) { Service::Ptr owner = GetOwnerByCommentID(id); if (!owner) - return Dictionary::Ptr(); + return Comment::Ptr(); Dictionary::Ptr comments = owner->GetComments(); if (comments) return comments->Get(id); - return Dictionary::Ptr(); -} - -bool Service::IsCommentExpired(const Dictionary::Ptr& comment) -{ - double expire_time = comment->Get("expire_time"); - - return (expire_time != 0 && expire_time < Utility::GetTime()); + return Comment::Ptr(); } void Service::AddCommentsToCache(void) @@ -181,9 +174,9 @@ void Service::AddCommentsToCache(void) boost::mutex::scoped_lock lock(l_CommentMutex); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { - int legacy_id = comment->Get("legacy_id"); + int legacy_id = comment->GetLegacyId(); if (legacy_id >= l_NextCommentID) l_NextCommentID = legacy_id + 1; @@ -203,9 +196,9 @@ void Service::RemoveCommentsByType(int type) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { - if (comment->Get("entry_type") == type) + if (comment->GetEntryType() == type) removedComments.push_back(id); } } @@ -225,9 +218,9 @@ void Service::RemoveExpiredComments(void) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { - if (IsCommentExpired(comment)) + if (comment->IsExpired()) expiredComments.push_back(id); } } diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index 2626457ff..31a06f5e9 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -23,6 +23,7 @@ #include "base/logger_fwd.h" #include "base/timer.h" #include "base/utility.h" +#include "base/convert.h" #include #include @@ -34,9 +35,9 @@ static std::map l_LegacyDowntimesCache; static std::map l_DowntimesCache; static Timer::Ptr l_DowntimesExpireTimer; -boost::signals2::signal Service::OnDowntimeAdded; -boost::signals2::signal Service::OnDowntimeRemoved; -boost::signals2::signal Service::OnDowntimeTriggered; +boost::signals2::signal Service::OnDowntimeAdded; +boost::signals2::signal Service::OnDowntimeRemoved; +boost::signals2::signal Service::OnDowntimeTriggered; int Service::GetNextDowntimeID(void) { @@ -45,7 +46,7 @@ int Service::GetNextDowntimeID(void) return l_NextDowntimeID; } -String Service::AddDowntime(const String& comment_id, +String Service::AddDowntime(const String& author, const String& comment, double startTime, double endTime, bool fixed, const String& triggeredBy, double duration, const String& id, const String& authority) { @@ -56,17 +57,16 @@ String Service::AddDowntime(const String& comment_id, else uid = id; - Dictionary::Ptr downtime = make_shared(); - downtime->Set("id", uid); - downtime->Set("entry_time", Utility::GetTime()); - downtime->Set("comment_id", comment_id); - downtime->Set("start_time", startTime); - downtime->Set("end_time", endTime); - downtime->Set("fixed", fixed); - downtime->Set("duration", duration); - downtime->Set("triggered_by", triggeredBy); - downtime->Set("triggers", make_shared()); - downtime->Set("trigger_time", 0); + Downtime::Ptr downtime = make_shared(); + downtime->SetId(uid); + downtime->SetEntryTime(Utility::GetTime()); + downtime->SetAuthor(author); + downtime->SetComment(comment); + downtime->SetStartTime(startTime); + downtime->SetEndTime(endTime); + downtime->SetFixed(fixed); + downtime->SetDuration(duration); + downtime->SetTriggeredBy(triggeredBy); int legacy_id; @@ -75,13 +75,13 @@ String Service::AddDowntime(const String& comment_id, legacy_id = l_NextDowntimeID++; } - downtime->Set("legacy_id", legacy_id); + downtime->SetLegacyId(legacy_id); if (!triggeredBy.IsEmpty()) { Service::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy); Dictionary::Ptr otherDowntimes = otherOwner->GetDowntimes(); - Dictionary::Ptr otherDowntime = otherDowntimes->Get(triggeredBy); - Dictionary::Ptr triggers = otherDowntime->Get("triggers"); + Downtime::Ptr otherDowntime = otherDowntimes->Get(triggeredBy); + Dictionary::Ptr triggers = otherDowntime->GetTriggers(); { ObjectLock olock(otherOwner); @@ -97,7 +97,7 @@ String Service::AddDowntime(const String& comment_id, l_DowntimesCache[uid] = GetSelf(); } - Log(LogWarning, "icinga", "added downtime with ID '" + downtime->Get("legacy_id") + "'."); + Log(LogWarning, "icinga", "added downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "'."); Utility::QueueAsyncCallback(boost::bind(boost::ref(OnDowntimeAdded), GetSelf(), downtime, authority)); @@ -113,14 +113,12 @@ void Service::RemoveDowntime(const String& id, bool cancelled, const String& aut Dictionary::Ptr downtimes = owner->GetDowntimes(); - Dictionary::Ptr downtime = downtimes->Get(id); + Downtime::Ptr downtime = downtimes->Get(id); if (!downtime) return; - String comment_id = downtime->Get("comment_id"); - - int legacy_id = downtime->Get("legacy_id"); + int legacy_id = downtime->GetLegacyId(); downtimes->Remove(id); @@ -130,11 +128,9 @@ void Service::RemoveDowntime(const String& id, bool cancelled, const String& aut l_DowntimesCache.erase(id); } - RemoveComment(comment_id); + downtime->SetWasCancelled(cancelled); - downtime->Set("was_cancelled", cancelled); - - Log(LogWarning, "icinga", "removed downtime with ID '" + downtime->Get("legacy_id") + "' from service '" + owner->GetName() + "'."); + Log(LogWarning, "icinga", "removed downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "' from service '" + owner->GetName() + "'."); Utility::QueueAsyncCallback(boost::bind(boost::ref(OnDowntimeRemoved), owner, downtime, authority)); } @@ -162,33 +158,27 @@ void Service::TriggerDowntimes(void) void Service::TriggerDowntime(const String& id) { Service::Ptr owner = GetOwnerByDowntimeID(id); - Dictionary::Ptr downtime = GetDowntimeByID(id); + Downtime::Ptr downtime = GetDowntimeByID(id); if (!downtime) return; - if (IsDowntimeActive(downtime) && IsDowntimeTriggered(downtime)) { - Log(LogDebug, "icinga", "Not triggering downtime with ID '" + downtime->Get("legacy_id") + "': already triggered."); + if (downtime->IsActive() && downtime->IsTriggered()) { + Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': already triggered."); return; } - if (IsDowntimeExpired(downtime)) { - Log(LogDebug, "icinga", "Not triggering downtime with ID '" + downtime->Get("legacy_id") + "': expired."); + if (downtime->IsExpired()) { + Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': expired."); return; } - double now = Utility::GetTime(); + Log(LogDebug, "icinga", "Triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "'."); - if (now < downtime->Get("start_time") || - now > downtime->Get("end_time")) - return; + if (downtime->GetTriggerTime() == 0) + downtime->SetTriggerTime(Utility::GetTime()); - Log(LogDebug, "icinga", "Triggering downtime with ID '" + downtime->Get("legacy_id") + "'."); - - if (downtime->Get("trigger_time") == 0) - downtime->Set("trigger_time", now); - - Dictionary::Ptr triggers = downtime->Get("triggers"); + Dictionary::Ptr triggers = downtime->GetTriggers(); ObjectLock olock(triggers); String tid; BOOST_FOREACH(boost::tie(tid, boost::tuples::ignore), triggers) { @@ -216,52 +206,19 @@ Service::Ptr Service::GetOwnerByDowntimeID(const String& id) return l_DowntimesCache[id].lock(); } -Dictionary::Ptr Service::GetDowntimeByID(const String& id) +Downtime::Ptr Service::GetDowntimeByID(const String& id) { Service::Ptr owner = GetOwnerByDowntimeID(id); if (!owner) - return Dictionary::Ptr(); + return Downtime::Ptr(); Dictionary::Ptr downtimes = owner->GetDowntimes(); if (downtimes) return downtimes->Get(id); - return Dictionary::Ptr(); -} - -bool Service::IsDowntimeActive(const Dictionary::Ptr& downtime) -{ - double now = Utility::GetTime(); - - if (now < downtime->Get("start_time") || - now > downtime->Get("end_time")) - return false; - - if (static_cast(downtime->Get("fixed"))) - return true; - - double triggerTime = downtime->Get("trigger_time"); - - if (triggerTime == 0) - return false; - - return (triggerTime + downtime->Get("duration") < now); -} - -bool Service::IsDowntimeTriggered(const Dictionary::Ptr& downtime) -{ - double now = Utility::GetTime(); - - double triggerTime = downtime->Get("trigger_time"); - - return (triggerTime > 0 && triggerTime <= now); -} - -bool Service::IsDowntimeExpired(const Dictionary::Ptr& downtime) -{ - return (downtime->Get("end_time") < Utility::GetTime()); + return Downtime::Ptr(); } void Service::StartDowntimesExpiredTimer(void) @@ -285,9 +242,9 @@ void Service::AddDowntimesToCache(void) ObjectLock olock(downtimes); String id; - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { - int legacy_id = downtime->Get("legacy_id"); + int legacy_id = downtime->GetLegacyId(); if (legacy_id >= l_NextDowntimeID) l_NextDowntimeID = legacy_id + 1; @@ -307,9 +264,9 @@ void Service::RemoveExpiredDowntimes(void) ObjectLock olock(downtimes); String id; - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { - if (IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) expiredDowntimes.push_back(id); } } @@ -332,9 +289,9 @@ bool Service::IsInDowntime(void) const ObjectLock olock(downtimes); - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) { - if (Service::IsDowntimeActive(downtime)) + if (downtime->IsActive()) return true; } @@ -348,9 +305,9 @@ int Service::GetDowntimeDepth(void) const ObjectLock olock(downtimes); - Dictionary::Ptr downtime; + Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) { - if (Service::IsDowntimeActive(downtime)) + if (downtime->IsActive()) downtime_depth++; } 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..1ae8fca8a 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -26,6 +26,8 @@ #include "icinga/host.h" #include "icinga/timeperiod.h" #include "icinga/notification.h" +#include "icinga/comment.h" +#include "icinga/downtime.h" #include "base/i2-base.h" #include "base/array.h" #include @@ -34,31 +36,6 @@ namespace icinga { -/** - * The type of a service comment. - * - * @ingroup icinga - */ -enum CommentType -{ - CommentUser = 1, - CommentDowntime = 2, - CommentFlapping = 3, - CommentAcknowledgement = 4 -}; - -/** - * The state of a service downtime. - * - * @ingroup icinga - */ -enum DowntimeState -{ - DowntimeStarted = 0, - DowntimeCancelled = 1, - DowntimeStopped = 2 -}; - /** * The state of service flapping. * @@ -72,18 +49,6 @@ enum FlappingState FlappingEnabled = 3 }; -/** - * The state of a changed downtime - * - * @ingroup icinga - */ -enum DowntimeChangedType -{ - DowntimeChangedAdded = 0, - DowntimeChangedUpdated = 1, - DowntimeChangedDeleted = 2 -}; - /** * Modified attributes. * @@ -172,16 +137,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,29 +161,29 @@ 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 OnCommentAdded; - static boost::signals2::signal OnCommentRemoved; - static boost::signals2::signal OnDowntimeAdded; - static boost::signals2::signal OnDowntimeRemoved; + 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; + static boost::signals2::signal OnDowntimeRemoved; static boost::signals2::signal OnFlappingChanged; - static boost::signals2::signal OnDowntimeTriggered; + static boost::signals2::signal OnDowntimeTriggered; static boost::signals2::signal OnAcknowledgementSet; 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); int GetDowntimeDepth(void) const; - String AddDowntime(const String& comment_id, + String AddDowntime(const String& author, const String& comment, double startTime, double endTime, bool fixed, const String& triggeredBy, double duration, const String& id = String(), const String& authority = String()); @@ -230,11 +195,7 @@ public: static String GetDowntimeIDFromLegacyID(int id); static Service::Ptr GetOwnerByDowntimeID(const String& id); - static Dictionary::Ptr GetDowntimeByID(const String& id); - - static bool IsDowntimeActive(const Dictionary::Ptr& downtime); - static bool IsDowntimeTriggered(const Dictionary::Ptr& downtime); - static bool IsDowntimeExpired(const Dictionary::Ptr& downtime); + static Downtime::Ptr GetDowntimeByID(const String& id); void StartDowntimesExpiredTimer(void); @@ -253,15 +214,13 @@ public: static String GetCommentIDFromLegacyID(int id); static Service::Ptr GetOwnerByCommentID(const String& id); - static Dictionary::Ptr GetCommentByID(const String& id); - - static bool IsCommentExpired(const Dictionary::Ptr& comment); + static Comment::Ptr GetCommentByID(const String& id); /* Notifications */ 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);