Asterisk SNMP

We needed a better way to monitor and track performance of‘s Asterisk 1.6 boxes.  We learned quickly that the scarce documentation for configuring Asterisk to use Simple Network Management Protocol (SNMP) is conflicting and outdated.  So we decided to share our configuration and hopefully save others a lot of time and head-scratching.

Downloading the Asterisk 1.6 source code

Enabling SNMP support in Asterisk requires a rebuild of Asterisk.

If you already have the Asterisk source code on your Asterisk server, open a terminal session with the Asterisk box and navigate to the Asterisk source code directory, then skip to Installing Net-SNMP.

If you don’t have the Asterisk source code on your Asterisk server, open a terminal session with the Asterisk box and copy these instructions to the command line:

#get asterisk source
# create source dir
mkdir -p /usr/src/digium
cd /usr/src/digium/
wget tar xzvf asterisk-1.6-current.tar.gz
cd asterisk-1.6.*

Installing Net-SNMP

Asterisk SNMP support is provided by the res_snmp module.  To build this module, you need to install the following packages:

  • net-snmp
  • net-snmp-devel
  • net-snmp-utils
  • bzip2
  • bzip2-devel
  • lm_sensors
  • lm_sensors-devel
  • newt
  • newt-devel

On a CentOS or Fedora box you can use the following command to install all the packages at once:

yum -y install net-snmp net-snmp-devel net-snmp-utils bzip2-devel newt-devel lm_sensors-devel ; # snmp support – res_snmp

Preparing the Asterisk box

Once the necessary packages are installed, run the following commands from the Asterisk source code directory:

make menuselect

Running make menuselect will launch a menu that looks something like the image below.

Asterisk Module and Build Options Selection

Select the Resource Modules option from the menu and press the Return key.  Then scroll down to res_snmp, if res_snmp is not selected, press the spacebar to enable res_snmp.  The selection should now look like the image below.

Asterisk resource modules

If you are unable to select res_snmp, it means the Net-SNMP package was not installed properly or the Asterisk configure tool was unable to find the Net-SNMP package. Try running .configure -with-netsnmp from the command line and then re-run make menuselect.

Press x to save your configuration changes.

Now we can build Asterisk with SNMP support and install it by runing the following commands:

make /etc/init.d/asterisk stop ; # make sure asterisk is stopped before installing
make install

Configuring the SNMP daemon

There are three versions of SNMP, but two are insecure and should not be used over an untrusted network.  We chose SNMPv3, which requires authentication and encryption from the asteriskUser when it connects to the server.

To create an SNMPv3 user account and to configure it to require authentication and encryption, run the commands below, replacing change_this_password with your own password.

Asterisk uses AgentX to communicate with the SNMP daemon.  Run the command below to configure the SNMP daemon for AgentX.  If your Asterisk daemon, does not run as a member of the asterisk group, replace asterisk in the agentXPerms command with an asterisk daemon group.

The commands below will install the Asterisk and Digium MIB files, configure the snmp daemon to start on boot, and launch the snmp daemon.

Let’s verify that the configuration is working so far by verifying that the snmp daemon set the file permissions correctly, run the following command:

Your permissions must look like:

If the file permissions on /var/agentx and /var/agentx/master don’t allow the asterisk daemon group to write tomaster, Asterisk will not be able to communicate with the SNMP daemon. We had problems with the /var/agentx directory permissions, you may need to run the following command to fix the permissions.

You can also check the logs to confirm that AgentX is running.

You should see lines like the following:

Jan 31 14:30:15 domU-12-31-39-00-55-E7 snmpd[27048]: Creating directory: /var/agentx
Jan 31 14:30:15 domU-12-31-39-00-55-E7 snmpd[27048]: Turning on AgentX master support.

Configuring the Asterisk res_snmp module

Now we configure Asterisk to use SNMP by running the following commands:

# configure res_snmp.conf
sed -e ‘s/;\(subagent\)/\1/’ -e ‘s/;\(enabled\)/\1/’ <configs/res_snmp.conf.sample >/etc/asterisk/res_snmp.conf

Start Asterisk from the command line:

asterisk -cvvvvvvvvvv

and look for the following Asterisk console output:

NET-SNMP version 5.4.1 AgentX subagent connected

The line above means that Asterisk is configured correctly and the res_snmp module has loaded.

You can now exit the asterisk console and then launch the Asterisk daemon, with the command below:

/etc/init.d/asterisk start

Final testing

You can now use the snmpwalk command to test that everything is configured correctly.  Replacechange_this_password with the password you created above for the snmp daemon configuration and run the commands below:

snmpwalk -v 3 -u asteriskUser -n “” -l authPriv -a SHA -A change_this_password -x AES -X change_this_password localhost asterisk

You should get a result like:

Congratulations, you’ve finished and your Asterisk server is now configured to use SNMP.

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *