Nagios - SIP Monitoring using SIPP

From open-voip.org

Jump to: navigation, search

We are mpnotoring the asterisk linux server (192.168.0.149). We will add a SIP test to the Nagios using SIPP and we will monitor the asterisk service on this server

Contents

Prepare the remote asterisk server

we will configure the sip.conf and the extentions.conf to support the monitor script:

sip.conf:

 [general]
 context=default                 ; Default context for incoming calls
 bindport=5060                   ; bindport is the local UDP port that Asterisk will listen on
 bindaddr=0.0.0.0                ; IP address to bind to (0.0.0.0 binds to all)
 ;
 disallow=all                    ; First disallow all codecs
 allow=gsm                       ; Allow default codec
 allow=ulaw                      ;
 ;
 ; *** configure the users: ***
 ;
 [1000]
 secret=1000
 context=from-sip                ; the context of this setup
 type=friend                     ; Can make inbound and outbound calls
 callerid="User-A"               ; Set your Caller-id
 host=dynamic                    ; This device needs to register
 nat=yes                         ; user is behind a NAT router
 ;qualify=yes                     ; keep the router open by sending periodic packets
 ;
 [2000]
 secret=2000
 context=from-sip                ; the context of this setup
 type=friend                     ; Can make inbound and outbound calls
 callerid="User-B"               ; Set your Caller-id
 host=dynamic                    ; This device needs to register
 nat=yes                         ; user is behind a NAT router
 ;qualify=yes                     ; keep the router open by sending periodic packets

extensions.conf:

 [general]
 [globals]
 ;
 [from-sip]
 exten => _X.,1,Answer()           ; Answer the call
 exten => _X.,2,wait(1)
 exten => _X.,3,hangup()

restart the service

 asterisk -r
 restart now

Install SIPP on the nagios server

Use the SIPP Installation article

Check SIPP and prepare the SIPP command line

let's create a new SIPP script that Register and than make one call to the asterisk server. for detailed explanation about the sipp scripts go to SIPP UAC and asterisk

 vi /opt/reg_inv_to_ast.xml

file can be found here Media:Reg_Inv_test.txt. copy past to the "Reg_Inv_test.txt" file. note that opening the file as XML may cause problems. save it as text file and open with text editor.

Create a paremeters file for the script:

 vi /opt/Param_file_sequential.txt

write the following in the file:

 SEQUENTIAL
 1000;[authentication username=1000 password=1000]
 2000;[authentication username=2000 password=2000]

make sure the asterisk is running on the monitored host (192.168.0.149) and test the sipp:

 /opt/sipp/sipp-3.0.src/sipp -s 1000 -ap 1000 -r 5 192.168.0.149 -sf /opt/reg_inv_to_ast.xml -m 200 -d 2000 -inf /opt/Param_file_sequential.txt -m 1 -timeout 3s -send_timeout 3s -recv_timeout 2s -f 8

Create a new check with nagios return codes - "check_sip"

Nagios need the following retund codes:

Numeric Value

Service Status

Status Description

0

OK

The plugin was able to check the service and it appeared to be functioning properly

1

Warning

The plugin was able to check the service, but it appeared to be above some "warning" threshold or did not appear to be working properly

2

Critical

The plugin detected that either the service was not running or it was above some "critical" threshold

3

Unknown

Invalid command line arguments were supplied to the plugin or low-level failures internal to the plugin (such as unable to fork, or open a tcp socket) that prevent it from performing the specified operation. Higher-level errors (such as name resolution errors, socket timeouts, etc) are outside of the control of plugins and should generally NOT be reported as UNKNOWN states.

  • sipp exit codes:
 0: All calls were successful 
 1: At least one call failed 
 97: exit on internal command. Calls may have been processed. Also exit on global timeout (see -timeout_global option) 
 99: Normal exit without calls processed 
 -1: Fatal error 

The nagios check scripts are located at "/usr/local/nagios/libexec" Let's create the new check_sip script that will exit with 0 when OK and with 2 when fails:

 vi /usr/local/nagios/libexec/check_sip

save the following script:

 #!/bin/bash
 #!/bin/bash
 /opt/sipp/sipp-3.0.src/sipp -s 1000 -ap 1000 -r 5 $1 -sf /opt/reg_inv_to_ast.xml -m 200 -d 2000 -inf /opt/Param_file_sequential.txt  -m 1 -timeout 3s -send_timeout 3s -recv_timeout 2s -f 8 > /opt/output.txt
 if [ "$?" == "0" ];
 then
 echo "TEST-GOOD"
 exit 0
 else
 echo "TEST-FAIL ($?)"
 exit 2
 fi

Change the permissions to nagios:

cd /usr/local/nagios/libexec/
chmod 775 check_sip
chown nagios check_sip 
chgrp nagios check_sip

check the check_sip script:

 ./check_sip 192.168.0.149

Add check_sip to nagios command's list

vi /usr/local/nagios/etc/objects/commands.cfg

and add the following code. I have placed it under the ping_check code:

# 'check_sip' command definition
define command{
       command_name    check_sip
       command_line    $USER1$/check_sip $HOSTADDRESS$
       }

Add the sip check to the host's monitored services

now we will add the the sip_check service monitor to the asterisk monitor (192.168.0.149)

vi /usr/local/nagios/etc/objects/localhost.cfg 
define service{
       use                             local-service         ; Name of service template to use
       host_name                       sipp_asterisk
       service_description             SIP
       check_command                   check_sip
       }

Make sure the asterisk is running and Restart nagios

/etc/init.d/nagios restart

if there are problems check the permissions of the output file:

chmod 777 /opt/output.txt

make sure nagios have permissions to run the sipp application and xml scripts

Personal tools