diff --git a/doc/3-monitoring-basics.md b/doc/3-monitoring-basics.md index 4d44cc2dd..f432e4d43 100644 --- a/doc/3-monitoring-basics.md +++ b/doc/3-monitoring-basics.md @@ -1583,7 +1583,10 @@ defaults can always be overwritten locally. #### mail-host-notification -A quick overview of the arguments that can be used. See also [host runtime +The `mail-host-notification` NotificationCommand object uses the +example notification script located in `/etc/icinga2/scripts/mail-host-notification.sh`. + +Here is a quick overview of the arguments that can be used. See also [host runtime macros](3-monitoring-basics.md#-host-runtime-macros) for further information. @@ -1600,13 +1603,16 @@ information. `notification_address6` | **Optional.** The host's IPv6 address. Defaults to `$address6$`. `notification_author` | **Optional.** Comment author. Defaults to `$notification.author$`. `notification_comment` | **Optional.** Comment text. Defaults to `$notification.comment$`. - `notification_from` | **Optional.** Define a valid From: string (e.g. `"Icinga 2 Host Monitoring "`) + `notification_from` | **Optional.** Define a valid From: string (e.g. `"Icinga 2 Host Monitoring "`). Requires `GNU mailutils` (Debian/Ubuntu) or `mailx` (RHEL/SUSE). `notification_icingaweb2url` | **Optional.** Define URL to your Icinga Web 2 (e.g. `"https://www.example.com/icingaweb2"`) `notification_logtosyslog` | **Optional.** Set `true` to log notification events to syslog; useful for debugging. Defaults to `false`. #### mail-service-notification -A quick overview of the arguments that can be used. See also [service runtime +The `mail-service-notification` NotificationCommand object uses the +example notification script located in `/etc/icinga2/scripts/mail-service-notification.sh`. + +Here is a quick overview of the arguments that can be used. See also [service runtime macros](3-monitoring-basics.md#-service-runtime-macros) for further information. @@ -1625,7 +1631,7 @@ information. `notification_address6` | **Optional.** The host's IPv6 address. Defaults to `$address6$`. `notification_author` | **Optional.** Comment author. Defaults to `$notification.author$`. `notification_comment` | **Optional.** Comment text. Defaults to `$notification.comment$`. - `notification_from` | **Optional.** Define a valid From: string (e.g. `"Icinga 2 Host Monitoring "`) + `notification_from` | **Optional.** Define a valid From: string (e.g. `"Icinga 2 Host Monitoring "`). Requires `GNU mailutils` (Debian/Ubuntu) or `mailx` (RHEL/SUSE). `notification_icingaweb2url` | **Optional.** Define URL to your Icinga Web 2 (e.g. `"https://www.example.com/icingaweb2"`) `notification_logtosyslog` | **Optional.** Set `true` to log notification events to syslog; useful for debugging. Defaults to `false`. diff --git a/doc/9-object-types.md b/doc/9-object-types.md index 7c6231c9f..0f4559d55 100644 --- a/doc/9-object-types.md +++ b/doc/9-object-types.md @@ -1113,7 +1113,10 @@ Example: required = true value = "$notification_servicename$" } - "-f" = "$notification_from$" + "-f" = { + value = "$notification_from$" + description = "Set from address. Requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)" + } "-i" = "$notification_icingaweb2url$" "-l" = { required = true diff --git a/etc/icinga2/conf.d/commands.conf b/etc/icinga2/conf.d/commands.conf index 05e08c261..2aaf44f86 100644 --- a/etc/icinga2/conf.d/commands.conf +++ b/etc/icinga2/conf.d/commands.conf @@ -1,5 +1,11 @@ /* Command objects */ +/* Notification Commands + * + * Please check the documentation for all required and + * optional parameters. + */ + object NotificationCommand "mail-host-notification" { command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ] @@ -15,7 +21,10 @@ object NotificationCommand "mail-host-notification" { required = true value = "$notification_date$" } - "-f" = "$notification_from$" + "-f" = { + value = "$notification_from$" + description = "Set from address. Requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)" + } "-i" = "$notification_icingaweb2url$" "-l" = { required = true @@ -78,7 +87,10 @@ object NotificationCommand "mail-service-notification" { required = true value = "$notification_servicename$" } - "-f" = "$notification_from$" + "-f" = { + value = "$notification_from$" + description = "Set from address. Requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)" + } "-i" = "$notification_icingaweb2url$" "-l" = { required = true diff --git a/etc/icinga2/scripts/mail-host-notification.sh b/etc/icinga2/scripts/mail-host-notification.sh index fba41c890..d9ab70754 100755 --- a/etc/icinga2/scripts/mail-host-notification.sh +++ b/etc/icinga2/scripts/mail-host-notification.sh @@ -1,4 +1,6 @@ -#!/bin/sh +#!/usr/bin/env bash +# +# Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) PROG="`basename $0`" HOSTNAME="`hostname`" @@ -28,7 +30,7 @@ Optional parameters: -b NOTIFICATIONAUTHORNAME (\$notification.author\$) -c NOTIFICATIONCOMMENT (\$notification.comment\$) -i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset) - -f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils) + -f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)) -v (\$notification_sendtosyslog\$, Default: false) EOF @@ -133,8 +135,17 @@ fi ## Send the mail using the $MAILBIN command. ## If an explicit sender was specified, try to set it. if [ -n "$MAILFROM" ] ; then - /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \ - | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL + + ## Modify this for your own needs! + + ## Debian/Ubuntu use mailutils which requires `-a` to append the header + if [ -f /etc/debian_version ]; then + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL + ## Other distributions (RHEL/SUSE/etc.) prefer mailx which sets a sender address with `-r` + else + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL + fi + else /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \ | $MAILBIN -s "$SUBJECT" $USEREMAIL diff --git a/etc/icinga2/scripts/mail-service-notification.sh b/etc/icinga2/scripts/mail-service-notification.sh index 48fe42043..dca23dc63 100755 --- a/etc/icinga2/scripts/mail-service-notification.sh +++ b/etc/icinga2/scripts/mail-service-notification.sh @@ -1,4 +1,6 @@ -#!/bin/sh +#!/usr/bin/env bash +# +# Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) PROG="`basename $0`" HOSTNAME="`hostname`" @@ -30,7 +32,7 @@ Optional parameters: -b NOTIFICATIONAUTHORNAME (\$notification.author\$) -c NOTIFICATIONCOMMENT (\$notification.comment\$) -i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset) - -f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils) + -f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)) -v (\$notification_sendtosyslog\$, Default: false) EOF @@ -139,8 +141,17 @@ fi ## Send the mail using the $MAILBIN command. ## If an explicit sender was specified, try to set it. if [ -n "$MAILFROM" ] ; then - /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \ - | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL + + ## Modify this for your own needs! + + ## Debian/Ubuntu use mailutils which requires `-a` to append the header + if [ -f /etc/debian_version ]; then + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL + ## Other distributions (RHEL/SUSE/etc.) prefer mailx which sets a sender address with `-r` + else + /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL + fi + else /usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \ | $MAILBIN -s "$SUBJECT" $USEREMAIL