[icinga-checkins] icinga.org: icinga2/master: livestatus: move host attribute getter into host->service again

git at icinga.org git at icinga.org
Fri Jul 5 13:43:46 CEST 2013


Module: icinga2
Branch: master
Commit: ec3e8cfe1ce42b3a3518d463efbcca8cc8c8e1ab
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=ec3e8cfe1ce42b3a3518d463efbcca8cc8c8e1ab

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri Jul  5 13:42:40 2013 +0200

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 178bdd4..d5a2df3 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<Host>(object)->GetMacros();
+
+	if (!macros)
+		return Value();
+
 	return macros->Get("address");
 }
 
 Value HostsTable::Address6Accessor(const Object::Ptr& object)
 {
 	Dictionary::Ptr macros = static_pointer_cast<Host>(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<int>(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<Host>(object)->GetLastCheck();
+	/* use hostcheck service */
+	Service::Ptr hc = static_pointer_cast<Host>(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<Host>(object)->IsFlapping();
+	/* use hostcheck service */
+	Service::Ptr hc = static_pointer_cast<Host>(object)->GetHostCheckService();
+
+	if (!hc)
+		return Value();
+
+	return hc->IsFlapping();
 }
 
 Value HostsTable::ScheduledDowntimeDepthAccessor(const Object::Ptr& object)
 {
-	return static_pointer_cast<Host>(object)->GetDowntimeDepth();
+	/* use hostcheck service */
+	Service::Ptr hc = static_pointer_cast<Host>(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 6d56ba8..caf39b1 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 2ef1a46..0b0ae8f 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);





More information about the icinga-checkins mailing list