Setup SNMP v3 on FreePBX 14

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

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

[general]
; 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: Home - Asterisk Documentation

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:

mibs +ASTERISK-MIB

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

ASTERISK-MIB::astConfigCallsActive
OID: .1.3.6.1.4.1.22736.1.2.5.0

# 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

ASTERISK-MIB::astConfigCallsProcessed
OID: .1.3.6.1.4.1.22736.1.2.6.0

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

3: Asterisk up time

ASTERISK-MIB::astConfigUpTime
OID: .1.3.6.1.4.1.22736.1.2.1.0

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

8 Likes

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.

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

1 Like

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

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

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

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

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

It seems that it’s time to retire these instructions. The asterisk-snmp package seems to no longer be available for installation and without it none of the needed functionality is present.

For now it seems there is no longer a way to get monitoring data out of Asterisk with SNMP using packages.

It might be possible to get this functionality if you manually compile asterisk and the various dependencies and requirements but this would be beyond my interest to document and maintain.

1 Like

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