Configuring email and SMS notifications.
-
- Posts: 47
- Joined: Fri Dec 06, 2019 7:44 am
Re: Configuring email and SMS notifications.
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.
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.
- Box293
- Too Basu
- Posts: 5126
- Joined: Sun Feb 07, 2010 10:55 pm
- Location: Deniliquin, Australia
- Contact:
Re: Configuring email and SMS notifications.
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.
-
- Posts: 47
- Joined: Fri Dec 06, 2019 7:44 am
Re: Configuring email and SMS notifications.
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
[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
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Configuring email and SMS notifications.
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.
Add the contacts to the hosts you want them to get notifications for.
-
- Posts: 47
- Joined: Fri Dec 06, 2019 7:44 am
Re: Configuring email and SMS notifications.
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
}
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
}
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Configuring email and SMS notifications.
not sure why but you have this line in the definition twice
Also, do you have this contact (nagiosadmin) added as a contact for any of your hosts/services?
Code: Select all
service_notification_commands notify-service-by-email
-
- Posts: 47
- Joined: Fri Dec 06, 2019 7:44 am
Re: Configuring email and SMS notifications.
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.
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.
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Configuring email and SMS notifications.
Do you see nagios attempting to send notification of the Notification report in the UI?
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Configuring email and SMS notifications.
Can you send a test message from the CLI
Code: Select all
echo "test message"/bin/mail -s "** TEST MESSAGE **" your-email@address.com
-
- Posts: 47
- Joined: Fri Dec 06, 2019 7:44 am
Re: Configuring email and SMS notifications.
[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 ~]#
test message/bin/mail -s ** TEST MESSAGE** dhe*@gmail.com
[root@nagiosserver ~]#