Page 2 of 3

Re: Configuring email and SMS notifications.

Posted: Fri Feb 07, 2020 10:31 am
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.

Re: Configuring email and SMS notifications.

Posted: Mon Feb 10, 2020 4:51 pm
by Box293
If you copied them then the syntax should be fine. Add them and restart Nagios.

Re: Configuring email and SMS notifications.

Posted: Tue Feb 11, 2020 11:42 am
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

Re: Configuring email and SMS notifications.

Posted: Wed Feb 12, 2020 8:13 am
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.

Re: Configuring email and SMS notifications.

Posted: Thu Feb 13, 2020 9:42 am
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
}

Re: Configuring email and SMS notifications.

Posted: Thu Feb 13, 2020 9:51 am
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?

Re: Configuring email and SMS notifications.

Posted: Thu Feb 13, 2020 1:17 pm
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.

Re: Configuring email and SMS notifications.

Posted: Fri Feb 14, 2020 2:41 pm
by scottwilkerson
Do you see nagios attempting to send notification of the Notification report in the UI?

Re: Configuring email and SMS notifications.

Posted: Fri Feb 14, 2020 2:43 pm
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

Re: Configuring email and SMS notifications.

Posted: Fri Feb 14, 2020 3:53 pm
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 ~]#