[icinga-checkins] icinga.org: icinga2/master: Implemented status. dat support for notifications.

git at icinga.org git at icinga.org
Sat Feb 9 18:40:22 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Feb  9 17:27:32 2013 +0100

Implemented status.dat support for notifications.

---

 components/compat/compatcomponent.cpp |    4 ++-
 lib/icinga/service-downtime.cpp       |   16 +++++++++++++++
 lib/icinga/service-notification.cpp   |   34 ++++++++++++++++++++++++++++++++-
 lib/icinga/service.cpp                |   20 ++----------------
 lib/icinga/service.h                  |    8 ++++++-
 5 files changed, 62 insertions(+), 20 deletions(-)

diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp
index ef73c63..5332bba 100644
--- a/components/compat/compatcomponent.cpp
+++ b/components/compat/compatcomponent.cpp
@@ -355,7 +355,9 @@ void CompatComponent::DumpServiceStatusAttrs(ofstream& fp, const Service::Ptr& s
 	   << "\t" << "problem_has_been_acknowledged=" << (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
 	   << "\t" << "acknowledgement_type=" << static_cast<int>(service->GetAcknowledgement()) << "\n"
 	   << "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
-	   << "\t" << "scheduled_downtime_depth=" << (service->IsInDowntime() ? 1 : 0) << "\n";
+	   << "\t" << "scheduled_downtime_depth=" << (service->IsInDowntime() ? 1 : 0) << "\n"
+	   << "\t" << "last_notification=" << service->GetLastNotification() << "\n"
+	   << "\t" << "next_notification=" << service->GetNextNotification() << "\n";
 }
 
 void CompatComponent::DumpServiceStatus(ofstream& fp, const Service::Ptr& service)
diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp
index b60ee23..43fcbf8 100644
--- a/lib/icinga/service-downtime.cpp
+++ b/lib/icinga/service-downtime.cpp
@@ -274,3 +274,19 @@ void Service::DowntimeExpireTimerHandler(void)
 		service->RemoveExpiredDowntimes();
 	}
 }
+
+bool Service::IsInDowntime(void) const
+{
+	Dictionary::Ptr downtimes = GetDowntimes();
+
+	if (!downtimes)
+		return false;
+
+	Dictionary::Ptr downtime;
+	BOOST_FOREACH(tie(tuples::ignore, downtime), downtimes) {
+		if (Service::IsDowntimeActive(downtime))
+			return true;
+	}
+
+	return false;
+}
diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp
index fb7ab4f..11e20b1 100644
--- a/lib/icinga/service-notification.cpp
+++ b/lib/icinga/service-notification.cpp
@@ -39,7 +39,7 @@ void Service::RequestNotifications(NotificationType type) const
 	EndpointManager::GetInstance()->SendAnycastMessage(Endpoint::Ptr(), msg);
 }
 
-void Service::SendNotifications(NotificationType type) const
+void Service::SendNotifications(NotificationType type)
 {
 	Logger::Write(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
 
@@ -51,6 +51,8 @@ void Service::SendNotifications(NotificationType type) const
 	BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
 		notification->SendNotification(type);
 	}
+
+	SetLastNotification(Utility::GetTime());
 }
 
 void Service::InvalidateNotificationsCache(void)
@@ -182,3 +184,33 @@ void Service::UpdateSlaveNotifications(void)
 
 	Set("slave_notifications", newNotifications);
 }
+
+double Service::GetLastNotification(void) const
+{
+	Value value = Get("last_notification");
+
+	if (value.IsEmpty())
+		value = 0;
+
+	return value;
+}
+
+void Service::SetLastNotification(double time)
+{
+	Set("last_notification", time);
+}
+
+double Service::GetNextNotification(void) const
+{
+	Value value = Get("next_notification");
+
+	if (value.IsEmpty())
+		value = 0;
+
+	return value;
+}
+
+void Service::SetNextNotification(double time)
+{
+	Set("next_notification", time);
+}
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index 1a65de6..41858a6 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -38,7 +38,9 @@ static AttributeDescription serviceAttributes[] = {
 	{ "acknowledgement", Attribute_Replicated },
 	{ "acknowledgement_expiry", Attribute_Replicated },
 	{ "downtimes", Attribute_Replicated },
-	{ "comments", Attribute_Replicated }
+	{ "comments", Attribute_Replicated },
+	{ "last_notification", Attribute_Replicated },
+	{ "next_notification", Attribute_Replicated }
 };
 
 REGISTER_TYPE(Service, serviceAttributes);
@@ -227,22 +229,6 @@ bool Service::IsReachable(void) const
 	return true;
 }
 
-bool Service::IsInDowntime(void) const
-{
-	Dictionary::Ptr downtimes = GetDowntimes();
-
-	if (!downtimes)
-		return false;
-
-	Dictionary::Ptr downtime;
-	BOOST_FOREACH(tie(tuples::ignore, downtime), downtimes) {
-		if (Service::IsDowntimeActive(downtime))
-			return true;
-	}
-
-	return false;
-}
-
 void Service::SetSchedulingOffset(long offset)
 {
 	Set("scheduling_offset", offset);
diff --git a/lib/icinga/service.h b/lib/icinga/service.h
index e136a26..f8033b1 100644
--- a/lib/icinga/service.h
+++ b/lib/icinga/service.h
@@ -224,7 +224,7 @@ public:
 
 	/* Notifications */
 	void RequestNotifications(NotificationType type) const;
-	void SendNotifications(NotificationType type) const;
+	void SendNotifications(NotificationType type);
 
 	static void InvalidateNotificationsCache(void);
 	static void ValidateNotificationsCache(void);
@@ -233,6 +233,12 @@ public:
 
 	void UpdateSlaveNotifications(void);
 
+	double GetLastNotification(void) const;
+	void SetLastNotification(double time);
+
+	double GetNextNotification(void) const;
+	void SetNextNotification(double time);
+
 protected:
 	virtual void OnAttributeChanged(const String& name, const Value& oldValue);
 





More information about the icinga-checkins mailing list