[icinga-checkins] icinga.org: icinga2/master: livestatus: add current_notification_number to host and service table

git at icinga.org git at icinga.org
Thu Jul 18 17:33:13 CEST 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu Jul 18 17:24:14 2013 +0200

livestatus: add current_notification_number to host and service table

refs #4372

---

 components/livestatus/hoststable.cpp    |   17 +++++++++++++++--
 components/livestatus/servicestable.cpp |   12 ++++++++++--
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp
index 2743761..819802d 100644
--- a/components/livestatus/hoststable.cpp
+++ b/components/livestatus/hoststable.cpp
@@ -681,8 +681,21 @@ Value HostsTable::HasBeenCheckedAccessor(const Value& row)
 
 Value HostsTable::CurrentNotificationNumberAccessor(const Value& row)
 {
-	/* TODO Host->Service->GetNotifications->(loop) new attribute */
-	return Empty;
+	/* use hostcheck service */
+	Service::Ptr hc = static_cast<Host::Ptr>(row)->GetHostCheckService();
+
+	if (!hc)
+		return Empty;
+
+        /* XXX Service -> Notifications, biggest wins */
+        int notification_number = 0;
+        BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
+                if (notification->GetNotificationNumber() > notification_number)
+                        notification_number = notification->GetNotificationNumber();
+        }
+
+        return notification_number;
+
 }
 
 Value HostsTable::PendingFlexDowntimeAccessor(const Value& row)
diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp
index 0b2d67d..b914ad4 100644
--- a/components/livestatus/servicestable.cpp
+++ b/components/livestatus/servicestable.cpp
@@ -543,8 +543,16 @@ Value ServicesTable::NextNotificationAccessor(const Value& row)
 
 Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
 {
-	/* TODO not implemented yet */
-	return Empty;
+	Service::Ptr service = static_cast<Service::Ptr>(row);
+
+	/* XXX Service -> Notifications, biggest wins */
+	int notification_number = 0;
+	BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+		if (notification->GetNotificationNumber() > notification_number)
+			notification_number = notification->GetNotificationNumber();
+	}
+
+	return notification_number;
 }
 
 Value ServicesTable::LastStateChangeAccessor(const Value& row)





More information about the icinga-checkins mailing list