Defining the email address which Nagios sends emails from
Hi currently Nagios sends notifications from [email protected], How do I go about configuring this? Thanks
In a default Nagios install, it's also defined in the host-notify-by-mail
or service-notify-by-mail
commands, which you'll find in commands.cfg
. The default would be something like:
/bin/echo -e "$NOTIFICATIONTYPE$ - Service notification for $SERVICEDESC$ from host $HOSTNAME$ - $HOSTALIAS$\n$SERVICEDESC$: $SERVICEOUTPUT$\n" | /bin/mail -s '$NOTIFICATIONTYPE$/$SERVICESTATE$ - $HOSTNAME$/$SERVICEDESC$' $CONTACTEMAIL$
So just add a -r sender@address
option to the mail command, and that should work.
Couldn't get the "-- -r [email protected]" solution to work. It turns out options after "--" are options for sendmail. Looking at sendmail options, it should be "-fnagios@domain" NOTE NO SPACE between -f and [email protected].
So the following is now working :-
command_line /usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTNAME$\Address: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$LONGSERVICEOUTPUT$" | /bin/mail -s "$SERVICESTATE$ - Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ -- [email protected]
Put -r nagios@domain before $CONTACTEMAIL$ on commands.cfg
What worked for me was adding -r $ADMINEMAIL$
before the -s
(immediately after /bin/mail
), and of course $ADMINEMAIL$
has to be set in nagios.cfg
using the admin_email
setting.