mirror of https://github.com/Icinga/icinga2.git
notifications: add notification number
This commit is contained in:
parent
26f1bf86f3
commit
fe4a5e721c
|
@ -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");
|
||||
|
||||
|
|
|
@ -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 = "");
|
||||
};
|
||||
|
||||
|
|
|
@ -429,6 +429,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
|
|||
|
||||
attempt = 1;
|
||||
recovery = true;
|
||||
ResetNotificationNumbers();
|
||||
} else {
|
||||
if (old_attempt >= GetMaxCheckAttempts()) {
|
||||
SetStateType(StateTypeHard);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -283,6 +283,8 @@ public:
|
|||
void SetForceNextNotification(bool force);
|
||||
bool GetForceNextNotification(void) const;
|
||||
|
||||
void ResetNotificationNumbers(void);
|
||||
|
||||
static void InvalidateNotificationsCache(void);
|
||||
|
||||
void UpdateSlaveNotifications(void);
|
||||
|
|
Loading…
Reference in New Issue