1 ## <a id="notifications"></a> Notifications
3 Notifications for service and host problems are an integral part of your
6 There are many ways of sending notifications, e.g. by e-mail, XMPP,
7 IRC, Twitter, etc. On its own Icinga 2 does not know how to send notifications.
8 Instead it relies on external mechanisms such as shell scripts to notify users.
10 A notification specification requires one or more users (and/or user groups)
11 who will be notified in case of problems. These users must have all custom
12 attributes defined which will be used in the `NotificationCommand` on execution.
16 The user `icingaadmin` in the example below will get notified only on `WARNING` and
17 `CRITICAL` states and `problem` and `recovery` notification types.
19 object User "icingaadmin" {
20 display_name = "Icinga 2 Admin"
21 enable_notifications = 1
22 notification_state_filter = [ OK, Warning, Critical ]
23 notification_type_filter = [ Problem, Recovery ]
24 vars.email = "icinga@localhost"
25 vars.pager = "+49123456789"
29 If you don't set the `notification_state_filter` and `notification_type_filter`
30 configuration attributes for the `User` object, all states and types will be
33 You should choose which information you (and your notified users) are interested in
34 case of emergency, and also which information does not provide any value to you and
37 There are various custom attributes available at runtime execution of the
38 `NotificationCommand`. The example below may or may not fit your needs.
40 object NotificationCommand "mail-service-notification" {
41 import "plugin-notification-command"
43 command = [ SysconfDir + "/icinga2/scripts/mail-notification.sh" ]
46 "NOTIFICATIONTYPE" = "$notification.type$"
47 "SERVICEDESC" = "$service.description$"
48 "HOSTALIAS" = "$host.displayname$",
49 "HOSTADDRESS" = "$host.vars.address$",
50 "SERVICESTATE" = "$service.state$",
51 "LONGDATETIME" = "$icinga.longdatetime$",
52 "SERVICEOUTPUT" = "$service.output$",
53 "NOTIFICATIONAUTHORNAME" = "$notification.author$",
54 "NOTIFICATIONCOMMENT" = "$notification.comment$",
55 "HOSTDISPLAYNAME" = "$host.displayname$",
56 "SERVICEDISPLAYNAME" = "$service.displayname$",
57 "USEREMAIL" = "$user.vars.email$"
61 The command attribute in the `mail-service-notification` command refers to the
62 shell script installed into `/etc/icinga2/scripts/mail-notification.sh`.
63 The macros specified in the `env` dictionary are exported as environment
64 variables and can be used in the notification script.
66 You can add all shared attributes to a `Notification` template which is inherited
67 to the defined notifications. That way you'll save duplicated attributes in each
68 `Notification` object. Attributes can be overridden locally.
72 template Notification "generic-notification" {
73 notification_interval = 15m
75 notification_command = "mail-service-notification"
77 notification_state_filter = [ Warning, Critical, Unknown ]
78 notification_type_filter = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart,
79 FlappingEnd, DowntimeStart,DowntimeEnd, DowntimeRemoved ]
81 notification_period = "24x7"
84 The time period `24x7` is shipped as example configuration with Icinga 2.
86 Use the `apply` keyword to create `Notification` objects for your services:
88 apply Notification "mail" to Service {
89 import "generic-notification"
91 notification_command = "mail-notification"
92 users = [ "icingaadmin" ]
94 assign where service.name == "mysql"
97 Instead of assigning users to notifications, you can also add the `user_groups`
98 attribute with a list of user groups to the `Notification` object. Icinga 2 will
99 resolve all group members and send notifications to all of them.
101 ### <a id="notification-escalations"></a> Notification Escalations
103 When a problem notification is sent and a problem still exists after re-notification
104 you may want to escalate the problem to the next support level. A different approach
105 is to configure the default notification by email, and escalate the problem via sms
106 if not already solved.
108 You can define notification start and end times as additional configuration
109 attributes making the `Notification` object a so-called `notification escalation`.
110 Using templates you can share the basic notification attributes such as users or the
111 `notification_interval` (and override them for the escalation then).
113 Using the example from above, you can define additional users being escalated for sms
114 notifications between start and end time.
116 object User "icinga-oncall-2nd-level" {
117 display_name = "Icinga 2nd Level"
118 enable_notifications = true
120 vars.mobile = "+1 555 424642"
123 object User "icinga-oncall-1st-level" {
124 display_name = "Icinga 1st Level"
125 enable_notifications = true
127 vars.mobile = "+1 555 424642"
131 Define an additional `NotificationCommand` for SMS notifications.
135 > The example is not complete as there are many different SMS providers.
136 > Please note that sending SMS notifications will require an SMS provider
137 > or local hardware with a sim card active.
139 object NotificationCommand "sms-notification" {
140 command = PluginDir + "/send_sms_notification $mobile$ ..."
143 The two new notification escalations are added onto the host `localhost`
144 and its service `ping4` using the `generic-notification` template.
145 The user `icinga-oncall-2nd-level` will get notified by SMS (`sms-notification`
146 command) after `30m` until `1h`.
150 > The `notification_interval` was set to 15m in the `generic-notification`
151 > template example. Lower that value in your escalations by using a secondary
152 > template or overriding the attribute directly in the `notifications` array
153 > position for `escalation-sms-2nd-level`.
155 If the problem does not get resolved or acknowledged preventing further notifications
156 the `escalation-sms-1st-level` user will be escalated `1h` after the initial problem was
157 notified, but only for one hour (`2h` as `end` key for the `times` dictionary).
159 apply Notification "mail" to Service {
160 import "generic-notification"
161 notification_command = "mail-notification"
162 users = [ "icingaadmin" ]
164 assign where service.name == "ping4"
167 apply Notification "escalation-sms-2nd-level" to Service {
168 import "generic-notification"
169 notification_command = "sms-notification"
170 users = [ "icinga-oncall-2nd-level" ]
177 assign where service.name == "ping4"
180 apply Notification "escalation-sms-1st-level" to Service {
181 import "generic-notification"
182 notification_command = "sms-notification"
183 users = [ "icinga-oncall-1st-level" ]
190 assign where service.name == "ping4"
193 Instead of assigning users to notifications, you can also add the `user_groups`
194 attribute with a list of user groups to the `Notification` object. Icinga 2 will
195 resolve all group members and send notifications and notification escalations to
198 ### <a id="first-notification-delay"></a> First Notification Delay
200 Sometimes the problem in question should not be notified when the first notification
201 happens, but a defined time duration afterwards. In Icinga 2 you can use the `times`
202 dictionary and set `begin = 15m` as key and value if you want to suppress notifications
203 in the first 15 minutes. Leave out the `end` key - if not set, Icinga 2 will not check against any
204 end time for this notification.
206 apply Notification "mail" to Service {
207 import "generic-notification"
208 notification_command = "mail-notification"
209 users = [ "icingaadmin" ]
211 times.begin = 15m // delay first notification
213 assign where service.name == "ping4"
216 ### <a id="notification-filters-state-type"></a> Notification Filters by State and Type
218 If there are no notification state and type filter attributes defined at the `Notification`
219 or `User` object Icinga 2 assumes that all states and types are being notified.
221 Available state and type filters for notifications are:
223 template Notification "generic-notification" {
225 notification_state_filter = [ Warning, Critical, Unknown ]
226 notification_type_filter = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart,
227 FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
230 If you are familiar with Icinga 1.x `notification_options` please note that they have been split
231 into type and state, and allow more fine granular filtering for example on downtimes and flapping.
232 You can filter for acknowledgements and custom notifications too.