SMS API Integration With NMS

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
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

SMS API Integration With NMS

Post 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.
Attachments
sendsms.txt
(725 Bytes) Downloaded 548 times
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: SMS API Integration With NMS

Post 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?
Former Nagios Employee
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: SMS API Integration With NMS

Post 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
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: SMS API Integration With NMS

Post 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?
Former Nagios Employee.
me.
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: SMS API Integration With NMS

Post 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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: SMS API Integration With NMS

Post 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?
Former Nagios Employee
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: SMS API Integration With NMS

Post by rlinux57 »

Yes this is what i'm looking for. Thanks for the guidance. :)
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: SMS API Integration With NMS

Post by hsmith »

Are we all right to close this post?
Former Nagios Employee.
me.
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: SMS API Integration With NMS

Post by rlinux57 »

Yes you can close it.
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: SMS API Integration With NMS

Post 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.
Be sure to check out the Knowledgebase for helpful articles and solutions!
Locked