Page 1 of 1
SMS API Integration With NMS
Posted: Fri Mar 11, 2016 11:27 am
by rlinux57
I have configured sms api with nagios but it won't work, i have added below code in commands.cfg file:
Code: Select all
# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/php /usr/local/nagios/sms/sendsms.php "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"
}
# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/bin/printf "%b" "***** 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/bin/php /usr/local/nagios/sms/sendsms.php "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **"
}
But when i run this file alone "/usr/bin/php /usr/local/nagios/sms/sendsms.php". It sends an sms.
I have attached the code example of sendsms.php.
Re: SMS API Integration With NMS
Posted: Fri Mar 11, 2016 1:30 pm
by rkennedy
@rlinux57 - did this have to do with your previous post, or are you still experiencing an issue?
Can you post the host / service and contact configuration that are using the notify-host-by-sms? Also, what are the permissions of /usr/local/nagios/sms/sendsms.php?
Re: SMS API Integration With NMS
Posted: Fri Mar 11, 2016 1:39 pm
by rlinux57
My previous post is regarding to email notification which has been fixed now. But i'm still facing issue with "notify by sms"
Code: Select all
[root@monitor ~]# ll /usr/local/nagios/sms/sendsms.php
-rwxrwx--x 1 nagios nagios 764 Mar 11 01:32 /usr/local/nagios/sms/sendsms.php
Code: Select all
[root@monitor ~]# cat /usr/local/nagios/etc/objects/contacts.cfg
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
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downt$
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime$
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-host-by-sms
email Email ID ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
###############################################################################
###############################################################################
#
# CONTACT GROUPS
#
###############################################################################
###############################################################################
# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
Code: Select all
cat /usr/local/nagios/etc/servers/shared-hosts.cfg
define host {
use linux-server
host_name Webs
alias Webs
address IP ADDRESS
action_url /nagiosgraph/cgi/showhost.cgi?host=$HOSTNAME$
contacts nagiosadmin
}
Code: Select all
[root@monitor ~]# ll /usr/local/nagios/etc/servers/shared-hosts.cfg
-rw-r--r-- 1 nagios nagios 2141 Mar 11 11:50 /usr/local/nagios/etc/servers/shared-hosts.cfg
Re: SMS API Integration With NMS
Posted: Fri Mar 11, 2016 3:17 pm
by hsmith
Can you su to the nagios user, and try to run the script from the command line again and see if it succeeds?
Re: SMS API Integration With NMS
Posted: Sat Mar 12, 2016 2:10 am
by rlinux57
I have fixed the issue, it was happened due to wrong syntax in commands.cfg file. Kindly let me know how to setup timeperiod of notify by email/sms, it send same trap/event again and again after sometime.
Re: SMS API Integration With NMS
Posted: Mon Mar 14, 2016 10:23 am
by rkennedy
Take a look at this link - in explains how time periods work and should answer your questions.
https://assets.nagios.com/downloads/nag ... riods.html
Is that what you were looking for?
Re: SMS API Integration With NMS
Posted: Tue Mar 15, 2016 11:11 am
by rlinux57
Yes this is what i'm looking for. Thanks for the guidance.

Re: SMS API Integration With NMS
Posted: Tue Mar 15, 2016 4:19 pm
by hsmith
Are we all right to close this post?
Re: SMS API Integration With NMS
Posted: Wed Mar 16, 2016 6:44 am
by rlinux57
Yes you can close it.
Re: SMS API Integration With NMS
Posted: Wed Mar 16, 2016 11:33 am
by bwallace
Glad we were able to help. We'll lock this thread now and feel free to open another should you require assistance with anything else.