Send email with Subject and CC list in nagios Core

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
anuruddhak
Posts: 8
Joined: Thu Oct 18, 2018 6:47 am

Send email with Subject and CC list in nagios Core

Post 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 ?
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

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

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
anuruddhak
Posts: 8
Joined: Thu Oct 18, 2018 6:47 am

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

Post 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: test_TO@gmail.com
Subject: Testing
From: Test_From@gmail.com
Cc: Test_CC@gmail.com

This is a test message
EOF

please note that I'm already integrate with Amazon SES with postfix that's wahy I used sendmail
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

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

Post 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 "nik@nagios.com" -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 "nik@nagios.com" -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?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
anuruddhak
Posts: 8
Joined: Thu Oct 18, 2018 6:47 am

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

Post 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 "nik@nagios.com" cc Test@gmail.com -vt $CONTACTEMAIL$
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

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

Post 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 "nik@nagios.com" -vt $CONTACTEMAIL$ cc:Test@gmail.com 
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked