Configuring email and SMS notifications.

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.
dheerushops
Posts: 47
Joined: Fri Dec 06, 2019 7:44 am

Re: Configuring email and SMS notifications.

Post by dheerushops »

I copied them.

Is the below syntax is right ?

# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\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$
}

# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/local/nagios/libexec/sms_send.sh "--Nagios Host Notification-- Host: $HOSTNAME$, State: $HOSTSTATE$, Time: $LONGDATETIME$"
}




--->Can I add above entries in to commands.cfg file.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Configuring email and SMS notifications.

Post by Box293 »

If you copied them then the syntax should be fine. Add them and restart Nagios.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dheerushops
Posts: 47
Joined: Fri Dec 06, 2019 7:44 am

Re: Configuring email and SMS notifications.

Post by dheerushops »

I have added entries in commands.cfg file.

[root@nagiosserver objects]# tail commands.cfg
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\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$
}

# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/local/nagios/libexec/sms_send.sh "--Nagios Host Notification-- Host: $HOSTNAME$, State: $HOSTSTATE$, Time: $LONGDATETIME$"
}
[root@nagiosserver objects]#


Can you please tell the process to receive alerts into mail and SMS
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Configuring email and SMS notifications.

Post by scottwilkerson »

You would then add these commands as host_notification_commands to contacts in Nagios.

Add the contacts to the hosts you want them to get notifications for.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
dheerushops
Posts: 47
Joined: Fri Dec 06, 2019 7:44 am

Re: Configuring email and SMS notifications.

Post by dheerushops »

I have added host_notification_commands to contacts.cfg. But not received any email alert. Can you please check.


define contact {

contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email dhe*@gmail.com ; CHANGE THIS TO YOUR EMAIL ADDRESS ******

service_notification_period 24x7
service_notification_options w,u,c,r,f,s
service_notification_commands notify-service-by-email
host_notification_period 24x7
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
}
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Configuring email and SMS notifications.

Post by scottwilkerson »

not sure why but you have this line in the definition twice

Code: Select all

service_notification_commands notify-service-by-email
Also, do you have this contact (nagiosadmin) added as a contact for any of your hosts/services?
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
dheerushops
Posts: 47
Joined: Fri Dec 06, 2019 7:44 am

Re: Configuring email and SMS notifications.

Post by dheerushops »

I have edited the file.

define contact {

contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email dhe*@gmail.com ; CHANGE THIS TO YOUR EMAIL ADDRESS ******

service_notification_period 24x7
service_notification_options w,u,c,r,f,s
service_notification_commands notify-service-by-email
host_notification_period 24x7
host_notification_options d,u,r
host_notification_commands notify-host-by-email
}


And I have added contact (nagiosadmin) in hosts.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Configuring email and SMS notifications.

Post by scottwilkerson »

Do you see nagios attempting to send notification of the Notification report in the UI?
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Configuring email and SMS notifications.

Post by scottwilkerson »

Can you send a test message from the CLI

Code: Select all

echo "test message"/bin/mail -s "** TEST MESSAGE **" your-email@address.com
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
dheerushops
Posts: 47
Joined: Fri Dec 06, 2019 7:44 am

Re: Configuring email and SMS notifications.

Post by dheerushops »

[root@nagiosserver ~]# echo "test message"/bin/mail -s "** TEST MESSAGE **" dhe*@gmail.com
test message/bin/mail -s ** TEST MESSAGE** dhe*@gmail.com
[root@nagiosserver ~]#
Locked