2014-02-05 15:53:22 +01:00
|
|
|
## <a id="notifications"></a> Notifications
|
2013-10-02 10:13:24 +02:00
|
|
|
|
2014-04-06 10:57:51 +02:00
|
|
|
Notifications for service and host problems are an integral part of your
|
|
|
|
monitoring setup.
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-04-06 10:57:51 +02:00
|
|
|
There are many ways of sending notifications, e.g. by e-mail, XMPP,
|
|
|
|
IRC, Twitter, etc. On its own Icinga 2 does not know how to send notifications.
|
|
|
|
Instead it relies on external mechanisms such as shell scripts to notify users.
|
|
|
|
|
|
|
|
A notification specification requires one or more users (and/or user groups)
|
|
|
|
who will be notified in case of problems. These users must have all custom
|
|
|
|
attributes defined which will be used in the `NotificationCommand` on execution.
|
2014-04-04 18:41:54 +02:00
|
|
|
|
|
|
|
TODO
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2013-10-21 21:43:17 +02:00
|
|
|
The user `icingaadmin` in the example below will get notified only on `WARNING` and
|
2013-10-18 00:11:35 +02:00
|
|
|
`CRITICAL` states and `problem` and `recovery` notification types.
|
|
|
|
|
|
|
|
object User "icingaadmin" {
|
2014-03-31 18:38:15 +02:00
|
|
|
display_name = "Icinga 2 Admin"
|
|
|
|
enable_notifications = 1
|
2014-04-07 13:59:41 +02:00
|
|
|
notification_state_filter = [ OK, Warning, Critical ]
|
|
|
|
notification_type_filter = [ Problem, Recovery ]
|
2014-04-04 18:41:54 +02:00
|
|
|
vars.email = "icinga@localhost"
|
|
|
|
vars.pager = "+49123456789"
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-04 22:57:56 +02:00
|
|
|
|
2014-04-06 21:15:25 +02:00
|
|
|
If you don't set the `notification_state_filter` and `notification_type_filter`
|
|
|
|
configuration attributes for the `User` object, all states and types will be
|
|
|
|
notified.
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2013-10-17 18:12:52 +02:00
|
|
|
You should choose which information you (and your notified users) are interested in
|
|
|
|
case of emergency, and also which information does not provide any value to you and
|
|
|
|
your environment.
|
|
|
|
|
2014-04-04 18:41:54 +02:00
|
|
|
There are various custom attributes available at runtime execution of the
|
|
|
|
`NotificationCommand`. The example below may or may not fit your needs.
|
|
|
|
|
2014-03-27 12:30:24 +01:00
|
|
|
object NotificationCommand "mail-service-notification" {
|
2014-03-31 18:38:15 +02:00
|
|
|
import "plugin-notification-command"
|
2014-03-27 12:30:24 +01:00
|
|
|
|
2014-04-07 21:30:27 +02:00
|
|
|
command = [ SysconfDir + "/icinga2/scripts/mail-notification.sh" ]
|
2014-01-15 21:04:01 +01:00
|
|
|
|
2014-04-04 22:57:56 +02:00
|
|
|
env = {
|
|
|
|
"NOTIFICATIONTYPE" = "$notification.type$"
|
|
|
|
"SERVICEDESC" = "$service.description$"
|
|
|
|
"HOSTALIAS" = "$host.displayname$",
|
|
|
|
"HOSTADDRESS" = "$host.vars.address$",
|
|
|
|
"SERVICESTATE" = "$service.state$",
|
|
|
|
"LONGDATETIME" = "$icinga.longdatetime$",
|
|
|
|
"SERVICEOUTPUT" = "$service.output$",
|
|
|
|
"NOTIFICATIONAUTHORNAME" = "$notification.author$",
|
|
|
|
"NOTIFICATIONCOMMENT" = "$notification.comment$",
|
|
|
|
"HOSTDISPLAYNAME" = "$host.displayname$",
|
|
|
|
"SERVICEDISPLAYNAME" = "$service.displayname$",
|
|
|
|
"USEREMAIL" = "$user.vars.email$"
|
|
|
|
}
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:04:01 +01:00
|
|
|
The command attribute in the `mail-service-notification` command refers to the
|
|
|
|
shell script installed into `/etc/icinga2/scripts/mail-notification.sh`.
|
2014-04-07 14:31:30 +02:00
|
|
|
The macros specified in the `env` dictionary are exported as environment
|
2014-01-15 21:04:01 +01:00
|
|
|
variables and can be used in the notification script.
|
2013-10-18 00:11:35 +02:00
|
|
|
|
|
|
|
You can add all shared attributes to a `Notification` template which is inherited
|
|
|
|
to the defined notifications. That way you'll save duplicated attributes in each
|
|
|
|
`Notification` object. Attributes can be overridden locally.
|
2014-04-04 18:41:54 +02:00
|
|
|
|
|
|
|
TODO
|
|
|
|
|
2013-10-18 00:11:35 +02:00
|
|
|
template Notification "generic-notification" {
|
2014-03-31 18:38:15 +02:00
|
|
|
notification_interval = 15m
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-03-31 18:38:15 +02:00
|
|
|
notification_command = "mail-service-notification"
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-04-07 13:59:41 +02:00
|
|
|
notification_state_filter = [ Warning, Critical, Unknown ]
|
|
|
|
notification_type_filter = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart,
|
|
|
|
FlappingEnd, DowntimeStart,DowntimeEnd, DowntimeRemoved ]
|
2013-10-18 00:11:35 +02:00
|
|
|
|
|
|
|
notification_period = "24x7"
|
|
|
|
}
|
|
|
|
|
2014-04-06 21:15:25 +02:00
|
|
|
The time period `24x7` is shipped as example configuration with Icinga 2.
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-03-29 01:13:28 +01:00
|
|
|
Use the `apply` keyword to create `Notification` objects for your services:
|
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
apply Notification "mail" to Service {
|
2014-03-31 18:38:15 +02:00
|
|
|
import "generic-notification"
|
2014-03-29 01:13:28 +01:00
|
|
|
|
2014-03-31 18:38:15 +02:00
|
|
|
notification_command = "mail-notification"
|
|
|
|
users = [ "icingaadmin" ]
|
2014-03-29 01:13:28 +01:00
|
|
|
|
2014-04-05 22:32:52 +02:00
|
|
|
assign where service.name == "mysql"
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
|
|
|
|
2014-04-06 21:15:25 +02:00
|
|
|
Instead of assigning users to notifications, you can also add the `user_groups`
|
|
|
|
attribute with a list of user groups to the `Notification` object. Icinga 2 will
|
|
|
|
resolve all group members and send notifications to all of them.
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-02-05 15:53:22 +01:00
|
|
|
### <a id="notification-escalations"></a> Notification Escalations
|
2013-10-10 19:05:49 +02:00
|
|
|
|
2013-10-18 00:11:35 +02:00
|
|
|
When a problem notification is sent and a problem still exists after re-notification
|
|
|
|
you may want to escalate the problem to the next support level. A different approach
|
|
|
|
is to configure the default notification by email, and escalate the problem via sms
|
|
|
|
if not already solved.
|
|
|
|
|
|
|
|
You can define notification start and end times as additional configuration
|
|
|
|
attributes making the `Notification` object a so-called `notification escalation`.
|
|
|
|
Using templates you can share the basic notification attributes such as users or the
|
|
|
|
`notification_interval` (and override them for the escalation then).
|
|
|
|
|
|
|
|
Using the example from above, you can define additional users being escalated for sms
|
|
|
|
notifications between start and end time.
|
|
|
|
|
|
|
|
object User "icinga-oncall-2nd-level" {
|
2014-03-31 18:38:15 +02:00
|
|
|
display_name = "Icinga 2nd Level"
|
|
|
|
enable_notifications = true
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-04-05 22:32:52 +02:00
|
|
|
vars.mobile = "+1 555 424642"
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
object User "icinga-oncall-1st-level" {
|
2014-03-31 18:38:15 +02:00
|
|
|
display_name = "Icinga 1st Level"
|
|
|
|
enable_notifications = true
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-04-05 22:32:52 +02:00
|
|
|
vars.mobile = "+1 555 424642"
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-06 21:15:25 +02:00
|
|
|
Define an additional `NotificationCommand` for SMS notifications.
|
2013-10-18 00:11:35 +02:00
|
|
|
|
|
|
|
> **Note**
|
|
|
|
>
|
2014-04-06 21:15:25 +02:00
|
|
|
> The example is not complete as there are many different SMS providers.
|
|
|
|
> Please note that sending SMS notifications will require an SMS provider
|
2013-10-18 00:11:35 +02:00
|
|
|
> or local hardware with a sim card active.
|
|
|
|
|
|
|
|
object NotificationCommand "sms-notification" {
|
2014-03-31 13:27:39 +02:00
|
|
|
command = PluginDir + "/send_sms_notification $mobile$ ..."
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
The two new notification escalations are added onto the host `localhost`
|
|
|
|
and its service `ping4` using the `generic-notification` template.
|
2014-04-06 21:15:25 +02:00
|
|
|
The user `icinga-oncall-2nd-level` will get notified by SMS (`sms-notification`
|
2013-10-18 00:11:35 +02:00
|
|
|
command) after `30m` until `1h`.
|
|
|
|
|
|
|
|
> **Note**
|
|
|
|
>
|
|
|
|
> The `notification_interval` was set to 15m in the `generic-notification`
|
|
|
|
> template example. Lower that value in your escalations by using a secondary
|
|
|
|
> template or overriding the attribute directly in the `notifications` array
|
|
|
|
> position for `escalation-sms-2nd-level`.
|
|
|
|
|
|
|
|
If the problem does not get resolved or acknowledged preventing further notifications
|
|
|
|
the `escalation-sms-1st-level` user will be escalated `1h` after the initial problem was
|
|
|
|
notified, but only for one hour (`2h` as `end` key for the `times` dictionary).
|
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
apply Notification "mail" to Service {
|
2014-03-31 18:38:15 +02:00
|
|
|
import "generic-notification"
|
|
|
|
notification_command = "mail-notification"
|
|
|
|
users = [ "icingaadmin" ]
|
2014-03-29 01:13:28 +01:00
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
assign where service.name == "ping4"
|
2014-03-29 01:13:28 +01:00
|
|
|
}
|
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
apply Notification "escalation-sms-2nd-level" to Service {
|
2014-03-31 18:38:15 +02:00
|
|
|
import "generic-notification"
|
|
|
|
notification_command = "sms-notification"
|
|
|
|
users = [ "icinga-oncall-2nd-level" ]
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-03-29 01:13:28 +01:00
|
|
|
times = {
|
2014-03-31 18:38:15 +02:00
|
|
|
begin = 30m
|
2014-03-29 01:13:28 +01:00
|
|
|
end = 1h
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
2014-04-05 14:53:12 +02:00
|
|
|
|
|
|
|
assign where service.name == "ping4"
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
2014-03-29 01:13:28 +01:00
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
apply Notification "escalation-sms-1st-level" to Service {
|
2014-03-31 18:38:15 +02:00
|
|
|
import "generic-notification"
|
|
|
|
notification_command = "sms-notification"
|
|
|
|
users = [ "icinga-oncall-1st-level" ]
|
2014-03-29 01:13:28 +01:00
|
|
|
|
|
|
|
times = {
|
2014-03-31 18:38:15 +02:00
|
|
|
begin = 1h
|
2014-03-29 01:13:28 +01:00
|
|
|
end = 2h
|
|
|
|
}
|
2014-04-05 14:53:12 +02:00
|
|
|
|
|
|
|
assign where service.name == "ping4"
|
2014-03-29 01:13:28 +01:00
|
|
|
}
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-04-06 21:15:25 +02:00
|
|
|
Instead of assigning users to notifications, you can also add the `user_groups`
|
|
|
|
attribute with a list of user groups to the `Notification` object. Icinga 2 will
|
|
|
|
resolve all group members and send notifications and notification escalations to
|
|
|
|
all of them.
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-02-05 15:53:22 +01:00
|
|
|
### <a id="first-notification-delay"></a> First Notification Delay
|
2013-10-18 00:11:35 +02:00
|
|
|
|
|
|
|
Sometimes the problem in question should not be notified when the first notification
|
|
|
|
happens, but a defined time duration afterwards. In Icinga 2 you can use the `times`
|
|
|
|
dictionary and set `begin = 15m` as key and value if you want to suppress notifications
|
|
|
|
in the first 15 minutes. Leave out the `end` key - if not set, Icinga 2 will not check against any
|
|
|
|
end time for this notification.
|
|
|
|
|
2014-04-05 14:53:12 +02:00
|
|
|
apply Notification "mail" to Service {
|
2014-03-31 18:38:15 +02:00
|
|
|
import "generic-notification"
|
|
|
|
notification_command = "mail-notification"
|
|
|
|
users = [ "icingaadmin" ]
|
2013-10-18 00:11:35 +02:00
|
|
|
|
2014-03-29 01:13:28 +01:00
|
|
|
times.begin = 15m // delay first notification
|
2014-04-05 14:53:12 +02:00
|
|
|
|
|
|
|
assign where service.name == "ping4"
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
|
|
|
|
2014-02-05 15:53:22 +01:00
|
|
|
### <a id="notification-filters-state-type"></a> Notification Filters by State and Type
|
2013-10-18 00:11:35 +02:00
|
|
|
|
|
|
|
If there are no notification state and type filter attributes defined at the `Notification`
|
|
|
|
or `User` object Icinga 2 assumes that all states and types are being notified.
|
|
|
|
|
|
|
|
Available state and type filters for notifications are:
|
|
|
|
|
|
|
|
template Notification "generic-notification" {
|
|
|
|
|
2014-04-07 13:59:41 +02:00
|
|
|
notification_state_filter = [ Warning, Critical, Unknown ]
|
|
|
|
notification_type_filter = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart,
|
|
|
|
FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
|
2013-10-18 00:11:35 +02:00
|
|
|
}
|
2013-10-10 19:05:49 +02:00
|
|
|
|
2014-04-06 21:15:25 +02:00
|
|
|
If you are familiar with Icinga 1.x `notification_options` please note that they have been split
|
|
|
|
into type and state, and allow more fine granular filtering for example on downtimes and flapping.
|
|
|
|
You can filter for acknowledgements and custom notifications too.
|