Question
Change the sender for notifications generated from the mail command with Icinga.
Solution
Icinga Configuration
This depends on the mail notification command you’re using. The provided examples for mail-{host,service}-notification
provide an additional attribute notification_from
which can be set in your notification object/apply rule.
apply Notification "mail-icingaadmin" to Service {
....
vars.notification_from = "Icinga Notifications <icinga-notifications@server.com>"
...
assign where host.vars.notification.mail
}
Custom Command
Depending on the mail
binary and distribution involved, the parameters are different. Example from mail-service-notification.sh:
## 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
MTA
Postfix, exim, sendmail take the daemon user into account. For all distributions use icinga
, Debian uses nagios
for historical reasons.
Postfix
Update the canonical map and restart your MTA.
vim /etc/postfix/main.cf
sender_canonical_maps = hash:/etc/postfix/canonical
vim /etc/postfix/canonical
icinga icinga-notifications@server.com
postmap hash:/etc/postfix/canonical
systemctl restart postfix
Resources:
http://www.postfix.org/ADDRESS_REWRITING_README.html
http://www.postfix.org/postconf.5.html