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.

(Ricardo Gilmore) #8

Hi Igor,

I have a similar situation to you when you wrote in the forum in 2017. Could you help me solve it?

I installed all the packages according to the procedure but I receive the same message that you received at that time:

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

Asterisk Version is: asterisk16-core-16.11.1-1.sng7.x86_64

But when I executed ´yum install asterisk-snmp´ the version that yum permit ti install is "astesrisk16-snmp-16.17.0-1.sng7.x86_64¨. i tried to install the same version according asterisk16-core (yum install astesrisk16-snmp-16.11.1-1.sng7.x86_64) but the yum command answer is: "No package astesrisk16-snmp-16.11.1-1.sng7.x86_64 available¨.

I am new in the asterisk and freepbx world but i apreciate your help in advance.

(Igor Dobrosavljevic) #9

It would seem that the SNMP package for Asterisk has been deprecated as that package doesn’t seem to be available any longer for install.

It might be possible to compile asterisk by hand to include the needed modules but it doesn’t seem like an official package is an option any longer.

I am sure it’s mentioned somewhere that this is the case but I can’t seem to find it readily available. Maybe @lgaetz can officially confirm that this is the case.

(Lorne Gaetz) #10

As far as I know SNMP was never officially supported, so it couldn’t be deprecated. Post #1 is from 2017 but using a freepbx version from well before 2015. I would not expect any of it to work unmodified on a current SNG7 Distro.

(Igor Dobrosavljevic) #11

When I say SNMP support I mostly refer to the fact that there was an official asterisk-snmp package available that you could install and get to work from the official repositories that was regularly updated in lockstep with the asterisk-core package release until recently (as in a year or two ago).

That’s no longer the case so I was mostly referring to that as support for SNMP in Asterisk.

But yea, it’s good to have an official confirmation.

(Jared Busch) #12

Well, snmp still works in 15, just not the asterisk additional package.

One of my favorite US providers will monitor snmp for you in their portal.

I wrote a guide for it on another community.

(Igor Dobrosavljevic) #13

When talking about SNMP support within Asterisk my assumption was that people wanted to pull data points from Asterisk using SNMP and not monitor the PBX hardware.

Yes, you can still install SNMP to monitor the OS but for that I am using tools like Zabbix. It would be nice if Asterisk had something that was easily setup and standards based (ie. SNMP) that would allow us to monitor critical stats from within Asterisk. However, SNMP even was super limited.

It would be nice if we didn’t have to hack together asterisk -x commands to pull data out of the asterisk console for monitoring purposes.

For example I would love it if I could get alerted to a trunk going down without the need to periodically run and parse the asterisk -x "pjsip show endpoint <trunk name>" command or wait for a client to call and tell us that they can’t make outbound or receive inbound calls.

(TheJames) #14

This can almost all be done with AMI events or ARI calls it is all built into asterisk. You don’t even have to pull you can run a socket connection and listen to events on AMI

(Lorne Gaetz) #15


It’s a bit of a Catch-22 here neither SNMP nor ‘polling the port’ are effective because you only will really know if a call fails when you send an INVITE and it fails and that can be for one of many reasons.

It might have its port open for calls, and if you use registration you will know if that has timed-out but neither would reflect the instantaneous state of the trunk as to whether is will take the call

True, if it fails, you can be retroactive and disable the trunk, perhaps inform you of the last Fail code or the absense of one, but again you wont know when to enable it again unless you have a background process checking the INVITES or a bit of warmware doing her job.

Make sure you have working failover trunks and have them inform you when they kick in.

Otherwise I find the MIBS still work fine and SNMP walk and report correctly the asterisk state if the module is loaded, the SMTP daemon is running, and the couple of .conf files are copacetic.

Historically we had AMI and AGI theen I would add SNMP and got a lot of traction.

Were I to do it over I would just go the ARI/websocket route, still RTFM though . . .

(Igor Dobrosavljevic) #17

Thank you guys for all the tips. While I was aware that AMI existed every time I started going down that route it felt overwhelming and I just didn’t pursue it further.

I am more on the sys admin side and this always felt like it needed a lot more coding skills then I possessed so I always gave up pretty quickly after starting down this rabbit hole.

SNMP always felt more natural to me as it definitely is a sys admin thing so I always wished that there was better SNMP support in asterisk. Especially since SNMP was just a wildly supported standard that had many third party monitoring tools associated with it that would allow me to also monitor asterisk without specialized programing knowledge that was just limited to asterisk.

With that said I COMPLETELY understand why there isn’t and probably won’t be extensive SNMP support for it.

It looks like AMI is the future and I should probably try and learn it.

@lgaetz I will certainly check out your videos and have another run at trying to wrap my head around things to see if I can make it work for us and our system monitoring needs.

(Igor Dobrosavljevic) #18

Just for future reference (and probably only valuable to me) but I did find this https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/tel/asterisk_http and it’s making me pretty excited about digging int AMI a bit more.

Thanks everyone for pointing me in the right direction, again.