object User "icingaadmin" {
display_name = "Icinga 2 Admin"
enable_notifications = 1
- notification_state_filter = (StateFilterOK |
- StateFilterWarning |
- StateFilterCritical)
- notification_type_filter = (NotificationFilterProblem |
- NotificationFilterRecovery)
+ notification_state_filter = [ OK, Warning, Critical ]
+ notification_type_filter = [ Problem, Recovery ]
vars.email = "icinga@localhost"
vars.pager = "+49123456789"
}
notification_command = "mail-service-notification"
- notification_state_filter = (StateFilterWarning |
- StateFilterCritical |
- StateFilterUnknown)
- notification_type_filter = (NotificationFilterProblem |
- NotificationFilterAcknowledgement |
- NotificationFilterRecovery |
- NotificationFilterCustom |
- NotificationFilterFlappingStart |
- NotificationFilterFlappingEnd |
- NotificationFilterDowntimeStart |
- NotificationFilterDowntimeEnd |
- NotificationFilterDowntimeRemoved)
+ notification_state_filter = [ Warning, Critical, Unknown ]
+ notification_type_filter = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart,
+ FlappingEnd, DowntimeStart,DowntimeEnd, DowntimeRemoved ]
notification_period = "24x7"
}
template Notification "generic-notification" {
- notification_state_filter = (StateFilterWarning |
- StateFilterCritical |
- StateFilterUnknown)
- notification_type_filter = (NotificationFilterProblem |
- NotificationFilterAcknowledgement |
- NotificationFilterRecovery |
- NotificationFilterCustom |
- NotificationFilterFlappingStart |
- NotificationFilterFlappingEnd |
- NotificationFilterDowntimeStart |
- NotificationFilterDowntimeEnd |
- NotificationFilterDowntimeRemoved)
+ notification_state_filter = [ Warning, Critical, Unknown ]
+ notification_type_filter = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart,
+ FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
}
If you are familiar with Icinga 1.x `notification_options` please note that they have been split
notification_command = "mail-notification"
users = [ "user1", "user2" ]
+
+ notification_type_filter = [ Problem, Recovery ]
}
Attributes:
notification_command | **Required.** The name of the notification command which should be executed when the notification is triggered.
notification_interval | **Optional.** The notification interval (in seconds). This interval is used for active notifications. Defaults to 5 minutes.
notification_period | **Optional.** The name of a time period which determines when this notification should be triggered. Not set by default.
- notification_type_filter | **Optional.** A set of state filters when this notification should be triggered. By default everything is matched.
- notification_state_filter | **Optional.** A set of type filters when this notification should be triggered. By default everything is matched.
+ notification_type_filter | **Optional.** A list of state filters when this notification should be triggered. By default everything is matched.
+ notification_state_filter | **Optional.** A list of type filters when this notification should be triggered. By default everything is matched.
+
+Available notification state filters:
-Available notification type and state filters:
+ OK
+ Warning
+ Critical
+ Unknown
+ Up
+ Down
- StateFilterOK
- StateFilterWarning
- StateFilterCritical
- StateFilterUnknown
+Available notification type filters:
- NotificationFilterDowntimeStart
- NotificationFilterDowntimeEnd
- NotificationFilterDowntimeRemoved
- NotificationFilterCustom
- NotificationFilterAcknowledgement
- NotificationFilterProblem
- NotificationFilterRecovery
- NotificationFilterFlappingStart
- NotificationFilterFlappingEnd
+ DowntimeStart
+ DowntimeEnd
+ DowntimeRemoved
+ Custom
+ Acknowledgement
+ Problem
+ Recovery
+ FlappingStart
+ FlappingEnd
### <a id="objecttype-dependency"></a> Dependency
parent_host_name = "internet"
parent_service_name = "ping4"
- state_filter = StateFilterOK
+ state_filter = [ OK, Warning ]
disable_checks = true
}
disable_checks |**Optional.** Whether to disable checks when this dependency fails. Defaults to false.
disable_notifications|**Optional.** Whether to disable notifications when this dependency fails. Defaults to true.
period |**Optional.** Time period during which this dependency is enabled.
- state_filter |**Optional.** A set of type filters when this dependency should be OK. Defaults to StateFilterOK | StateFilterWarning.
+ state_filter |**Optional.** A list of type filters when this dependency should be OK. Defaults to [ OK, Warning ] for services and [ Up ] for hosts.
Available state filters:
- StateFilterOK
- StateFilterWarning
- StateFilterCritical
- StateFilterUnknown
+ OK
+ Warning
+ Critical
+ Unknown
+ Up
+ Down
Dependency objects have composite names, i.e. their names are based on the `child_host_name` and `child_service_name` attributes and the
name you specified. This means you can define more than one object with the same (short) name as long as one of the `child_host_name` and
enable_notifications = 1
notification_period = "24x7"
- notification_state_filter = (StateFilterOK |
- StateFilterWarning |
- StateFilterCritical |
- StateFilterUnknown)
- notification_type_filter = (NotificationFilterProblem |
- NotificationFilterRecovery)
+ notification_state_filter = [ OK, Warning, Critical, Unknown ]
+ notification_type_filter = [ Problem, Recovery ]
vars = {
name = "Icinga 2 Admin"
}
}
-Available notification type and state filters:
-
- StateFilterOK
- StateFilterWarning
- StateFilterCritical
- StateFilterUnknown
-
- NotificationFilterDowntimeStart
- NotificationFilterDowntimeEnd
- NotificationFilterDowntimeRemoved
- NotificationFilterCustom
- NotificationFilterAcknowledgement
- NotificationFilterProblem
- NotificationFilterRecovery
- NotificationFilterFlappingStart
- NotificationFilterFlappingEnd
+Available notification state filters:
+
+ OK
+ Warning
+ Critical
+ Unknown
+ Up
+ Down
+
+Available notification type filters:
+
+ DowntimeStart
+ DowntimeEnd
+ DowntimeRemoved
+ Custom
+ Acknowledgement
+ Problem
+ Recovery
+ FlappingStart
+ FlappingEnd
Attributes:
notification_options w,u,c,r,f,s
- notification_state_filter = StateFilterWarning | StateFilterUnknown | StateFilterCritical,
- notification_type_filter = NotificationProblem | NotificationRecovery | NotificationFlappingStart | NotificationFlappingEnd | NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved
+ notification_state_filter = [ Warning, Unknown, Critical ]
+ notification_type_filter = [ Problem, Recovery, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
Icinga 2 adds more fine-grained type filters for acknowledgements, downtime
and flapping type (start, end, ...).
install_if_not_exists(icinga2/features-available/perfdata.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
install_if_not_exists(icinga2/features-available/statusdata.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
install_if_not_exists(icinga2/features-available/syslog.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
-install_if_not_exists(icinga2/scripts/mail-notification.sh ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/scripts)
+install_if_not_exists(icinga2/scripts/mail-host-notification.sh ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/scripts)
+install_if_not_exists(icinga2/scripts/mail-service-notification.sh ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/scripts)
install_if_not_exists(icinga2/scripts/snmp-extend.sh ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/scripts)
install_if_not_exists(logrotate.d/icinga2 ${CMAKE_INSTALL_SYSCONFDIR}/logrotate.d)
}
apply Notification "mail-icingaadmin" to Host {
- import "mail-notification"
+ import "mail-host-notification"
user_groups = [ "icingaadmins"]
}
apply Notification "mail-icingaadmin" to Service {
- import "mail-notification"
+ import "mail-service-notification"
user_groups = [ "icingaadmins"]
* The example notification templates.
*/
-template Notification "mail-notification" {
+template Notification "mail-host-notification" {
+ notification_command = "mail-host-notification"
+
+ notification_state_filter = [ Up, Down ]
+ notification_type_filter = [ Problem, Acknowledgement, Recovery, Custom,
+ FlappingStart, FlappingEnd,
+ DowntimeStart, DowntimeEnd, DowntimeRemoved ]
+
+ notification_period = "24x7"
+}
+
+object NotificationCommand "mail-host-notification" {
+ import "plugin-notification-command"
+
+ command = [ IcingaSysconfDir + "/icinga2/scripts/mail-host-notification.sh" ]
+
+ env = {
+ "NOTIFICATIONTYPE" = "$notification.type$"
+ "HOSTALIAS" = "$host.displayname$",
+ "HOSTADDRESS" = "$host.vars.address$",
+ "HOSTSTATE" = "$host.state$",
+ "LONGDATETIME" = "$icinga.longdatetime$",
+ "HOSTOUTPUT" = "$host.output$",
+ "NOTIFICATIONAUTHORNAME" = "$notification.author$",
+ "NOTIFICATIONCOMMENT" = "$notification.comment$",
+ "HOSTDISPLAYNAME" = "$host.displayname$",
+ "HOSTDISPLAYNAME" = "$host.displayname$",
+ "USEREMAIL" = "$user.vars.email$"
+ }
+}
+
+template Notification "mail-service-notification" {
notification_command = "mail-service-notification"
- notification_state_filter = (StateFilterOK |
- StateFilterWarning |
- StateFilterCritical |
- StateFilterUnknown)
- notification_type_filter = (NotificationFilterProblem |
- NotificationFilterAcknowledgement |
- NotificationFilterRecovery |
- NotificationFilterCustom |
- NotificationFilterFlappingStart |
- NotificationFilterFlappingEnd |
- NotificationFilterDowntimeStart |
- NotificationFilterDowntimeEnd |
- NotificationFilterDowntimeRemoved)
+ notification_state_filter = [ OK, Warning, Critical, Unknown ]
+ notification_type_filter = [ Problem, Acknowledgement, Recovery, Custom,
+ FlappingStart, FlappingEnd,
+ DowntimeStart, DowntimeEnd, DowntimeRemoved ]
notification_period = "24x7"
}
object NotificationCommand "mail-service-notification" {
import "plugin-notification-command"
- command = [ IcingaSysconfDir + "/icinga2/scripts/mail-notification.sh" ]
+ command = [ IcingaSysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
env = {
"NOTIFICATIONTYPE" = "$notification.type$"
--- /dev/null
+#!/usr/bin/env bash
+template=$(cat <<TEMPLATE
+***** Icinga *****
+
+Notification Type: $NOTIFICATIONTYPE
+
+Host: $HOSTALIAS
+Address: $HOSTADDRESS
+State: $HOSTSTATE
+
+Date/Time: $LONGDATETIME
+
+Additional Info: $HOSTOUTPUT
+
+Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
+TEMPLATE
+)
+
+/usr/bin/printf "%b" "$template" | mail -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME is $HOSTSTATE" $USEREMAIL
+
using namespace icinga;
REGISTER_TYPE(CheckResult);
-INITIALIZE_ONCE(&CheckResult::StaticInitialize);
-
-void CheckResult::StaticInitialize(void)
-{
- ScriptVariable::Set("StateOK", StateOK, true, true);
- ScriptVariable::Set("StateWarning", StateWarning, true, true);
- ScriptVariable::Set("StateCritical", StateCritical, true, true);
- ScriptVariable::Set("StateUnknown", StateUnknown, true, true);
-
- ScriptVariable::Set("StateFilterOK", 1 << StateOK, true, true);
- ScriptVariable::Set("StateFilterWarning", 1 << StateWarning, true, true);
- ScriptVariable::Set("StateFilterCritical", 1 << StateCritical, true, true);
- ScriptVariable::Set("StateFilterUnknown", 1 << StateUnknown, true, true);
-}
-
{
public:
DECLARE_PTR_TYPEDEFS(CheckResult);
-
- static void StaticInitialize(void);
};
}
{
code {{{
+/**
+ * The state of a host.
+ *
+ * @ingroup icinga
+ */
+enum HostState
+{
+ HostUp = 0,
+ HostDown = 1,
+ HostUnreachable = 2
+};
+
/**
* The state of a service.
*
#include "icinga/dependency.h"
#include "icinga/service.h"
+#include "config/configcompilercontext.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
+#include "base/scriptfunction.h"
#include <boost/foreach.hpp>
using namespace icinga;
REGISTER_TYPE(Dependency);
+REGISTER_SCRIPTFUNCTION(ValidateDependencyFilters, &Dependency::ValidateFilters);
String DependencyNameComposer::MakeName(const String& shortName, const Dictionary::Ptr props) const
{
return name;
}
+void Dependency::OnConfigLoaded(void)
+{
+ Value defaultFilter;
+
+ if (GetParentServiceName().IsEmpty())
+ defaultFilter = StateFilterUp;
+ else
+ defaultFilter = StateFilterOK | StateFilterWarning;
+
+ SetStateFilter(FilterArrayToInt(GetStateFilterRaw(), defaultFilter));
+}
+
void Dependency::OnStateLoaded(void)
{
DynamicObject::Start();
int state;
if (is_service)
- state = static_cast<int>(static_pointer_cast<Service>(parent)->GetState());
+ state = ServiceStateToFilter(static_pointer_cast<Service>(parent)->GetState());
else
- state = static_cast<int>(static_pointer_cast<Host>(parent)->GetState());
+ state = HostStateToFilter(static_pointer_cast<Host>(parent)->GetState());
/* check state */
- if ((1 << state) & GetStateFilter()) {
+ if (state & GetStateFilter()) {
Log(LogDebug, "icinga", "Dependency '" + GetName() + "' passed: Object matches state filter.");
return true;
}
{
return TimePeriod::GetByName(GetPeriodRaw());
}
+
+void Dependency::ValidateFilters(const String& location, const Dictionary::Ptr& attrs)
+{
+ int sfilter = FilterArrayToInt(attrs->Get("state_filter"), 0);
+
+ if (!attrs->Contains("parent_service_name") && (sfilter & ~(StateFilterUp | StateFilterDown)) != 0) {
+ ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+ location + ": State filter is invalid.");
+ }
+
+ if (attrs->Contains("parent_service_name") && (sfilter & ~(StateFilterOK | StateFilterWarning | StateFilterCritical | StateFilterUnknown)) != 0) {
+ ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+ location + ": State filter is invalid.");
+ }
+}
static void RegisterApplyRuleHandler(void);
+ static void ValidateFilters(const String& location, const Dictionary::Ptr& attrs);
+
protected:
+ virtual void OnConfigLoaded(void);
virtual void OnStateLoaded(void);
virtual void Stop(void);
[config] String period (PeriodRaw);
- [config] int state_filter {
- default {{{ return (1 << StateOK) | (1 << StateWarning); }}}
- };
+ [config] Array::Ptr state_filter (StateFilterRaw);
+ int state_filter_real (StateFilter);
[config] bool disable_checks;
[config] bool disable_notifications;
class Service;
class Dependency;
-/**
- * The state of a host.
- *
- * @ingroup icinga
- */
-enum HostState
-{
- HostUp = 0,
- HostDown = 1,
- HostUnreachable = 2
-};
-
/**
* An Icinga host.
*
}
%type Notification {
+ %validator "ValidateNotificationFilters"
+
%require "host_name",
%attribute %name(Host) "host_name",
%attribute %string "service_name",
%attribute %number "notification_interval",
%attribute %name(TimePeriod) "notification_period",
- %attribute %number "notification_type_filter",
- %attribute %number "notification_state_filter",
+ %attribute %array "notification_type_filter" {
+ %attribute %number "*"
+ },
+ %attribute %array "notification_state_filter" {
+ %attribute %number "*"
+ },
%attribute %array "authorities" {
%attribute %name(Endpoint) "*"
},
%attribute %number "enable_notifications",
- %attribute %number "notification_type_filter",
- %attribute %number "notification_state_filter",
+ %attribute %array "notification_type_filter" {
+ %attribute %number "*"
+ },
+ %attribute %array "notification_state_filter" {
+ %attribute %number "*"
+ },
%attribute %name(TimePeriod) "notification_period"
}
}
%type Dependency {
+ %validator "ValidateDependencyFilters"
+
%require "parent_host_name",
%attribute %name(Host) "parent_host_name",
%attribute %string "parent_service_name",
#include "icinga/notificationcommand.h"
#include "icinga/macroprocessor.h"
#include "icinga/service.h"
+#include "config/configcompilercontext.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/exception.h"
#include "base/initialize.h"
#include "base/scriptvariable.h"
+#include "base/scriptfunction.h"
#include <boost/foreach.hpp>
using namespace icinga;
REGISTER_TYPE(Notification);
+REGISTER_SCRIPTFUNCTION(ValidateNotificationFilters, &Notification::ValidateFilters);
INITIALIZE_ONCE(&Notification::StaticInitialize);
boost::signals2::signal<void (const Notification::Ptr&, double, const String&)> Notification::OnNextNotificationChanged;
void Notification::StaticInitialize(void)
{
- ScriptVariable::Set("NotificationDowntimeStart", NotificationDowntimeStart, true, true);
- ScriptVariable::Set("NotificationDowntimeEnd", NotificationDowntimeEnd, true, true);
- ScriptVariable::Set("NotificationDowntimeRemoved", NotificationDowntimeRemoved, true, true);
- ScriptVariable::Set("NotificationCustom", NotificationCustom, true, true);
- ScriptVariable::Set("NotificationAcknowledgement", NotificationAcknowledgement, true, true);
- ScriptVariable::Set("NotificationProblem", NotificationProblem, true, true);
- ScriptVariable::Set("NotificationRecovery", NotificationRecovery, true, true);
- ScriptVariable::Set("NotificationFlappingStart", NotificationFlappingStart, true, true);
- ScriptVariable::Set("NotificationFlappingEnd", NotificationFlappingEnd, true, true);
-
- ScriptVariable::Set("NotificationFilterDowntimeStart", 1 << NotificationDowntimeStart, true, true);
- ScriptVariable::Set("NotificationFilterDowntimeEnd", 1 << NotificationDowntimeEnd, true, true);
- ScriptVariable::Set("NotificationFilterDowntimeRemoved", 1 << NotificationDowntimeRemoved, true, true);
- ScriptVariable::Set("NotificationFilterCustom", 1 << NotificationCustom, true, true);
- ScriptVariable::Set("NotificationFilterAcknowledgement", 1 << NotificationAcknowledgement, true, true);
- ScriptVariable::Set("NotificationFilterProblem", 1 << NotificationProblem, true, true);
- ScriptVariable::Set("NotificationFilterRecovery", 1 << NotificationRecovery, true, true);
- ScriptVariable::Set("NotificationFilterFlappingStart", 1 << NotificationFlappingStart, true, true);
- ScriptVariable::Set("NotificationFilterFlappingEnd", 1 << NotificationFlappingEnd, true, true);
+ ScriptVariable::Set("OK", StateFilterOK, true, true);
+ ScriptVariable::Set("Warning", StateFilterWarning, true, true);
+ ScriptVariable::Set("Critical", StateCritical, true, true);
+ ScriptVariable::Set("Unknown", StateUnknown, true, true);
+ ScriptVariable::Set("Up", StateFilterUp, true, true);
+ ScriptVariable::Set("Down", StateFilterDown, true, true);
+
+ ScriptVariable::Set("DowntimeStart", 1 << NotificationDowntimeStart, true, true);
+ ScriptVariable::Set("DowntimeEnd", 1 << NotificationDowntimeEnd, true, true);
+ ScriptVariable::Set("DowntimeRemoved", 1 << NotificationDowntimeRemoved, true, true);
+ ScriptVariable::Set("Custom", 1 << NotificationCustom, true, true);
+ ScriptVariable::Set("Acknowledgement", 1 << NotificationAcknowledgement, true, true);
+ ScriptVariable::Set("Problem", 1 << NotificationProblem, true, true);
+ ScriptVariable::Set("Recovery", 1 << NotificationRecovery, true, true);
+ ScriptVariable::Set("FlappingStart", 1 << NotificationFlappingStart, true, true);
+ ScriptVariable::Set("FlappingEnd", 1 << NotificationFlappingEnd, true, true);
+}
+
+void Notification::OnConfigLoaded(void)
+{
+ SetNotificationTypeFilter(FilterArrayToInt(GetNotificationTypeFilterRaw(), 0));
+ SetNotificationStateFilter(FilterArrayToInt(GetNotificationStateFilterRaw(), 0));
+
+ GetCheckable()->AddNotification(GetSelf());
}
void Notification::Start(void)
unsigned long fstate;
if (service)
- fstate = 1 << service->GetState();
+ fstate = ServiceStateToFilter(service->GetState());
else
- fstate = 1 << host->GetState();
+ fstate = HostStateToFilter(host->GetState());
if (!(fstate & GetNotificationStateFilter())) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': state filter does not match");
unsigned long fstate;
if (service)
- fstate = 1 << service->GetState();
+ fstate = ServiceStateToFilter(service->GetState());
else
- fstate = 1 << host->GetState();
+ fstate = HostStateToFilter(host->GetState());
if (!(fstate & user->GetNotificationStateFilter())) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" +
}
}
+int icinga::ServiceStateToFilter(ServiceState state)
+{
+ switch (state) {
+ case StateOK:
+ return StateFilterOK;
+ case StateWarning:
+ return StateFilterWarning;
+ case StateCritical:
+ return StateFilterCritical;
+ case StateUnknown:
+ return StateFilterUnknown;
+ default:
+ VERIFY(!"Invalid state type.");
+ }
+}
+
+int icinga::HostStateToFilter(HostState state)
+{
+ switch (state) {
+ case HostUp:
+ return StateFilterUp;
+ case HostDown: /* fall through */
+ case HostUnreachable:
+ return StateFilterDown;
+ default:
+ VERIFY(!"Invalid state type.");
+ }
+}
+
+int icinga::FilterArrayToInt(const Array::Ptr& typeFilters, int defaultValue)
+{
+ Value resultTypeFilter;
+
+ if (!typeFilters || typeFilters->GetLength() == 0)
+ return defaultValue;
+
+ resultTypeFilter = 0;
+
+ ObjectLock olock(typeFilters);
+ BOOST_FOREACH(const Value& typeFilter, typeFilters) {
+ resultTypeFilter = resultTypeFilter | typeFilter;
+ }
+
+ return resultTypeFilter;
+}
+
+void Notification::ValidateFilters(const String& location, const Dictionary::Ptr& attrs)
+{
+ int sfilter = FilterArrayToInt(attrs->Get("notification_state_filter"), 0);
+
+ if (!attrs->Contains("service_name") && (sfilter & ~(StateFilterUp | StateFilterDown)) != 0) {
+ ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+ location + ": State filter is invalid.");
+ }
+
+ if (attrs->Contains("service_name") && (sfilter & ~(StateFilterOK | StateFilterWarning | StateFilterCritical | StateFilterUnknown)) != 0) {
+ ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+ location + ": State filter is invalid.");
+ }
+
+ int tfilter = FilterArrayToInt(attrs->Get("notification_type_filter"), 0);
+
+ if ((tfilter & ~(1 << NotificationDowntimeStart | 1 << NotificationDowntimeEnd | 1 << NotificationDowntimeRemoved |
+ 1 << NotificationCustom | 1 << NotificationAcknowledgement | 1 << NotificationProblem | 1 << NotificationRecovery |
+ 1 << NotificationFlappingStart | 1 << NotificationFlappingEnd)) != 0) {
+ ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+ location + ": Type filter is invalid.");
+ }
+}
+
bool Notification::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
{
Dictionary::Ptr vars = GetVars();
namespace icinga
{
+/**
+ * @ingroup icinga
+ */
+enum NotificationFilter
+{
+ StateFilterOK = 1,
+ StateFilterWarning = 2,
+ StateFilterCritical = 4,
+ StateFilterUnknown = 8,
+
+ StateFilterUp = 16,
+ StateFilterDown = 32
+};
+
/**
* The notification type.
*
static void RegisterApplyRuleHandler(void);
+ static void ValidateFilters(const String& location, const Dictionary::Ptr& attrs);
+
protected:
+ virtual void OnConfigLoaded(void);
virtual void Start(void);
virtual void Stop(void);
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
};
+I2_ICINGA_API int ServiceStateToFilter(ServiceState state);
+I2_ICINGA_API int HostStateToFilter(HostState state);
+I2_ICINGA_API int FilterArrayToInt(const Array::Ptr& typeFilters, int defaultValue);
+
}
#endif /* NOTIFICATION_H */
[config, protected] Array::Ptr users (UsersRaw);
[config, protected] Array::Ptr user_groups (UserGroupsRaw);
[config] Dictionary::Ptr times;
- [config] int notification_type_filter {
- default {{{ return ~(int)0; }}}
- };
- [config] int notification_state_filter {
- default {{{ return ~(int)0; }}}
- };
+ [config] Array::Ptr notification_type_filter (NotificationTypeFilterRaw);
+ int notification_type_filter_real (NotificationTypeFilter);
+ [config] Array::Ptr notification_state_filter (NotificationStateFilterRaw);
+ int notification_state_filter_real (NotificationStateFilter);
[config, protected] String host_name;
[config, protected] String service_name;
******************************************************************************/
#include "icinga/user.h"
+#include "icinga/notification.h"
#include "icinga/usergroup.h"
+#include "config/configcompilercontext.h"
#include "base/dynamictype.h"
+#include "base/scriptfunction.h"
#include "base/utility.h"
#include "base/objectlock.h"
using namespace icinga;
REGISTER_TYPE(User);
+REGISTER_SCRIPTFUNCTION(ValidateUserFilters, &User::ValidateFilters);
void User::OnConfigLoaded(void)
{
+ SetNotificationTypeFilter(FilterArrayToInt(GetNotificationTypeFilterRaw(), 0));
+ SetNotificationStateFilter(FilterArrayToInt(GetNotificationStateFilterRaw(), 0));
+
Array::Ptr groups = GetGroups();
if (groups) {
return TimePeriod::GetByName(GetNotificationPeriodRaw());
}
+void User::ValidateFilters(const String& location, const Dictionary::Ptr& attrs)
+{
+ int sfilter = FilterArrayToInt(attrs->Get("notification_state_filter"), 0);
+
+ if ((sfilter & ~(StateFilterUp | StateFilterDown | StateFilterOK | StateFilterWarning | StateFilterCritical | StateFilterUnknown)) != 0) {
+ ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+ location + ": State filter is invalid.");
+ }
+
+ int tfilter = FilterArrayToInt(attrs->Get("notification_type_filter"), 0);
+
+ if ((tfilter & ~(1 << NotificationDowntimeStart | 1 << NotificationDowntimeEnd | 1 << NotificationDowntimeRemoved |
+ 1 << NotificationCustom | 1 << NotificationAcknowledgement | 1 << NotificationProblem | 1 << NotificationRecovery |
+ 1 << NotificationFlappingStart | 1 << NotificationFlappingEnd)) != 0) {
+ ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+ location + ": Type filter is invalid.");
+ }
+}
+
bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
{
String key;
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
+ static void ValidateFilters(const String& location, const Dictionary::Ptr& attrs);
+
protected:
virtual void Stop(void);
[config] Dictionary::Ptr macros;
[config] Array::Ptr groups;
[config] String notification_period (NotificationPeriodRaw);
- [config] int notification_type_filter {
- default {{{ return ~(int)0; }}}
- };
- [config] int notification_state_filter {
- default {{{ return ~(int)0; }}}
- };
+ [config] Array::Ptr notification_type_filter (NotificationTypeFilterRaw);
+ int notification_type_filter_real (NotificationTypeFilter);
+ [config] Array::Ptr notification_state_filter (NotificationStateFilterRaw);
+ int notification_state_filter_real (NotificationStateFilter);
[state] bool enable_notifications;
[state] double last_notification;
};