Having a switchboard that’s not working properly can lead to lost business.
But what’s even worse is having a phone system with many extensions and no ability to see what’s happening or when someone is offline with their SIP phone.
Are you worried about after hours calls?
It will be nice to see activity 24/7, wouldn’t it?
Perhaps time to expand the business for after hours telephone support?
Maybe check up on whose having those really long phone calls?
SNMP to the rescue. You can monitor anything with SNMP and a bit of effort and configuration files.
In this tutorial we’ll be created four files that each reads:
- Asterisk Extensions Not Available
- Why are extensions unavailable? They are defined as SIP but not working. Someone plugged the phone out?
- Asterisk Extensions In Use
- Useful to see peak activity
- Asterisk Extensions Not In Use
- A total tally of all the phones in the system
- Asterisk Extensions Ringing
- Useful to see peak activity or missed calls
When we’re done you’ll end up with a beautiful monitoring system that shows you activity such as this below:
The key is to use the SNMP exec command to execute a script.
The scripts themselves are all similar, they run the Asterisk console command once and look for keywords, and then count the lines returned.
All these scripts needs certain permissions and because they will be running as root with extra sudo permissions too so run passwordless.
First let’s install
net-snmp with is the daemon and then
net-snmp-utils which has the snmpwalk utility that’s useful for testing. We also ensure SNMP is activated after restart and we back up the existing exceedingly long and elaborate configuration file that you need a doctorate in IT to understand. We’ll be going minimalist here thank goodness.
yum install net-snmp yum install net-snmp-utils chkconfig snmpd on mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.backup
Create a new
snmpd.conf file that only has the following information (or amend your existing one):
# cat /etc/snmp/snmpd.conf rocommunity secret_community_name exec AsteriskExtensionsInUse /usr/bin/sudo /etc/snmp/asterisk_extensions_in_use.sh exec AsteriskExtensionsNotInUse /usr/bin/sudo /etc/snmp/asterisk_extensions_not_in_use.sh exec AsteriskExtensionsUnavailable /usr/bin/sudo /etc/snmp/asterisk_extensions_unavailable.sh exec AsteriskExtensionsRinging /usr/bin/sudo /etc/snmp/asterisk_extensions_ringing.sh
As you can see we’ll be executing shell scripts to give us the values we need. Here are the four files that you need to create. We’ll also be give them execute permissions for the owned user (root), and enable execute.
# cat /etc/snmp/asterisk_extensions_in_use.sh asterisk -rx 'pjsip show endpoints'|grep 'In use' | (wc -l) # cat /etc/snmp/asterisk_extensions_not_in_use.sh asterisk -rx 'pjsip show endpoints'|grep 'Not in use' | (wc -l) # cat /etc/snmp/asterisk_extensions_unavailable.sh asterisk -rx 'pjsip show endpoints'|grep Unavailable | (wc -l) # cat /etc/snmp/asterisk_extensions_ringing.sh asterisk -rx 'pjsip show endpoints'|grep 'Ringing' | (wc -l) # chmod 755 /etc/snmp/asterisk_extensions_* # chmod +x /etc/snmp/asterisk_extensions_*
Those script won’t just work. We have to add these special permissions to the end of or some other good place of
/etc/sudoers so that root can run them:
cat /etc/sudoers snmp ALL=(ALL) NOPASSWD: /etc/snmp/asterisk_extensions_in_use.sh snmp ALL=(ALL) NOPASSWD: /etc/snmp/asterisk_extensions_not_in_use.sh snmp ALL=(ALL) NOPASSWD: /etc/snmp/asterisk_extensions_unavailable.sh snmp ALL=(ALL) NOPASSWD: /etc/snmp/asterisk_extensions_ringing.sh
At this point you should be good to go, so do this:
service snmpd restart
[[email protected]]# snmpwalk -c secret localhost -v2c 126.96.36.199.4.1.2021.8.1.101.1 UCD-SNMP-MIB::extOutput.1 = STRING: 3
Now on your SNMP monitoring software you’ll have these four new OIDs :
- Extensions in use:
- Extensions not in use:
- Extensions unavailable
- Extensions ringing
Contact us should you require assistance!