From cea15e11dc9f101aa709ab721a8dc2c66d888118 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 7 Apr 2014 13:59:41 +0200 Subject: [PATCH] Implement new state and type filters. Fixes #5906 --- doc/3.04-notifications.md | 37 ++---- doc/4.3-object-types.md | 96 +++++++------- doc/8-differences-between-icinga-1x-and-2.md | 4 +- etc/CMakeLists.txt | 3 +- etc/icinga2/conf.d/generic-host.conf | 2 +- etc/icinga2/conf.d/generic-service.conf | 2 +- etc/icinga2/conf.d/notifications.conf | 52 +++++--- etc/icinga2/scripts/mail-host-notification.sh | 20 +++ ...cation.sh => mail-service-notification.sh} | 0 lib/icinga/checkresult.cpp | 15 --- lib/icinga/checkresult.h | 2 - lib/icinga/checkresult.ti | 12 ++ lib/icinga/dependency.cpp | 36 ++++- lib/icinga/dependency.h | 3 + lib/icinga/dependency.ti | 5 +- lib/icinga/host.h | 12 -- lib/icinga/icinga-type.conf | 20 ++- lib/icinga/notification.cpp | 124 ++++++++++++++---- lib/icinga/notification.h | 21 +++ lib/icinga/notification.ti | 10 +- lib/icinga/user.cpp | 26 ++++ lib/icinga/user.h | 2 + lib/icinga/user.ti | 10 +- 23 files changed, 347 insertions(+), 167 deletions(-) create mode 100755 etc/icinga2/scripts/mail-host-notification.sh rename etc/icinga2/scripts/{mail-notification.sh => mail-service-notification.sh} (100%) diff --git a/doc/3.04-notifications.md b/doc/3.04-notifications.md index fb5a1e776..ce87ca5b6 100644 --- a/doc/3.04-notifications.md +++ b/doc/3.04-notifications.md @@ -19,11 +19,8 @@ The user `icingaadmin` in the example below will get notified only on `WARNING` 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" } @@ -77,18 +74,9 @@ TODO 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" } @@ -234,18 +222,9 @@ Available state and type filters for notifications are: 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 diff --git a/doc/4.3-object-types.md b/doc/4.3-object-types.md index 6f44cc25b..dff7eecad 100644 --- a/doc/4.3-object-types.md +++ b/doc/4.3-object-types.md @@ -134,6 +134,8 @@ Example: notification_command = "mail-notification" users = [ "user1", "user2" ] + + notification_type_filter = [ Problem, Recovery ] } Attributes: @@ -149,25 +151,29 @@ 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 ### Dependency @@ -188,7 +194,7 @@ Example: parent_host_name = "internet" parent_service_name = "ping4" - state_filter = StateFilterOK + state_filter = [ OK, Warning ] disable_checks = true } @@ -204,14 +210,16 @@ Attributes: 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 @@ -230,12 +238,8 @@ Example: 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" @@ -248,22 +252,26 @@ Example: } } -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: diff --git a/doc/8-differences-between-icinga-1x-and-2.md b/doc/8-differences-between-icinga-1x-and-2.md index b16ff3d3c..d3f58445f 100644 --- a/doc/8-differences-between-icinga-1x-and-2.md +++ b/doc/8-differences-between-icinga-1x-and-2.md @@ -497,8 +497,8 @@ All state and type filter use long names or'd with a pipe together 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, ...). diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index 5eb19701f..a1f0a8fd1 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -43,7 +43,8 @@ install_if_not_exists(icinga2/features-available/notification.conf ${CMAKE_INSTA 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) diff --git a/etc/icinga2/conf.d/generic-host.conf b/etc/icinga2/conf.d/generic-host.conf index 060e23572..499afa4f0 100644 --- a/etc/icinga2/conf.d/generic-host.conf +++ b/etc/icinga2/conf.d/generic-host.conf @@ -7,7 +7,7 @@ template Host "generic-host" { } apply Notification "mail-icingaadmin" to Host { - import "mail-notification" + import "mail-host-notification" user_groups = [ "icingaadmins"] diff --git a/etc/icinga2/conf.d/generic-service.conf b/etc/icinga2/conf.d/generic-service.conf index 811750a82..eed24046f 100644 --- a/etc/icinga2/conf.d/generic-service.conf +++ b/etc/icinga2/conf.d/generic-service.conf @@ -10,7 +10,7 @@ template Service "generic-service" { } apply Notification "mail-icingaadmin" to Service { - import "mail-notification" + import "mail-service-notification" user_groups = [ "icingaadmins"] diff --git a/etc/icinga2/conf.d/notifications.conf b/etc/icinga2/conf.d/notifications.conf index 636d05125..31ea3062d 100644 --- a/etc/icinga2/conf.d/notifications.conf +++ b/etc/icinga2/conf.d/notifications.conf @@ -2,22 +2,44 @@ * 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" } @@ -25,7 +47,7 @@ template Notification "mail-notification" { 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$" diff --git a/etc/icinga2/scripts/mail-host-notification.sh b/etc/icinga2/scripts/mail-host-notification.sh new file mode 100755 index 000000000..0ecec0e82 --- /dev/null +++ b/etc/icinga2/scripts/mail-host-notification.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +template=$(cat <