mirror of https://github.com/Icinga/icinga2.git
parent
6b8d079fd2
commit
76cc69c701
|
@ -97,48 +97,71 @@ space).
|
||||||
|
|
||||||
### Notification Commands
|
### Notification Commands
|
||||||
|
|
||||||
`NotificationCommand` objects define how notifications are sent to external
|
`NotificationCommand` objects define how notifications are delivered to external
|
||||||
interfaces (E-Mail, XMPP, IRC, Twitter, etc).
|
interfaces (E-Mail, XMPP, IRC, Twitter, etc).
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
>
|
>
|
||||||
> `NotificationCommand` objects require the ITL template `plugin-notification-command`
|
> `NotificationCommand` objects require the ITL template `plugin-notification-command`
|
||||||
> to support native plugin based checks.
|
> to support native plugin-based notifications.
|
||||||
|
|
||||||
Below is an example using runtime macros from Icinga 2 (such as `$SERVICEOUTPUT$` for
|
Below is an example using runtime macros from Icinga 2 (such as `$SERVICEOUTPUT$` for
|
||||||
the current check output) sending an email to the user(s) associated with the
|
the current check output) sending an email to the user(s) associated with the
|
||||||
notification itself (`email` macro attribute provided as `$USERMACRO$`).
|
notification itself (`email` macro attribute provided as `$USERMACRO$`).
|
||||||
|
|
||||||
Please note the notation for better readability using multiple lines enclosed with
|
If you require default macro definitions, you can add a macro dictionary as shown for the
|
||||||
`{{{ ... }}}`. You can use a single line as argument item as well. If you require
|
|
||||||
default macro definitions, you can add a macro dictionary as shown for the
|
|
||||||
`CheckCommand` object.
|
`CheckCommand` object.
|
||||||
|
|
||||||
object NotificationCommand "mail-service-notification" inherits "plugin-notification-command" {
|
object NotificationCommand "mail-service-notification" inherits "plugin-notification-command" {
|
||||||
command = [
|
command = [ (IcingaSysconfDir + "/icinga2/scripts/mail-notification.sh") ],
|
||||||
"/usr/bin/printf",
|
|
||||||
"\"%b\"",
|
|
||||||
{{{\"***** Icinga *****
|
|
||||||
|
|
||||||
Notification Type: $NOTIFICATIONTYPE$
|
export_macros = [
|
||||||
|
"NOTIFICATIONTYPE",
|
||||||
Service: $SERVICEDESC$
|
"SERVICEDESC",
|
||||||
Host: $HOSTALIAS$
|
"HOSTALIAS",
|
||||||
Address: $HOSTADDRESS$
|
"HOSTADDRESS",
|
||||||
State: $SERVICESTATE$
|
"SERVICESTATE",
|
||||||
|
"LONGDATETIME",
|
||||||
Date/Time: $LONGDATETIME$
|
"SERVICEOUTPUT",
|
||||||
|
"NOTIFICATIONAUTHORNAME",
|
||||||
Additional Info: $SERVICEOUTPUT$
|
"NOTIFICATIONCOMMENT",
|
||||||
|
"HOSTDISPLAYNAME",
|
||||||
Comment: [$NOTIFICATIONAUTHORNAME$] $NOTIFICATIONCOMMENT$\"}}},
|
"SERVICEDISPLAYNAME",
|
||||||
"-s",
|
"USEREMAIL"
|
||||||
"\"$NOTIFICATIONTYPE$ - $HOSTDISPLAYNAME$ - $SERVICEDISPLAYNAME$ is $SERVICESTATE$\"",
|
|
||||||
"$USEREMAIL$"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
The command attribute in the `mail-service-notification` command refers to the following
|
||||||
|
shell script. The macros specified in the `export_macros` array are exported
|
||||||
|
as environment variables and can be used in the notification script:
|
||||||
|
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
template=$(cat <<TEMPLATE
|
||||||
|
***** Icinga *****
|
||||||
|
|
||||||
|
Notification Type: $NOTIFICATIONTYPE
|
||||||
|
|
||||||
|
Service: $SERVICEDESC
|
||||||
|
Host: $HOSTALIAS
|
||||||
|
Address: $HOSTADDRESS
|
||||||
|
State: $SERVICESTATE
|
||||||
|
|
||||||
|
Date/Time: $LONGDATETIME
|
||||||
|
|
||||||
|
Additional Info: $SERVICEOUTPUT
|
||||||
|
|
||||||
|
Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
|
||||||
|
TEMPLATE
|
||||||
|
)
|
||||||
|
|
||||||
|
/usr/bin/printf "%b" $template | mail -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME - $SERVICEDISPLAYNAME is $SERVICESTATE" $USEREMAIL
|
||||||
|
|
||||||
|
> **Best Practice**
|
||||||
|
>
|
||||||
|
> While it's possible to specify the entire notification command right
|
||||||
|
> in the NotificationCommand object it is generally advisable to create a
|
||||||
|
> shell script in the `/etc/icinga2/scripts` directory and have the
|
||||||
|
> NotificationCommand object refer to that.
|
||||||
|
|
||||||
### Event Commands
|
### Event Commands
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue