[icinga-checkins] icinga.org: icinga2/master: notifications: add notification number

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


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

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

notifications: add notification number

---

 lib/icinga/notification.cpp         |   26 ++++++++++++++++++++++++++
 lib/icinga/notification.h           |    6 ++++++
 lib/icinga/service-check.cpp        |    1 +
 lib/icinga/service-notification.cpp |    8 ++++++++
 lib/icinga/service.h                |    2 ++
 5 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp
index b65537c..80d17cb 100644
--- a/lib/icinga/notification.cpp
+++ b/lib/icinga/notification.cpp
@@ -44,6 +44,7 @@ Notification::Notification(const Dictionary::Ptr& serializedUpdate)
 	RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod);
 	RegisterAttribute("last_notification", Attribute_Replicated, &m_LastNotification);
 	RegisterAttribute("next_notification", Attribute_Replicated, &m_NextNotification);
+	RegisterAttribute("notification_number", Attribute_Replicated, &m_NotificationNumber);
 	RegisterAttribute("macros", Attribute_Config, &m_Macros);
 	RegisterAttribute("users", Attribute_Config, &m_Users);
 	RegisterAttribute("groups", Attribute_Config, &m_Groups);
@@ -208,6 +209,26 @@ void Notification::SetNextNotification(double time)
 	Touch("next_notification");
 }
 
+int Notification::GetNotificationNumber(void) const
+{
+	if (m_NotificationNumber.IsEmpty())
+		return 0;
+	else
+		return m_NotificationNumber;
+}
+
+void Notification::UpdateNotificationNumber(void)
+{
+	m_NotificationNumber = m_NotificationNumber + 1;
+	Touch("notification_number");
+}
+
+void Notification::ResetNotificationNumber(void)
+{
+	m_NotificationNumber = 0;
+	Touch("notification_number");
+}
+
 String Notification::NotificationTypeToString(NotificationType type)
 {
 	switch (type) {
@@ -332,6 +353,11 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
 	try {
 		GetNotificationCommand()->Execute(GetSelf(), user, cr, type);
 
+		{
+			ObjectLock olock(this);
+			UpdateNotificationNumber();
+		}
+
 		RequestMessage rm;
 		rm.SetMethod("icinga::NotificationSent");
 
diff --git a/lib/icinga/notification.h b/lib/icinga/notification.h
index 0a10d99..c85c8c1 100644
--- a/lib/icinga/notification.h
+++ b/lib/icinga/notification.h
@@ -83,6 +83,10 @@ public:
 	double GetNextNotification(void) const;
 	void SetNextNotification(double time);
 
+	int GetNotificationNumber(void) const;
+	void UpdateNotificationNumber(void);
+	void ResetNotificationNumber(void);
+
 	void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = "");
 
 	static String NotificationTypeToString(NotificationType type);
@@ -98,6 +102,7 @@ private:
 	Attribute<String> m_NotificationPeriod;
 	Attribute<double> m_LastNotification;
 	Attribute<double> m_NextNotification;
+	Attribute<int> m_NotificationNumber;
 	Attribute<Dictionary::Ptr> m_Macros;
 	Attribute<Array::Ptr> m_ExportMacros;
 	Attribute<Array::Ptr> m_Users;
@@ -108,6 +113,7 @@ private:
 	Attribute<String> m_HostName;
 	Attribute<String> m_Service;
 
+
 	void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = "");
 };
 
diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp
index 57e805b..c5ab8f2 100644
--- a/lib/icinga/service-check.cpp
+++ b/lib/icinga/service-check.cpp
@@ -429,6 +429,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 
 		attempt = 1;
 		recovery = true;
+		ResetNotificationNumbers();
 	} else {
 		if (old_attempt >= GetMaxCheckAttempts()) {
 			SetStateType(StateTypeHard);
diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp
index be0581e..58b6b24 100644
--- a/lib/icinga/service-notification.cpp
+++ b/lib/icinga/service-notification.cpp
@@ -39,6 +39,14 @@ static Timer::Ptr l_NotificationsCacheTimer;
 
 boost::signals2::signal<void (const Service::Ptr&, const String&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentChanged;
 
+void Service::ResetNotificationNumbers(void)
+{
+	BOOST_FOREACH(const Notification::Ptr& notification, GetNotifications()) {
+		ObjectLock olock(notification);
+		notification->ResetNotificationNumber();
+	}
+}
+
 void Service::NotificationSentRequestHandler(const RequestMessage& request)
 {
 	NotificationMessage params;
diff --git a/lib/icinga/service.h b/lib/icinga/service.h
index 9da59e9..3d7911a 100644
--- a/lib/icinga/service.h
+++ b/lib/icinga/service.h
@@ -283,6 +283,8 @@ public:
 	void SetForceNextNotification(bool force);
 	bool GetForceNextNotification(void) const;
 
+	void ResetNotificationNumbers(void);
+
 	static void InvalidateNotificationsCache(void);
 
 	void UpdateSlaveNotifications(void);





More information about the icinga-checkins mailing list