From 76cc69c701b34c011f9ff54e50e205405849ce0d Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 12 Dec 2013 09:44:59 +0100 Subject: [PATCH] Update documentation for notification commands. Fixes #5259 --- doc/3.02-commands.md | 73 +++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/doc/3.02-commands.md b/doc/3.02-commands.md index 4fb528895..d90e35e4b 100644 --- a/doc/3.02-commands.md +++ b/doc/3.02-commands.md @@ -97,48 +97,71 @@ space). ### 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). > **Note** > > `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 the current check output) sending an email to the user(s) associated with the notification itself (`email` macro attribute provided as `$USERMACRO$`). -Please note the notation for better readability using multiple lines enclosed with -`{{{ ... }}}`. 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 +If you require default macro definitions, you can add a macro dictionary as shown for the `CheckCommand` object. object NotificationCommand "mail-service-notification" inherits "plugin-notification-command" { - command = [ - "/usr/bin/printf", - "\"%b\"", - {{{\"***** Icinga ***** - - Notification Type: $NOTIFICATIONTYPE$ - - Service: $SERVICEDESC$ - Host: $HOSTALIAS$ - Address: $HOSTADDRESS$ - State: $SERVICESTATE$ - - Date/Time: $LONGDATETIME$ - - Additional Info: $SERVICEOUTPUT$ - - Comment: [$NOTIFICATIONAUTHORNAME$] $NOTIFICATIONCOMMENT$\"}}}, - "-s", - "\"$NOTIFICATIONTYPE$ - $HOSTDISPLAYNAME$ - $SERVICEDISPLAYNAME$ is $SERVICESTATE$\"", - "$USEREMAIL$" + command = [ (IcingaSysconfDir + "/icinga2/scripts/mail-notification.sh") ], + + export_macros = [ + "NOTIFICATIONTYPE", + "SERVICEDESC", + "HOSTALIAS", + "HOSTADDRESS", + "SERVICESTATE", + "LONGDATETIME", + "SERVICEOUTPUT", + "NOTIFICATIONAUTHORNAME", + "NOTIFICATIONCOMMENT", + "HOSTDISPLAYNAME", + "SERVICEDISPLAYNAME", + "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 <