From ec3e8cfe1ce42b3a3518d463efbcca8cc8c8e1ab Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 5 Jul 2013 13:42:40 +0200 Subject: [PATCH] livestatus: move host attribute getter into host->service again refs #4372 --- components/livestatus/hoststable.cpp | 34 +++++++++++++++++++++++++--- lib/icinga/host.cpp | 30 ------------------------ lib/icinga/host.h | 9 -------- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 178bdd407..d5a2df3a7 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -176,12 +176,20 @@ Value HostsTable::DisplayNameAccessor(const Object::Ptr& object) Value HostsTable::AddressAccessor(const Object::Ptr& object) { Dictionary::Ptr macros = static_pointer_cast(object)->GetMacros(); + + if (!macros) + return Value(); + return macros->Get("address"); } Value HostsTable::Address6Accessor(const Object::Ptr& object) { Dictionary::Ptr macros = static_pointer_cast(object)->GetMacros(); + + if (!macros) + return Value(); + return macros->Get("address6"); } @@ -443,6 +451,7 @@ Value HostsTable::AcknowledgementTypeAccessor(const Object::Ptr& object) if (!hc) return Value(); + /* important: lock acknowledgements */ ObjectLock olock(hc); return static_cast(hc->GetAcknowledgement()); @@ -572,6 +581,7 @@ Value HostsTable::AcknowledgedAccessor(const Object::Ptr& object) if (!hc) return Value(); + /* important: lock acknowledgements */ ObjectLock olock(hc); return (hc->IsAcknowledged() ? 1 : 0); @@ -601,7 +611,13 @@ Value HostsTable::CheckFlappingRecoveryNotificationAccessor(const Object::Ptr& o Value HostsTable::LastCheckAccessor(const Object::Ptr& object) { - return static_pointer_cast(object)->GetLastCheck(); + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetLastCheck(); } Value HostsTable::LastStateChangeAccessor(const Object::Ptr& object) @@ -629,12 +645,24 @@ Value HostsTable::LastTimeUnreachableAccessor(const Object::Ptr& object) Value HostsTable::IsFlappingAccessor(const Object::Ptr& object) { - return static_pointer_cast(object)->IsFlapping(); + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->IsFlapping(); } Value HostsTable::ScheduledDowntimeDepthAccessor(const Object::Ptr& object) { - return static_pointer_cast(object)->GetDowntimeDepth(); + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetDowntimeDepth(); } Value HostsTable::IsExecutingAccessor(const Object::Ptr& object) diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 6d56ba8b6..caf39b166 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -610,36 +610,6 @@ StateType Host::GetStateType(void) const return hc->GetStateType(); } -double Host::GetLastCheck(void) const -{ - Service::Ptr hc = GetHostCheckService(); - - if (!hc) - return -1; - - return hc->GetLastCheck(); -} - -bool Host::IsFlapping(void) const -{ - Service::Ptr hc = GetHostCheckService(); - - if (!hc) - return false; - - return hc->IsFlapping(); -} - -int Host::GetDowntimeDepth() const -{ - Service::Ptr hc = GetHostCheckService(); - - if (!hc) - return 0; - - return hc->GetDowntimeDepth(); -} - String Host::StateToString(HostState state) { switch (state) { diff --git a/lib/icinga/host.h b/lib/icinga/host.h index 2ef1a46a8..0b0ae8f11 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -118,18 +118,9 @@ public: double GetLastStateChange(void) const; double GetLastHardStateChange(void) const; - bool IsFlapping(void) const; - static String StateToString(HostState state); virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; - - /* Virtual Checks */ - double GetLastCheck(void) const; - - /* Virtual Downtime */ - int GetDowntimeDepth(void) const; - protected: virtual void OnRegistrationCompleted(void); virtual void OnAttributeChanged(const String& name); -- 2.40.0