Asterisk PJSIP & LibreNMS

Asterisk PJSIP monitoring is closed to new replies, but thought to share an updated script to /etc/snmp/asterisk for the search engines.

  • Returns number of total number of peers, number available, and unavailable
  • Works with existing “Asterisk - SIP Peers”, this just retrofits PJSIP data to LibreNMS Asterisk app SIP format
#!/bin/bash

ASCLI=/usr/sbin/asterisk

if [ -f $ASCLI ];
then
    $ASCLI -rx "core show uptime" > /dev/null
    if [ $? -ne 0 ]; then
        # Asterisk not running, silently exit.
        exit 0
    fi

    echo "<<<asterisk>>>"
    $ASCLI -rx "core show channels" | awk '/active calls/ { print "Calls=" $1 } /active channels/ { print "Channels=" $1}'
    $ASCLI -rx "pjsip show endpoints" | awk '/Objects found:/ { print "SipPeers=" $3 }'
    $ASCLI -rx 'pjsip show endpoints' | grep "Avail" | wc -l | (read foo; echo SipMonOnline=$foo; )
    $ASCLI -rx 'pjsip show endpoints' | grep "Unavailable" | wc -l | (read foo; echo SipMonOffline=$foo; )
    echo "SipUnMonOnline=0"
    echo "SipUnMonOffline=0"
    $ASCLI -rx 'iax2 show peers' | awk '/iax2 peers/ { gsub("\\[",""); gsub("\\]",""); print "Iax2Peers=" $1 "\nIax2Online=" $4 "\nIax2Offline=" $6 "\nIax2Unmonitored=" $8}'

else
   exit 0
fi
1 Like