Implement notification_*_filter variables for Host/Service objects.

This commit is contained in:
Gunnar Beutner 2013-06-26 09:50:04 +02:00
parent 6e3afe7748
commit 463f4e4cf9
8 changed files with 49 additions and 38 deletions

View File

@ -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" ] },

View File

@ -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");

View File

@ -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"
}

View File

@ -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;

View File

@ -75,8 +75,8 @@ public:
std::set<User::Ptr> GetUsers(void) const;
std::set<UserGroup::Ptr> 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<Array::Ptr> m_Users;
Attribute<Array::Ptr> m_Groups;
Attribute<Dictionary::Ptr> m_Times;
Attribute<long> m_TypeFilter;
Attribute<long> m_StateFilter;
Attribute<long> m_NotificationTypeFilter;
Attribute<long> m_NotificationStateFilter;
Attribute<String> m_HostName;
Attribute<String> m_Service;

View File

@ -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<ExpressionList>();

View File

@ -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

View File

@ -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<Dictionary::Ptr> m_Macros;
Attribute<String> m_NotificationPeriod;
Attribute<Array::Ptr> m_Groups;
Attribute<long> m_TypeFilter;
Attribute<long> m_StateFilter;
Attribute<long> m_NotificationTypeFilter;
Attribute<long> m_NotificationStateFilter;
};
}