Tuesday, August 31, 2010

Monitor Asterisk calls using SNMP

Monitor calls in asterisk using Cacti or MRTG.

Requirements:
1) install net-snmp on linux
2) recompile asterisk. make sure res_snmp in resource module is enabled

#make menuselect

[*] 13. res_odbc
[*] 14. res_smdi
[*] 15. res_snmp
[*] 16. res_speech

3) install asterisk

4) configure asterisk and enable snmp.

# vi /etc/asterisk/res_snmp.conf

[general]
subagent = yes
enabled = yes

5) enable snmpd on linux

# vi /etc/snmp/snmpd.conf

# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):

# sec.name source community
com2sec mymrtg 192.168.1.10 MyCOMMUNITY
com2sec mymrtg 192.168.1.11 MyCOMMUNITY
com2sec mymrtg localhost MyCOMMUNITY

####
# Second, map the security names into group names:

# sec.model sec.name
group networkmon v1 mymrtg
group networkmon v2c mymrtg
group networkmon usm mymrtg
group networkmon local mymrtg

####
# Third, create a view for us to let the groups have rights to:

# incl/excl subtree mask
view all included .iso

####
# Finally, grant the group access
# context sec.model sec.level match read write notif
access networkmon "" any noauth exact all none none


# Asterisk configuration
master agentx
agentXSocket /var/agentx/master
agentXPerms 0660 0550 nobody asterisk

6) copy asterisk MIB files to snmp mib directory

# cp doc/asterisk-mib.txt /usr/share/snmp/mibs
# cp doc/digium-mib.txt /usr/share/snmp/mibs

7) restart snmpd and set agentx permission

# /etc/init.d/snmpd restart
# chmod 755 /var/agentx

8) restart asterisk

# amportal restart <-- if you are using freepbx to start asterisk

9) Test it locally

# export MIBS=+ASTERISK-MIB
# snmpwalk -c MyCOMMUNITY -v 1 localhost asterisk

10) You can use the OID equivalant if you want.

# MIB equivalent (Asterisk 1.4.22 version)
ASTERISK-MIB::astChanTypeName.1 = STRING: Phone
ASTERISK-MIB::astChanTypeName.2 = STRING: Local
ASTERISK-MIB::astChanTypeName.3 = STRING: IAX2
ASTERISK-MIB::astChanTypeName.4 = STRING: Skinny
ASTERISK-MIB::astChanTypeName.5 = STRING: SIP <---- SIP MIB ID
ASTERISK-MIB::astChanTypeName.6 = STRING: MGCP
ASTERISK-MIB::astChanTypeName.7 = STRING: DAHDI
ASTERISK-MIB::astChanTypeName.8 = STRING: Agent
ASTERISK-MIB::astChanTypeName.9 = STRING: OOH323

ASTERISK-MIB::astChanTypeChannels.1 = Gauge32: 0
ASTERISK-MIB::astChanTypeChannels.2 = Gauge32: 0
ASTERISK-MIB::astChanTypeChannels.3 = Gauge32: 0
ASTERISK-MIB::astChanTypeChannels.4 = Gauge32: 0
ASTERISK-MIB::astChanTypeChannels.5 = Gauge32: 0 <---- SIP channel value
ASTERISK-MIB::astChanTypeChannels.6 = Gauge32: 0
ASTERISK-MIB::astChanTypeChannels.7 = Gauge32: 0
ASTERISK-MIB::astChanTypeChannels.8 = Gauge32: 0
ASTERISK-MIB::astChanTypeChannels.9 = Gauge32: 0

# Get OID equivalent
# snmpwalk -On -c MyCOMMUNITY -v 1 localhost ASTERISK-MIB::astChanTypeChannels.5

.1.3.6.1.4.1.22736.1.5.4.1.7.5 = Gauge32: 0 <---- oid that can be used in cacti


11) open cacti and use the generic snmp template for the device
you want to create the graph for, then define the OID. Same method applies
for mrtg users.

3 comments:

  1. Thanks for this post! As a network manager I was looking online for different SNMP Monitoring because as you know, you can't have certain operations fail. That's when I came across your blog post,you have definitely helped. I'm going to give this a try, thanks again.

    ReplyDelete
  2. Hello. I would like to thank you for this post. I was suffering to make it work in my environment until I got this information. Adapting some name I was able to amke it work. Great post !

    ReplyDelete
  3. Your tutorial helped me a lot.

    After finishing reading your tutorial I created one by myself teaching how to install and configure Asterisk snmp feature:

    https://techexpert.tips/asterisk/asterisk-snmp-configuration/

    Thanks again,

    ReplyDelete