diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index 4aca33446..a8c384d7a 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -78,7 +78,7 @@ void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, String id; Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; if (type == CompatTypeHost) @@ -177,7 +177,7 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner String id; Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; if (type == CompatTypeHost) @@ -199,7 +199,7 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner << "\t" << "triggered_by=" << triggeredByLegacy << "\n" << "\t" << "fixed=" << static_cast(downtime->GetFixed()) << "\n" << "\t" << "duration=" << static_cast(downtime->GetDuration()) << "\n" - << "\t" << "is_in_effect=" << (Service::IsDowntimeActive(downtime) ? 1 : 0) << "\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" diff --git a/components/livestatus/downtimestable.cpp b/components/livestatus/downtimestable.cpp index ab7381cc7..c046a8331 100644 --- a/components/livestatus/downtimestable.cpp +++ b/components/livestatus/downtimestable.cpp @@ -108,7 +108,7 @@ Value DowntimesTable::TypeAccessor(const Value& 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) diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index f8b420980..f517c2d4f 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -1425,7 +1425,7 @@ Value HostsTable::DowntimesAccessor(const Value& row) if (!downtime) continue; - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; ids->Add(downtime->GetLegacyId()); @@ -1460,7 +1460,7 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row) if (!downtime) continue; - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; Array::Ptr downtime_info = make_shared(); @@ -1499,7 +1499,7 @@ Value HostsTable::CommentsAccessor(const Value& row) if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; ids->Add(comment->GetLegacyId()); @@ -1534,7 +1534,7 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row) if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; Array::Ptr comment_info = make_shared(); @@ -1573,7 +1573,7 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row) if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; Array::Ptr comment_info = make_shared(); diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index 0d01fa02e..26e0868d8 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -1050,7 +1050,7 @@ Value ServicesTable::DowntimesAccessor(const Value& row) if (!downtime) continue; - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; ids->Add(downtime->GetLegacyId()); @@ -1079,7 +1079,7 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row) if (!downtime) continue; - if (Service::IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) continue; Array::Ptr downtime_info = make_shared(); @@ -1112,7 +1112,7 @@ Value ServicesTable::CommentsAccessor(const Value& row) if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; ids->Add(comment->GetLegacyId()); @@ -1141,7 +1141,7 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row) if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; Array::Ptr comment_info = make_shared(); @@ -1174,7 +1174,7 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row) if (!comment) continue; - if (Service::IsCommentExpired(comment)) + if (comment->IsExpired()) continue; Array::Ptr comment_info = make_shared(); diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 895fcc45e..b6e3f61b4 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -18,8 +18,16 @@ ******************************************************************************/ #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 index a54a94563..0e042c692 100644 --- a/lib/icinga/comment.h +++ b/lib/icinga/comment.h @@ -35,6 +35,8 @@ class I2_ICINGA_API Comment : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(Comment); + + bool IsExpired(void) const; }; } diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index 6361c3f24..f6d6175b2 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -18,8 +18,42 @@ ******************************************************************************/ #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 index d67a2b9a8..0f702bba4 100644 --- a/lib/icinga/downtime.h +++ b/lib/icinga/downtime.h @@ -35,6 +35,11 @@ class I2_ICINGA_API Downtime : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(Downtime); + + bool IsActive(void) const; + bool IsTriggered(void) const; + bool IsExpired(void) const; + }; } diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index 89b8c28ac..e07f2a08e 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -163,13 +163,6 @@ Comment::Ptr Service::GetCommentByID(const String& id) return Comment::Ptr(); } -bool Service::IsCommentExpired(const Comment::Ptr& comment) -{ - double expire_time = comment->GetExpireTime(); - - return (expire_time != 0 && expire_time < Utility::GetTime()); -} - void Service::AddCommentsToCache(void) { Log(LogDebug, "icinga", "Updating Service comments cache."); @@ -227,7 +220,7 @@ void Service::RemoveExpiredComments(void) String id; 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 1c983d5d4..31a06f5e9 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -163,26 +163,20 @@ void Service::TriggerDowntime(const String& id) if (!downtime) return; - if (IsDowntimeActive(downtime) && IsDowntimeTriggered(downtime)) { + if (downtime->IsActive() && downtime->IsTriggered()) { Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': already triggered."); return; } - if (IsDowntimeExpired(downtime)) { + if (downtime->IsExpired()) { Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': expired."); return; } - double now = Utility::GetTime(); - - if (now < downtime->GetStartTime() || - now > downtime->GetEndTime()) - return; - Log(LogDebug, "icinga", "Triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "'."); if (downtime->GetTriggerTime() == 0) - downtime->SetTriggerTime(now); + downtime->SetTriggerTime(Utility::GetTime()); Dictionary::Ptr triggers = downtime->GetTriggers(); ObjectLock olock(triggers); @@ -227,39 +221,6 @@ Downtime::Ptr Service::GetDowntimeByID(const String& id) return Downtime::Ptr(); } -bool Service::IsDowntimeActive(const Downtime::Ptr& downtime) -{ - double now = Utility::GetTime(); - - if (now < downtime->GetStartTime() || - now > downtime->GetEndTime()) - return false; - - if (downtime->GetFixed()) - return true; - - double triggerTime = downtime->GetTriggerTime(); - - if (triggerTime == 0) - return false; - - return (triggerTime + downtime->GetDuration() < now); -} - -bool Service::IsDowntimeTriggered(const Downtime::Ptr& downtime) -{ - double now = Utility::GetTime(); - - double triggerTime = downtime->GetTriggerTime(); - - return (triggerTime > 0 && triggerTime <= now); -} - -bool Service::IsDowntimeExpired(const Downtime::Ptr& downtime) -{ - return (downtime->GetEndTime() < Utility::GetTime()); -} - void Service::StartDowntimesExpiredTimer(void) { if (!l_DowntimesExpireTimer) { @@ -305,7 +266,7 @@ void Service::RemoveExpiredDowntimes(void) String id; Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(id, downtime), downtimes) { - if (IsDowntimeExpired(downtime)) + if (downtime->IsExpired()) expiredDowntimes.push_back(id); } } @@ -330,7 +291,7 @@ bool Service::IsInDowntime(void) const Downtime::Ptr downtime; BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) { - if (Service::IsDowntimeActive(downtime)) + if (downtime->IsActive()) return true; } @@ -346,7 +307,7 @@ int Service::GetDowntimeDepth(void) const 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.h b/lib/icinga/service.h index 3a7cb01e3..1ae8fca8a 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -197,10 +197,6 @@ public: static Service::Ptr GetOwnerByDowntimeID(const String& id); static Downtime::Ptr GetDowntimeByID(const String& id); - static bool IsDowntimeActive(const Downtime::Ptr& downtime); - static bool IsDowntimeTriggered(const Downtime::Ptr& downtime); - static bool IsDowntimeExpired(const Downtime::Ptr& downtime); - void StartDowntimesExpiredTimer(void); bool IsInDowntime(void) const; @@ -220,8 +216,6 @@ public: static Service::Ptr GetOwnerByCommentID(const String& id); static Comment::Ptr GetCommentByID(const String& id); - static bool IsCommentExpired(const Comment::Ptr& comment); - /* Notifications */ bool GetEnableNotifications(void) const; void SetEnableNotifications(bool enabled, const String& authority = String());