Asterisk Zaptel Nagios plugin

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


  1. !/bin/bash
  2. check_zap_pri
  3. this is a basic Nagios plugin that tests ISDN lines status in Asterisk
  4. you will need to use the check_by_ssh feature of nagios. You need to add the command to commands.conf
  5. define command{
  6. command_name check_by_ssh
  7. command_line /usr/lib/nagios/plugins/check_by_ssh -l root -H $HOSTADDRESS$ -C /usr/lib/nagios/plugins/$ARG1$
  8. }
  9. then place this code in the /usr/lib/nagios/plugins/ on the box with the
  10. PRI spans you want to monitor. Additionally you are going to need to use
  11. ssh-keygen to create key pairs. It is important that the pairs are created from
  12. the account of the user nagios is running at. In other words if nagios runs as user
  13. nagios then you need to 'su' to nagios and generate a keypair as that user.
  14. That public key is then installed into the 'root' users authorized_keys on the box
  15. that you installed the script into. This is important because you will not get a
  16. successful result if this script executes as a regular user versus the user asterisk
  17. runs as or one with higher permissions.
  18. The services.cfg entry looks like many other except check_command is
  19. check_command check_by_ssh!name_of_script
  20. so in my case since I named my script check_zap_pri :
  21. 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 [ x$STATUS == "x" ]; then
continue
fi

if [ $STATUS != "Up" ]; then
FAILS="$FAILS span $i"
fi
done

if [ "x$FAILS" != "x" ]; 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


  1. !/bin/bash
  2. check_zappri_mgr
  3. install this into /usr/lib/nagios/plugins/contrib/
  4. You need a manager entry in /etc/asterisk/manager.conf
  5. [nagios]
  6. secret=somesecret
  7. deny=0.0.0.0/0.0.0.0
  8. permit=127.0.0.0/255.0.0.0
  9. permit=111.222.333.444/255.255.255.111 <-- the network nagios connects from
  10. read = system,call,log,verbose,command,agent,user
  11. write = system,call,log,verbose,command,agent,user
  12. add the following command to your commands.cfg
  13. define command{
  14. command_name check_zappri_mgr
  15. command_line /usr/lib/nagios/plugins/contrib/check_zappri_mgr $ARG1$ $ARG2$ $HOSTADDRESS$
  16. }
  17. the services.cfg entry uses this check_command
  18. check_command check_zappri_mgr!mgr_user!mgr_pass
  19. 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 [ x$STATUS == "x" ]; then

continue
fi

if [ $STATUS != "Up" ]; then
FAILS="$FAILS span $i"
fi
done

if [ "x$FAILS" != "x" ]; then
echo "ISDN Critical: lines down, $FAILS"
exit 2
fi

echo "ISDN OK "
exit 0

Created by: ctrlaltdel, Last modification: Mon 30 of Jul, 2007 (05:23 UTC) by eeman


Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

 

Featured -

Search: