Page 1 of 1

Send email with Subject and CC list in nagios Core

Posted: Thu Oct 18, 2018 6:53 am
by anuruddhak
I already installed nagios core and add few host to check the stats

when I get the notification I need came up with custom subject line and also need to cc to few peoples

how I can do this ? is that possible to do using mail utility ?

Re: Send email with Subject and CC list in nagios Core

Posted: Thu Oct 18, 2018 4:51 pm
by npolovenko
Hello, @anuruddhak. Can you show me the notification commands you're currently using? They should be in the /usr/local/nagios/etc/commands.cfg file.

Re: Send email with Subject and CC list in nagios Core

Posted: Fri Oct 19, 2018 1:14 am
by anuruddhak
notify-host-by-email command

/usr/bin/printf "%b" "***** Location $HOSTNAME$ Health Report*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

I need to use below script with the notify-host-by-email command

cat <<EOF | sendmail -t
To: [email protected]
Subject: Testing
From: [email protected]
Cc: [email protected]

This is a test message
EOF

please note that I'm already integrate with Amazon SES with postfix that's wahy I used sendmail

Re: Send email with Subject and CC list in nagios Core

Posted: Fri Oct 19, 2018 11:09 am
by npolovenko
@anuruddhak, You can use the following commands if you want to use the sendmail. Change my email address after -f to whatever email should be in the From field.

notify-host-by-email command

Code: Select all

/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 -f "[email protected]" -vt $CONTACTEMAIL$ 
notify-service-by-email command

Code: Select all

/usr/bin/printf "%b" "Subject: $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/sbin/sendmail  -f "[email protected]" -vt $CONTACTEMAIL$
You can change:
Subject: $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$
To whatever you want to have in the email subject, for example, "Test".



As far as CC multiple recipients, would the second email always be the same? You can create a separate contact in XI and have it use the same notification command. That way the notification will always fire for the second contact as well. Does this make sense?

Re: Send email with Subject and CC list in nagios Core

Posted: Mon Oct 22, 2018 1:38 am
by anuruddhak
thank you for the support it's working now.

if I create the new contact in contact.cfg and mention in host configuration file under contact group it's working.but in the email unable to visible to email address.how can I fixed that ?

can we mention the cc email address in command like this

/usr/bin/printf "%b" "Subject: $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/sbin/sendmail -f "[email protected]" cc [email protected] -vt $CONTACTEMAIL$

Re: Send email with Subject and CC list in nagios Core

Posted: Mon Oct 22, 2018 2:38 pm
by scottwilkerson
you should be able to add it like this

Code: Select all

/usr/bin/printf "%b" "Subject: $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/sbin/sendmail -f "[email protected]" -vt $CONTACTEMAIL$ cc:[email protected]