Enable SNMP in FreePBX Distro

(Konos Koncepts) #1

I came upon some threads re SNMP here the other day and found a distinct lack of attention to documenting the implementation and behavior of SNMP in regards to Asterisk, FreePBX and Distro with many forum members providing unhelpful posts and external links instead of actually discussing it to the benefit of the community.

So… I hope this helps those seeking answers to SNMP in direct relation to the product. The trick is just to get over the hump of understanding how the SNMP implementation differs to a standard OS install… Asterisk SNMP is a sub-agent of the yum-installed base SNMP package.

In this example, I’ve used a legacy (pre-Sangoma) model of FreePBX ( I know this is old (ish) but it’s a good starting point as many folks will have oldish deployments out there. I’ll update this guideline with a modern Distro when I do my next site deployment.

Now… Myself, I only using SNMP for traffic monitoring so i haven’t full tested the Asterisk and Digium MIBs but we can work through that bit later. You will need both the Asterisk and Digium MIBs as they reference each other. I’m not sure if i’m allowed to post the MIB content here but it would become outdated anyway so I’ll just reference the Digium public definitions.

For recent versions of Distro, you should be able to get snmp functioning pretty easily.
ie… no need to compile/recompile anything. You just yum install what you need and reconfigure snmpd.

1. Install SNMP and Dependencies:

# yum install net-snmp net-snmp-utils net-snmp-devel

One thing that I have found is that when you install net-snmp, you don’t really know what state the default configuration is in and sometimes it just doesn’t work out of the box. So… you should start with a clean slate by discarding the default configs then reconfigure by answering all the questions in the setup wizard…

cd /etc/snmp
mv snmpd.conf snmpd.conf.orig
mv snmptrapd.conf snmptrapd.conf.orig
snmpconf -g basic_setup

Start the snmpd service and enable start on boot.

# service snmpd start
# chkconfig snmpd on

Test It:

# snmpwalk -c public -v 2c localhost <-public is what I chose as the rocommunity. yours may differ.

Now you're ready to monitor network traffic and OS but not Asterisk.

##2. Asterisk SNMP Module Install:

I only use traffic monitoring for my deployments so I haven’t deployed and tested the full Asterisk functionality but it goes something like this… Please do contribute to this knowledge.

Install the Asterisk snmp module:

# yum install asterisk-snmp <–This command might not install the exact correct version. See below.

When you yum install asterisk-snmp package, it may not install the exact right version, especially if you are installing retrospectively and module version numbers advance… It’s not considered to be a bug as such so just be aware that you may need to target the exact version instead. If this happens, you may see an error like this when asterisk starts up…

Module ‘res_snmp.so’ was not compiled with the same compile-time options as this version of Asterisk

So… This command will tell you what version you need.

# rpm -qa | grep asterisk | grep core
—> asterisk13-core-13.12.1-1.shmz65.1.143.x86_64

If the version number returned is not the same as the yum asterisk-snmp package then you will need to manually install the correct version. For example:

# yum install asterisk13-snmp-13.12.1-1.shmz65.1.143.x86_64

You can confirm the module is loaded once you restart amportal / fwconsole and connect with "asterisk -r"

# 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

##3. Asterisk Sub-Agent Integration:
Install Dependancies…

# yum install lm_sensors lm_sensors-devel newt newt-devel bzip2 bzip2-devel

Asterisk monitoring requires the use of a sub-agent of snmp.
So… you need to load the sub-agent daemon AgentX then install Asterisk MIB definitions.

Enable agentX in snmp.

# nano /etc/snmp/snmpd.conf

#Enable AgentX support
master agentx
# Set permissions on AgentX socket and containing
# directory such that process in group 'asterisk'
# will be able to connect
agentXPerms  0660 0550 nobody asterisk

Enable sub-agent in Asterisk snmp module…

# nano /etc/asterisk/res_snmp.conf

 subagent = yes
 enabled = yes

Restart Services

# service snmp restart
# amportal restart <— This will later be deprecated and become fwconsole

You can confirm that AgentX is loaded by stopping Amportal/fwconsole and running "asterisk -cvvvvvvvvvv"
you should see the line "NET-SNMP version 5.5 AgentX subagent connected"
This also confirms that the module re_snmp is loaded.

Create an asterisk user for snmp v3
just append the following to /etc/snmp/snmpd.conf

# Asterisk user
rwuser asteriskUser priv
createUser asteriskUser SHA asteriskPasswd AES

Lookup the Asterisk MIB defs at https://wiki.asterisk.org/wiki/display/AST/Asterisk+MIB+Definitions
Install the ASTERISK-MIB definitions into /usr/share/snmp/mibs/ASTERISK-MIB.txt
Install the DIGIUM-MIB definitions into /usr/share/snmp/mibs/DIGIUM-MIB.txt

Restart Amportal and SNMP

# amportal restart <— This will later be deprecated and become fwconsole
# service snmpd restart

Good MIB knowledge here…

Now test it using snmp v3 with auth

snmpwalk -v 3 -u asteriskUser -l authPriv -a SHA -A asteriskPasswd -x AES -X asteriskPasswd localhost asterisk

So… I hope this helps clear things up or at least set you on the right path.
I will return here and update this for a modern Sangoma edition of Distro soon.



How to enable SNMP?
SNMP Configuration Asterisk 11
(Daniel Friedman) #2

Hello @konos,

This is a good article, thank you. Can you just fix the typo fw-console to fwconsole ?

Thank you,

Daniel Friedman
Trixton LTD.

(Igor Dobrosavljevic) #3

Really appreciate you putting this together. It definitely helped me get started with this. However I am unable to get my setup working quite completely.

I am running on the latest version of the FreePBX distribution and am hoping that I am not being out of line by asking for some additional assistance with my setup.

I believe that I have both snmpd and res_snmp working properly as I am able to confirm that both snmpd is running properly and the module is loaded and running in asterisk without any errors.

However when I run the snmpwalk command to test it I get the following error thrown at me:

Unknown Object Identifier (Sub-id not found: (top) -> asterisk)

If I do a:

snmpget -v 2c -c public localhost ASTERISK-MIB::astVersionString

I get:

ASTERISK-MIB::astVersionString = No Such Object available on this agent at this OID

I apologize but I am super new to SNMP so I am not even sure where to start the troubleshooting. Any additional assistance that you can offer would be greatly appreciated.

(Igor Dobrosavljevic) #4

Figured out the problem:

sudo chmod 755 /var/agentx

Also, the “mibs +ASTERISK-MIB” line goes into /etc/snmp/snmp.conf (notice there is no d in snmp.conf).

(Igor Dobrosavljevic) #5

I’ve created a new topic with instructions on how I setup SNMPv3 on my system (which is a FreePBX 14 box) right here. https://community.freepbx.org/t/setup-snmp-v3-on-freepbx-14/44684

(Jeremiah Kioko) #6

Whenever I try to run snmpwalk -c public -v 2c localhost I get the error:

Timeout: No Response from localhost

Any idea of where to start tshoot?

(Dave Burgess) #7

Setup SNMP v3 on FreePBX 14 would be a good start.