Implement notification escalations.

This commit is contained in:
Gunnar Beutner 2013-05-13 13:44:57 +02:00
parent f4d04f8172
commit 8e754b085e
3 changed files with 51 additions and 8 deletions

View File

@ -97,7 +97,12 @@ type Host {
}, },
%attribute array "groups" { %attribute array "groups" {
%attribute name(UserGroup) "*" %attribute name(UserGroup) "*"
} },
%attribute dictionary "times" {
%attribute number "begin",
%attribute number "end",
},
} }
}, },
} }
@ -122,7 +127,12 @@ type Host {
}, },
%attribute array "groups" { %attribute array "groups" {
%attribute name(UserGroup) "*" %attribute name(UserGroup) "*"
} },
%attribute dictionary "times" {
%attribute number "begin",
%attribute number "end",
},
} }
}, },
@ -240,7 +250,13 @@ type Service {
}, },
%attribute array "groups" { %attribute array "groups" {
%attribute name(UserGroup) "*" %attribute name(UserGroup) "*"
} },
%attribute dictionary "times" {
%attribute number "begin",
%attribute number "end",
},
} }
} }
} }
@ -277,6 +293,11 @@ type Notification {
%attribute name(UserGroup) "*" %attribute name(UserGroup) "*"
}, },
%attribute dictionary "times" {
%attribute number "begin",
%attribute number "end",
},
%attribute array "notification_command" { %attribute array "notification_command" {
%attribute string "*" %attribute string "*"
}, },

View File

@ -43,6 +43,7 @@ Notification::Notification(const Dictionary::Ptr& serializedUpdate)
RegisterAttribute("macros", Attribute_Config, &m_Macros); RegisterAttribute("macros", Attribute_Config, &m_Macros);
RegisterAttribute("users", Attribute_Config, &m_Users); RegisterAttribute("users", Attribute_Config, &m_Users);
RegisterAttribute("groups", Attribute_Config, &m_Groups); RegisterAttribute("groups", Attribute_Config, &m_Groups);
RegisterAttribute("times", Attribute_Config, &m_Times);
RegisterAttribute("host_name", Attribute_Config, &m_HostName); RegisterAttribute("host_name", Attribute_Config, &m_HostName);
RegisterAttribute("service", Attribute_Config, &m_Service); RegisterAttribute("service", Attribute_Config, &m_Service);
RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros); RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
@ -132,6 +133,11 @@ std::set<UserGroup::Ptr> Notification::GetGroups(void) const
return result; return result;
} }
Dictionary::Ptr Notification::GetTimes(void) const
{
return m_Times;
}
double Notification::GetNotificationInterval(void) const double Notification::GetNotificationInterval(void) const
{ {
if (m_NotificationInterval.IsEmpty()) if (m_NotificationInterval.IsEmpty())
@ -202,17 +208,31 @@ String Notification::NotificationTypeToString(NotificationType type)
} }
} }
void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool ignore_timeperiod) void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force)
{ {
ASSERT(!OwnsLock()); ASSERT(!OwnsLock());
if (!ignore_timeperiod) { if (!force) {
TimePeriod::Ptr tp = GetNotificationPeriod(); TimePeriod::Ptr tp = GetNotificationPeriod();
if (tp && !tp->IsInside(Utility::GetTime())) { if (tp && !tp->IsInside(Utility::GetTime())) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': not in timeperiod"); Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': not in timeperiod");
return; return;
} }
double now = Utility::GetTime();
Dictionary::Ptr times = GetTimes();
Service::Ptr service = GetService();
if (times && times->Contains("begin") && now < service->GetLastHardStateChange() + times->Get("begin")) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': before escalation range");
return;
}
if (times && times->Contains("end") && now > service->GetLastHardStateChange() + times->Get("end")) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': after escalation range");
return;
}
} }
{ {
@ -233,7 +253,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const Diction
BOOST_FOREACH(const User::Ptr& user, allUsers) { BOOST_FOREACH(const User::Ptr& user, allUsers) {
Log(LogDebug, "icinga", "Sending notification for user " + user->GetName()); Log(LogDebug, "icinga", "Sending notification for user " + user->GetName());
Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, ignore_timeperiod)); Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force));
} }
} }

View File

@ -71,6 +71,7 @@ public:
Array::Ptr GetExportMacros(void) const; Array::Ptr GetExportMacros(void) const;
std::set<User::Ptr> GetUsers(void) const; std::set<User::Ptr> GetUsers(void) const;
std::set<UserGroup::Ptr> GetGroups(void) const; std::set<UserGroup::Ptr> GetGroups(void) const;
Dictionary::Ptr GetTimes(void) const;
double GetLastNotification(void) const; double GetLastNotification(void) const;
void SetLastNotification(double time); void SetLastNotification(double time);
@ -78,7 +79,7 @@ public:
double GetNextNotification(void) const; double GetNextNotification(void) const;
void SetNextNotification(double time); void SetNextNotification(double time);
void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool ignore_timeperiod); void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool force);
static String NotificationTypeToString(NotificationType type); static String NotificationTypeToString(NotificationType type);
@ -97,10 +98,11 @@ private:
Attribute<Array::Ptr> m_ExportMacros; Attribute<Array::Ptr> m_ExportMacros;
Attribute<Array::Ptr> m_Users; Attribute<Array::Ptr> m_Users;
Attribute<Array::Ptr> m_Groups; Attribute<Array::Ptr> m_Groups;
Attribute<Dictionary::Ptr> m_Times;
Attribute<String> m_HostName; Attribute<String> m_HostName;
Attribute<String> m_Service; Attribute<String> m_Service;
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool ignore_timeperiod); void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force);
}; };
} }