After running into a lot of incomplete information on the web and here in the forums on how to properly setup SNMP to monitor resources on a FreePBX installation I’ve decided to put together a guide on what worked for me here for anyone that would like to setup the same.
1. Setup the snmpd agent:
# yum install net-snmp asterisk-snmp
The above command will install the snmpd agent and the latest version of the asterisk snmp module onto the machine. However there is a caveat, if you don’t have the latest version of asterisk installed on the machine that you are attempting to setup snmp on the module will fail to load later on in the process. There are a couple of workarounds to this. First you could run
yum update to update all the packages on your machine to the latest version automatically or you could install the version of asterisk-snmp that matches the specific installed asterisk version that’s currently running on your machine.
To find out what version of asterisk is currently installed and to install the proper version of the asterisk-snmp module you can run the following commands.
# rpm -qa | grep asterisk | grep core asterisk13-addons-core-13.17.2-1.sng7.x86_64
To install the exact version of the asterisk-snmp package that would match your installed version of asterisk your yum install command would actually look like this:
# yum install net-snmp asterisk13-snmp-13.17.2-1.sng7.x86_64
If the installation was successful you can move on to configuring the snmp agent and asterisk snmp module to properly collect and report data for you.
First, we’ll modify the /etc/snmp/snmpd.conf file to configure a couple of things. First we’ll setup a snmp v3 user that’s allowed to connect to the service and receive data. We’ll make this a read-only user since we are not really using snmp to modify any settings on this box (I am not even sure that you can even use snmp to modify any asterisk settings). Second we’ll configure AgentX since that’s how asterisk provides the snmpd agent with informaiton.
To accomplish both add the following lines to your snmpd.conf:
# Asterisk SNMPv3 user
createUser AsteriskMon MD5 [CHANGEME] DES
rouser AsteriskMon priv
# I am also monitoring to ensure that at least one asterisk process is running on this machine at all times.
# Enable AgentX support
# Set permissions on AgentX socket such that process in group ‘asterisk’ will be able to connect
agentXPerms 0660 0550 nobody asterisk
Make sure to modify the [CHANGEME] block above and provide the system with what you want to be your password and encryption pass phrase.
Second, we’ll modify the /etc/asterisk/res_snmp.conf file to enable snmp within asterisk:
; We run as a subagent per default – to run as a full agent
; we must run as root (to be able to bind to port 161)
subagent = yes
; SNMP must be explicitly enabled to be active
enabled = yes
Third, we’ll enable snmpd to start automatically on boot, start the service and ensure that the asterisk module is properly loaded:
# chkconfig snmpd on # service snmpd start
To load the asterisk module and ensure it is running properly get into the asterisk CLI and run the following commands:
# asterisk -r pbx*CLI> module load res_snmp.so pbx*CLI> module show like snmp Module Description Use Count Status Support Level res_snmp.so SNMP [Sub]Agent for Asterisk 0 Running extended 1 modules loaded
Lastly, the /var/agentx directory doesn’t automatically get the correct permissions assigned for asterisk to be able to write to the master socket file so we need to make this one time change as the last step in the configuration process:
# chmod 755 /var/agentx
2. Setup the monitoring tools:
Normally you’ll want to setup a tool on another host to access and store the snmp information from your phone system (Zabbix in my case). However, if you’d like to test your configuration after the above setup procedure you can do the following.
First, we’ll need to install the snmp utilities package which contains tools like snmpwalk that will allow us to do our testing.
# yum install net-snmp-utils
Second, we’ll need to load the appropriate MIB files that are provided by asterisk right here: https://wiki.asterisk.org/wiki/display/AST/Asterisk+MIB+Definitions
You’ll want to save the ASTERISK-MIB.txt and DIGIUM-MIB.txt to
Lastly, we’ll need to modify the snmp.conf file to use the MIBs that we’ve just added. Modify the /etc/snmp/snmp.conf file and add the following line:
Notice that the above file is snmp.conf and NOT snmpd.conf. That’s also the only line in my snmp.conf file.
Now you should be able to run the following command and get information spat back out at you:
# snmpwalk -v 3 -u AsteriskMon -l authPriv -a MD5 -A [CHANGEME] -x DES -X [CHANGEME] localhost asterisk
3. Sample interesting information and wish list
Following are a few examples of interesting data that I am collecting using snmp from my phone system.
1: Total currently active calls
# snmpwalk -v 3 -u AsteriskMon -l authPriv -a MD5 -A [CHANGEME] -x DES -X [CHANGEME] localhost ASTERISK-MIB::astConfigCallsActive
2: Total calls processed since asterisk was last restarted
# snmpwalk -v 3 -u AsteriskMon -l authPriv -a MD5 -A [CHANGEME] -x DES -X [CHANGEME] localhost ASTERISK-MIB::astConfigCallsProcessed
3: Asterisk up time
# snmpwalk -v 3 -u AsteriskMon -l authPriv -a MD5 -A [CHANGEME] -x DES -X [CHANGEME] localhost ASTERISK-MIB::astConfigUpTime
Now I really wish it was possible to collect additional info through snmp that currently doesn’t seem to be an option. I would love to be able to get the latency in ms of all peers that are setup in asterisk. I would be primarily interested in knowing when a SIP trunk is lagging or disconnected, however knowing how individual peers are doing would be a nice bonus as well. It would also be nice if I could find out the status of registered trunks directly through SNMP.
The above is certainly not an exhaustive list of information that would be nice for me to be able to retrieve from asterisk through snmp but it would make me ecstatic if support for those was added in some day.
I realize this wish list has nothing to do with FreePBX but my hope is that somebody that can do something about adding additional functionality to snmp for asterisk will read this and consider extending the functionality of the snmp implementation for asterisk some day. A boy can dream.