From 463f4e4cf9b6b2bbad8b38f613628d1b2576d5f0 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 26 Jun 2013 09:50:04 +0200 Subject: [PATCH] Implement notification_*_filter variables for Host/Service objects. --- etc/icinga2/icinga2.conf.dist | 2 +- lib/icinga/host.cpp | 2 ++ lib/icinga/icinga-type.conf | 21 +++++++++++++++------ lib/icinga/notification.cpp | 28 +++++++++++++--------------- lib/icinga/notification.h | 8 ++++---- lib/icinga/service-notification.cpp | 2 ++ lib/icinga/user.cpp | 16 ++++++++-------- lib/icinga/user.h | 8 ++++---- 8 files changed, 49 insertions(+), 38 deletions(-) diff --git a/etc/icinga2/icinga2.conf.dist b/etc/icinga2/icinga2.conf.dist index 1a9986e46..7bba49fa0 100644 --- a/etc/icinga2/icinga2.conf.dist +++ b/etc/icinga2/icinga2.conf.dist @@ -32,7 +32,7 @@ local object CompatComponent "compat" { } */ object Host "localhost" { services["ping4"] = { templates = [ "ping4" ] }, - services["ping4"] = { templates = [ "ping4" ] }, + services["ping6"] = { templates = [ "ping6" ] }, services["http"] = { templates = [ "http_ip" ] }, services["ssh"] = { templates = [ "ssh" ] }, services["load"] = { templates = [ "load" ] }, diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 9435187ba..0d6381682 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -224,6 +224,8 @@ void Host::UpdateSlaveServices(void) keys.insert("servicegroups"); keys.insert("checkers"); keys.insert("notification_interval"); + keys.insert("notification_type_filter"); + keys.insert("notification_state_filter"); keys.insert("check_period"); keys.insert("servicedependencies"); keys.insert("hostdependencies"); diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf index bac85be1b..7acf132fc 100644 --- a/lib/icinga/icinga-type.conf +++ b/lib/icinga/icinga-type.conf @@ -99,6 +99,9 @@ type Host { %attribute number "begin", %attribute number "end", }, + + %attribute number "notification_type_filter", + %attribute number "notification_state_filter" } }, } @@ -125,6 +128,9 @@ type Host { %attribute number "begin", %attribute number "end", }, + + %attribute number "notification_type_filter", + %attribute number "notification_state_filter" } }, @@ -137,6 +143,9 @@ type Host { %attribute number "notification_interval", %attribute name(TimePeriod) "notification_period", + %attribute number "notification_type_filter", + %attribute number "notification_state_filter" + %attribute dictionary "macros" { %attribute string "*" }, @@ -231,8 +240,8 @@ type Service { %attribute number "end", }, - %attribute number "type_filter", - %attribute number "state_filter" + %attribute number "notification_type_filter", + %attribute number "notification_state_filter" } } } @@ -307,8 +316,8 @@ type Notification { %attribute number "notification_interval", %attribute name(TimePeriod) "notification_period", - %attribute number "type_filter", - %attribute number "state_filter" + %attribute number "notification_type_filter", + %attribute number "notification_state_filter" } type User { @@ -322,8 +331,8 @@ type User { %attribute name(UserGroup) "*" }, - %attribute number "type_filter", - %attribute number "state_filter" + %attribute number "notification_type_filter", + %attribute number "notification_state_filter" } diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 9329e98c8..9460f8fdd 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -46,8 +46,8 @@ Notification::Notification(const Dictionary::Ptr& serializedUpdate) RegisterAttribute("users", Attribute_Config, &m_Users); RegisterAttribute("groups", Attribute_Config, &m_Groups); RegisterAttribute("times", Attribute_Config, &m_Times); - RegisterAttribute("type_filter", Attribute_Config, &m_TypeFilter); - RegisterAttribute("state_filter", Attribute_Config, &m_StateFilter); + RegisterAttribute("notification_type_filter", Attribute_Config, &m_NotificationTypeFilter); + RegisterAttribute("notification_state_filter", Attribute_Config, &m_NotificationStateFilter); RegisterAttribute("host_name", Attribute_Config, &m_HostName); RegisterAttribute("service", Attribute_Config, &m_Service); RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros); @@ -142,20 +142,20 @@ Dictionary::Ptr Notification::GetTimes(void) const return m_Times; } -unsigned long Notification::GetTypeFilter(void) const +unsigned long Notification::GetNotificationTypeFilter(void) const { - if (m_TypeFilter.IsEmpty()) + if (m_NotificationTypeFilter.IsEmpty()) return ~(unsigned long)0; /* All states. */ else - return m_TypeFilter; + return m_NotificationTypeFilter; } -unsigned long Notification::GetStateFilter(void) const +unsigned long Notification::GetNotificationStateFilter(void) const { - if (m_StateFilter.IsEmpty()) + if (m_NotificationStateFilter.IsEmpty()) return ~(unsigned long)0; /* All states. */ else - return m_StateFilter; + return m_NotificationStateFilter; } double Notification::GetNotificationInterval(void) const @@ -260,18 +260,16 @@ void Notification::BeginExecuteNotification(NotificationType type, const Diction unsigned long ftype = 1 << type; - Log(LogDebug, "icinga", "FType=" + Convert::ToString(ftype) + ", TypeFilter=" + Convert::ToString(GetTypeFilter())); + Log(LogDebug, "icinga", "FType=" + Convert::ToString(ftype) + ", TypeFilter=" + Convert::ToString(GetNotificationTypeFilter())); - if (!(ftype & GetTypeFilter())) { + if (!(ftype & GetNotificationTypeFilter())) { Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': type filter does not match"); return; } unsigned long fstate = 1 << GetService()->GetState(); - Log(LogDebug, "icinga", "FState=" + Convert::ToString(fstate) + ", StateFilter=" + Convert::ToString(GetStateFilter())); - - if (!(fstate & GetStateFilter())) { + if (!(fstate & GetNotificationStateFilter())) { Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': state filter does not match"); return; } @@ -314,7 +312,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: unsigned long ftype = 1 << type; - if (!(ftype & user->GetTypeFilter())) { + if (!(ftype & user->GetNotificationTypeFilter())) { Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + " and user '" + user->GetName() + "': type filter does not match"); return; @@ -322,7 +320,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: unsigned long fstate = 1 << GetService()->GetState(); - if (!(fstate & user->GetStateFilter())) { + if (!(fstate & user->GetNotificationStateFilter())) { Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + " and user '" + user->GetName() + "': state filter does not match"); return; diff --git a/lib/icinga/notification.h b/lib/icinga/notification.h index 6fa736253..c13b200ce 100644 --- a/lib/icinga/notification.h +++ b/lib/icinga/notification.h @@ -75,8 +75,8 @@ public: std::set GetUsers(void) const; std::set GetGroups(void) const; Dictionary::Ptr GetTimes(void) const; - unsigned long GetTypeFilter(void) const; - unsigned long GetStateFilter(void) const; + unsigned long GetNotificationTypeFilter(void) const; + unsigned long GetNotificationStateFilter(void) const; double GetLastNotification(void) const; void SetLastNotification(double time); @@ -104,8 +104,8 @@ private: Attribute m_Users; Attribute m_Groups; Attribute m_Times; - Attribute m_TypeFilter; - Attribute m_StateFilter; + Attribute m_NotificationTypeFilter; + Attribute m_NotificationStateFilter; Attribute m_HostName; Attribute m_Service; diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index e7c6eb478..7939a9bd4 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -243,6 +243,8 @@ void Service::UpdateSlaveNotifications(void) keys.insert("groups"); keys.insert("notification_interval"); keys.insert("notification_period"); + keys.insert("notification_type_filter"); + keys.insert("notification_state_filter"); keys.insert("export_macros"); ExpressionList::Ptr svc_exprl = boost::make_shared(); diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 2b740963a..53e297670 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -34,8 +34,8 @@ User::User(const Dictionary::Ptr& serializedUpdate) RegisterAttribute("macros", Attribute_Config, &m_Macros); RegisterAttribute("groups", Attribute_Config, &m_Groups); RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod); - RegisterAttribute("type_filter", Attribute_Config, &m_TypeFilter); - RegisterAttribute("state_filter", Attribute_Config, &m_StateFilter); + RegisterAttribute("notification_type_filter", Attribute_Config, &m_NotificationTypeFilter); + RegisterAttribute("notification_state_filter", Attribute_Config, &m_NotificationStateFilter); } User::~User(void) @@ -81,20 +81,20 @@ TimePeriod::Ptr User::GetNotificationPeriod(void) const return TimePeriod::GetByName(m_NotificationPeriod); } -unsigned long User::GetTypeFilter(void) const +unsigned long User::GetNotificationTypeFilter(void) const { - if (m_TypeFilter.IsEmpty()) + if (m_NotificationTypeFilter.IsEmpty()) return ~(unsigned long)0; /* All states. */ else - return m_TypeFilter; + return m_NotificationTypeFilter; } -unsigned long User::GetStateFilter(void) const +unsigned long User::GetNotificationStateFilter(void) const { - if (m_StateFilter.IsEmpty()) + if (m_NotificationStateFilter.IsEmpty()) return ~(unsigned long)0; /* All states. */ else - return m_StateFilter; + return m_NotificationStateFilter; } bool User::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const diff --git a/lib/icinga/user.h b/lib/icinga/user.h index 855a8ecdc..cad26ad7a 100644 --- a/lib/icinga/user.h +++ b/lib/icinga/user.h @@ -48,8 +48,8 @@ public: String GetDisplayName(void) const; Array::Ptr GetGroups(void) const; TimePeriod::Ptr GetNotificationPeriod(void) const; - unsigned long GetTypeFilter(void) const; - unsigned long GetStateFilter(void) const; + unsigned long GetNotificationTypeFilter(void) const; + unsigned long GetNotificationStateFilter(void) const; Dictionary::Ptr GetMacros(void) const; @@ -63,8 +63,8 @@ private: Attribute m_Macros; Attribute m_NotificationPeriod; Attribute m_Groups; - Attribute m_TypeFilter; - Attribute m_StateFilter; + Attribute m_NotificationTypeFilter; + Attribute m_NotificationStateFilter; }; }