]> granicus.if.org Git - icinga2/commitdiff
Update documentation for notification commands.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 12 Dec 2013 08:44:59 +0000 (09:44 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 12 Dec 2013 08:45:36 +0000 (09:45 +0100)
Fixes #5259

doc/3.02-commands.md

index 4fb52889532f4e511be43b82c5332cc80093c7c2..d90e35e4b09648e684eb83a120e3579a822f6c6f 100644 (file)
@@ -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 <<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