Setup SNMP v3 on FreePBX 14

(Igor Dobrosavljevic) #1

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

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.
proc asterisk
sysObjectID .

# Enable AgentX support
master agentx
agentXSocket /var/agentx/master
# 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
pbx*CLI> module show like snmp
Module                         Description                          Use Count  Status         Support Level                    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:

You’ll want to save the ASTERISK-MIB.txt and DIGIUM-MIB.txt to /usr/share/snmp/mibs/

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

OID: .

# 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

OID: .

# snmpwalk -v 3 -u AsteriskMon -l authPriv -a MD5 -A [CHANGEME] -x DES -X [CHANGEME] localhost ASTERISK-MIB::astConfigCallsProcessed

3: Asterisk up time

OID: .

# 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.

Enable SNMP in FreePBX Distro
Is there a way to obtain peak SIP trunk usage?
Statistics Access
Enable SNMP in FreePBX Distro
(Gotham) #2

Thanks for posting these articles, it’s much appreciated.

Have a (hopefully) quick question. I haven’t got those MIBS up and running, only the standard SNMP MIBs for the server itself. In those Digi/Asterisk MIBs is there any data showing status of SIP trunks, or any way to send an alert if a SIP trunk goes up/down, etc…

One other question. When the MIBs are loaded does the PBX server require a reboot in order for the new MIBs to take effect? A reboot was done from the PBX administration Admin->System Admin -> Reboot, but still can’t see the new MIB info when doing an SNMPwalk.

(Igor Dobrosavljevic) #3

I wish. SNMP support in asterisk is not all that extensive.

(Dave Burgess) #4

Putting my old sysadmin hat on (it’s been 10 years since I SNMPed) but it seems to me that, if the MIB is getting pulled in to SNMP, the data identified by SNMP should be populating it. Adding a new MIB usually requires an ‘snmpd’ restart, but if the MIB is properly constructed, it should start pulling data almost immediately (if available).

(Igor Dobrosavljevic) #5

MIBs get loaded onto the machine that’s doing the walk, not the machine that you are pulling the data from.

(Gotham) #6

Thanks Igor, I was wondering about that, as I didn’t see any variables relating to SIP trunks being up/down

(Gotham) #7

Ah yes, correct. My apologies, I meant the Asterisk modules that are loaded onto the PBX.

(Lorne Gaetz) closed #8

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.