Hi currently Nagios sends notifications from nagios@server.domain.com, How do I go about configuring this? Thanks
8 Answers
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.
- 3,700
- 1
- 23
- 29
-
That's what I did, and it worked fine. Different alerts actually get sent out by different accounts because of our automated ticketing program. – breadly Oct 09 '09 at 17:25
-
2I added this between `/bin/mail` and the `-s` – jgritty Nov 20 '14 at 00:50
-
1@RainyRat - any chance you can edit your answer to place the -r as first parameter? - as other answers suggest then happy to upvote your answer :o) – Dazed Jun 12 '19 at 16:13
Couldn't get the "-- -r nagios@domain.com" 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 nagios@domain.com.
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$ -- -fnagios@domain.com
- 31
- 1
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.
- 68,316
- 31
- 175
- 255
- 31
- 1
I was able to do this by changing the command to something liek:
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$ -- -r $ADMINEMAIL$
The magic is the '-- -r' part.
ADMINEMAIL is set in your nagios.cfg, but could be any email address for the 'From' address.
None of the above works with current versions of Nagios and/or Postfix. The flag that needs to be added to the Nagios "host-notify-by-mail" or "service-notify-by-mail" commands in the file "commands.cfg" reads as follows:
-a "From: john.doe@uzh.ch"
Note that the quotation marks are essential!
- 407
- 1
- 6
- 17
-
This changes the From-address, but it does not change the Return-Path address. You may want to change both. – Christopher K. Jul 08 '19 at 09:32
This is defined in etc/nagios3/conf.d/contacts_nagios2.cfg
You can define users with e-mails and groups. Also you can configure different groups for different purposes - e.g. web_admin for http alerts, admin for host alerts, etc.
-
In the contacts config, you configure the *recipients* of the mails sent, not the *sender* address. This question is about how to change the sender address ("where it sends mails *from*"). – Christopher K. Jul 08 '19 at 09:27
For the bsd-mailx
that my /usr/bin/mail
command links to, nothing seemed to work, so I used /usr/sbin/sendmail
(provided by postfix) like this:
command_line /usr/bin/printf "%b" "Subject:** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **\n\n**** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/sbin/sendmail -r "nagios@example.com" $CONTACTEMAIL$
For sendmail
two things to consider:
- Use
-r
to specify the return path (and from-address) - There is no
-s
for the subject. Instead, add theSubject:
mail header in theprintf
followed by two newlines\n\n
- 291
- 2
- 6