Asterisk Zaptel Nagios plugin

The following Nagios plugin will check the specified zaptel spans for status.


 #!/bin/bash
 # 
 # check_zap_pri
 #
 # this is a basic Nagios plugin that tests ISDN lines status in Asterisk
 # you will need to use the check_by_ssh feature of nagios. You need to add the command to commands.conf 
 # 
 #  define command{
 #       command_name    check_by_ssh
 #       command_line    /usr/lib/nagios/plugins/check_by_ssh -l root -H $HOSTADDRESS$ -C /usr/lib/nagios/plugins/$ARG1$
 #       }
 #
 # then place this code in the /usr/lib/nagios/plugins/ on the box with the 
 # PRI spans you want to monitor. Additionally you are going to need to use 
 # ssh-keygen to create key pairs. It is important that the pairs are created from 
 # the account of the user nagios is running at. In other words if nagios runs as user 
 # nagios then you need to 'su' to nagios and generate a keypair as that user.
 # That public key is then installed into the 'root' users authorized_keys on the box
 # that you installed the script into. This is important because you will not get a 
 # successful result if this script executes as a regular user versus the user asterisk 
 # runs as or one with higher permissions. 
 #
 # The services.cfg entry looks like many other except check_command is 
 #  check_command                   check_by_ssh!name_of_script 
 # so in my case since I named my script check_zap_pri :
 #
 #  check_command                   check_by_ssh!check_zap_pri
 #
 # 
 PATH=/bin:/sbin:/usr/bin:/usr/sbin
 FAILS=""
 SPANS=$(asterisk -rnx "pri show spans" | grep -a PRI | awk '{print $3;}' | cut -d"/" -f1)
 
 for i in $SPANS; do
        STATUS=$(asterisk -rnx "pri show span $i" | grep -a Status | awk '{print $3;}' | cut -d, -f1)
        if ~np~[ x$STATUS == "x" ]~/np~; then
                continue
        fi
 
        if ~np~[ $STATUS != "Up" ]~/np~; then
                FAILS="$FAILS span $i"
        fi
 done
 
 if ~np~[ "x$FAILS" != "x" ]~/np~; then
        echo "ISDN Critical: lines down, $FAILS"
        exit 2
 fi
 
 echo "ISDN OK "
 exit 0



I wasn't a huge fan of the ssh venue of running this script so I wrote one that uses the manager interface via the nc aka netcat utility


 #!/bin/bash
 # check_zappri_mgr
 #       install this into /usr/lib/nagios/plugins/contrib/
 # You need a manager entry in /etc/asterisk/manager.conf
 # ~np~[nagios]~/np~
 # secret=somesecret
 # deny=0.0.0.0/0.0.0.0
 # permit=127.0.0.0/255.0.0.0
 # permit=111.222.333.444/255.255.255.111 <-- the network nagios connects from
 # read = system,call,log,verbose,command,agent,user
 # write = system,call,log,verbose,command,agent,user
 #
 # add the following command to your commands.cfg
 #
 # define command{
 #         command_name    check_zappri_mgr
 #         command_line    /usr/lib/nagios/plugins/contrib/check_zappri_mgr $ARG1$ $ARG2$ $HOSTADDRESS$
 #         }
 #
 # the services.cfg entry uses this check_command
 # check_command              check_zappri_mgr!mgr_user!mgr_pass
 #
 # this is a basic Nagios plugin that tests ISDN lines status in Asterisk
 PATH=/bin:/sbin:/usr/bin:/usr/sbin
 FAILS=""
 HOST=$3
 USER=$1
 PASS=$2
 EOF="\015\012"
 BLANK=$EOF$EOF
 SPANS=$((echo -ne "Action: Login$EOF"
 echo -ne "Username: $USER$EOF"
 echo -ne "Secret: $PASS$BLANK"
 echo -ne "Action: Command$EOF"
 echo -ne "command: pri show spans$BLANK"
 echo -ne "Action: Logoff$BLANK") | nc $HOST 5038 | grep -a PRI | awk '{print $3;}' | cut -d"/" -f1)
 
 for i in $SPANS; do
        STATUS=$((echo -ne "Action: Login$EOF"
 echo -ne "Username: $USER$EOF"
 echo -ne "Secret: $PASS$BLANK"
 echo -ne "Action: Command$EOF"
 echo -ne "command: pri show span $i$BLANK"
 echo -ne "Action: Logoff$BLANK") | nc $HOST 5038 | grep -a Status | awk '{print $3;}' | cut -d, -f1)
        if ~np~[ x$STATUS == "x" ]~/np~; then
                
                continue
        fi
 
        if ~np~[ $STATUS != "Up" ]~/np~; then
                FAILS="$FAILS span $i"
        fi
 done
 
 if ~np~[ "x$FAILS" != "x" ]~/np~; then
        echo "ISDN Critical: lines down, $FAILS"
        exit 2
 fi
 
 echo "ISDN OK "
 exit 0 


The following Nagios plugin will check the specified zaptel spans for status.


 #!/bin/bash
 # 
 # check_zap_pri
 #
 # this is a basic Nagios plugin that tests ISDN lines status in Asterisk
 # you will need to use the check_by_ssh feature of nagios. You need to add the command to commands.conf 
 # 
 #  define command{
 #       command_name    check_by_ssh
 #       command_line    /usr/lib/nagios/plugins/check_by_ssh -l root -H $HOSTADDRESS$ -C /usr/lib/nagios/plugins/$ARG1$
 #       }
 #
 # then place this code in the /usr/lib/nagios/plugins/ on the box with the 
 # PRI spans you want to monitor. Additionally you are going to need to use 
 # ssh-keygen to create key pairs. It is important that the pairs are created from 
 # the account of the user nagios is running at. In other words if nagios runs as user 
 # nagios then you need to 'su' to nagios and generate a keypair as that user.
 # That public key is then installed into the 'root' users authorized_keys on the box
 # that you installed the script into. This is important because you will not get a 
 # successful result if this script executes as a regular user versus the user asterisk 
 # runs as or one with higher permissions. 
 #
 # The services.cfg entry looks like many other except check_command is 
 #  check_command                   check_by_ssh!name_of_script 
 # so in my case since I named my script check_zap_pri :
 #
 #  check_command                   check_by_ssh!check_zap_pri
 #
 # 
 PATH=/bin:/sbin:/usr/bin:/usr/sbin
 FAILS=""
 SPANS=$(asterisk -rnx "pri show spans" | grep -a PRI | awk '{print $3;}' | cut -d"/" -f1)
 
 for i in $SPANS; do
        STATUS=$(asterisk -rnx "pri show span $i" | grep -a Status | awk '{print $3;}' | cut -d, -f1)
        if ~np~[ x$STATUS == "x" ]~/np~; then
                continue
        fi
 
        if ~np~[ $STATUS != "Up" ]~/np~; then
                FAILS="$FAILS span $i"
        fi
 done
 
 if ~np~[ "x$FAILS" != "x" ]~/np~; then
        echo "ISDN Critical: lines down, $FAILS"
        exit 2
 fi
 
 echo "ISDN OK "
 exit 0



I wasn't a huge fan of the ssh venue of running this script so I wrote one that uses the manager interface via the nc aka netcat utility


 #!/bin/bash
 # check_zappri_mgr
 #       install this into /usr/lib/nagios/plugins/contrib/
 # You need a manager entry in /etc/asterisk/manager.conf
 # ~np~[nagios]~/np~
 # secret=somesecret
 # deny=0.0.0.0/0.0.0.0
 # permit=127.0.0.0/255.0.0.0
 # permit=111.222.333.444/255.255.255.111 <-- the network nagios connects from
 # read = system,call,log,verbose,command,agent,user
 # write = system,call,log,verbose,command,agent,user
 #
 # add the following command to your commands.cfg
 #
 # define command{
 #         command_name    check_zappri_mgr
 #         command_line    /usr/lib/nagios/plugins/contrib/check_zappri_mgr $ARG1$ $ARG2$ $HOSTADDRESS$
 #         }
 #
 # the services.cfg entry uses this check_command
 # check_command              check_zappri_mgr!mgr_user!mgr_pass
 #
 # this is a basic Nagios plugin that tests ISDN lines status in Asterisk
 PATH=/bin:/sbin:/usr/bin:/usr/sbin
 FAILS=""
 HOST=$3
 USER=$1
 PASS=$2
 EOF="\015\012"
 BLANK=$EOF$EOF
 SPANS=$((echo -ne "Action: Login$EOF"
 echo -ne "Username: $USER$EOF"
 echo -ne "Secret: $PASS$BLANK"
 echo -ne "Action: Command$EOF"
 echo -ne "command: pri show spans$BLANK"
 echo -ne "Action: Logoff$BLANK") | nc $HOST 5038 | grep -a PRI | awk '{print $3;}' | cut -d"/" -f1)
 
 for i in $SPANS; do
        STATUS=$((echo -ne "Action: Login$EOF"
 echo -ne "Username: $USER$EOF"
 echo -ne "Secret: $PASS$BLANK"
 echo -ne "Action: Command$EOF"
 echo -ne "command: pri show span $i$BLANK"
 echo -ne "Action: Logoff$BLANK") | nc $HOST 5038 | grep -a Status | awk '{print $3;}' | cut -d, -f1)
        if ~np~[ x$STATUS == "x" ]~/np~; then
                
                continue
        fi
 
        if ~np~[ $STATUS != "Up" ]~/np~; then
                FAILS="$FAILS span $i"
        fi
 done
 
 if ~np~[ "x$FAILS" != "x" ]~/np~; then
        echo "ISDN Critical: lines down, $FAILS"
        exit 2
 fi
 
 echo "ISDN OK "
 exit 0 


Created by: ctrlaltdel, Last modification: Wed 15 of Aug, 2012 (05:57 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+