[icinga-checkins] icinga.org: icinga2/master: livestatus: add more hosttable todos

git at icinga.org git at icinga.org
Fri Jul 5 19:14:58 CEST 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri Jul  5 19:14:10 2013 +0200

livestatus: add more hosttable todos

refs #4372

---

 components/livestatus/hoststable.cpp |   61 +++++++++++++++++++++++++++------
 lib/icinga/host.cpp                  |    2 +-
 2 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp
index d5a2df3..46ffd06 100644
--- a/components/livestatus/hoststable.cpp
+++ b/components/livestatus/hoststable.cpp
@@ -830,7 +830,30 @@ Value HostsTable::InCheckPeriodAccessor(const Object::Ptr& object)
 
 Value HostsTable::ContactsAccessor(const Object::Ptr& object)
 {
-	/* TODO */
+	/* TODO - host->service->notifications->users */
+	/* use hostcheck service */
+	Service::Ptr hc = static_pointer_cast<Host>(object)->GetHostCheckService();
+
+	if (!hc)
+		return Value();
+
+	std::set<User::Ptr> allUsers;
+	std::set<User::Ptr> users;
+
+	BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
+		ObjectLock olock(notification);
+
+		users = notification->GetUsers();
+
+		std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
+
+		BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetGroups()) {
+			std::set<User::Ptr> members = ug->GetMembers();
+			std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
+		}
+	}
+
+
 	return Value();
 }
 
@@ -901,8 +924,8 @@ Value HostsTable::ChildsAccessor(const Object::Ptr& object)
 
 Value HostsTable::NumServicesAccessor(const Object::Ptr& object)
 {
-	/* TODO */
-	return Value();
+	/* duplicate of TotalServices */
+	return static_pointer_cast<Host>(object)->GetTotalServices();
 }
 
 Value HostsTable::WorstServiceStateAccessor(const Object::Ptr& object)
@@ -973,37 +996,53 @@ Value HostsTable::NumServicesHardUnknownAccessor(const Object::Ptr& object)
 
 Value HostsTable::HardStateAccessor(const Object::Ptr& object)
 {
-	/* TODO */
-	return Value();
+	/* use hostcheck service */
+	Service::Ptr hc = static_pointer_cast<Host>(object)->GetHostCheckService();
+
+	if (!hc)
+		return Value();
+
+	if (hc->GetState() == StateOK)
+		return StateOK;
+	if (hc->GetStateType() == StateTypeHard)
+		return hc->GetState();
+
+	return hc->GetLastHardState();
 }
 
 Value HostsTable::PnpgraphPresentAccessor(const Object::Ptr& object)
 {
-	/* TODO */
+	/* wtf. not supported */
 	return Value();
 }
 
 Value HostsTable::StalenessAccessor(const Object::Ptr& object)
 {
-	/* TODO */
+	/* TODO time since last check normalized on the check_interval */
 	return Value();
 }
 
 Value HostsTable::GroupsAccessor(const Object::Ptr& object)
 {
-	/* TODO */
-	return Value();
+	/* TODO create array */
+	/* use hostcheck service */
+	Service::Ptr hc = static_pointer_cast<Host>(object)->GetHostCheckService();
+
+	if (!hc)
+		return Value();
+
+	return hc->GetGroups();
 }
 
 Value HostsTable::ContactGroupsAccessor(const Object::Ptr& object)
 {
-	/* TODO */
+	/* TODO create array */
 	return Value();
 }
 
 Value HostsTable::ServicesAccessor(const Object::Ptr& object)
 {
-	/* TODO */
+	/* TODO create array */
 	return Value();
 }
 
diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp
index caf39b1..635b886 100644
--- a/lib/icinga/host.cpp
+++ b/lib/icinga/host.cpp
@@ -97,7 +97,7 @@ Host::Ptr Host::GetByName(const String& name)
 
 Array::Ptr Host::GetGroups(void) const
 {
-	return m_HostGroups;;
+	return m_HostGroups;
 }
 
 Dictionary::Ptr Host::GetMacros(void) const





More information about the icinga-checkins mailing list