Update to SNMP installation instructions

I just went through configuring SNMP and found that, though there are several tutorials out there, not all the information needed is in one place. The following is the combination of four or five tutorials and the eventual steps I found work for me. Tested on both Debian and Redhat based distributions, I hope this helps somebody out!

Installing SNMP for Asterisk

Start by installing the related packages

    (DEBIAN) apt-get install snmp libsnmp-dev snmpd snmptrapd snmp-mibs-downloader
    (REDHAT) yum install net-snmp net-snmp-agent-libs net-snmp-libs net-snmp-utils asterisk16-snmp

Now backup the original config files and set permissions

    cp /etc/snmp/snmp.conf /etc/snmp/snmp.conf.orig
    cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig

Then download the Asterisk specific MIBS from Digium

    https://wiki.asterisk.org/wiki/display/AST/Asterisk+MIB+Definitions
    https://wiki.asterisk.org/wiki/display/AST/Digium+MIB+Definitions

    This data is placed in:

    /usr/share/snmp/mibs/ASTERISK-MIB.txt
    /usr/share/snmp/mibs/DIGIUM-MIB.txt

Next lets add the res_snmp.conf file (copy paste from cat to EoE)

cat <<-EoE > /etc/asterisk/res_snmp.conf
        ;
        ; Configuration file for res_snmp
        ; --------------------------------
        ;
        ; Res_snmp can run as a subagent or standalone SNMP agent. The standalone snmp
        ; agent is based on net-snmp and will read a configuration file called
        ; asterisk.conf in the net-snmp configuration file path, starting with
        ; /etc/snmp on many systems.
        ;
        ; If you use the subagent model, you need to enable agentx in snmpd.conf
        ; Note that you can only run one Asterisk on the system in this case.
        ;
        ; See https://wiki.asterisk.org/wiki/display/AST/Simple+Network+Management+Protocol+(SNMP)+Support
        ; to get more information about
        ; snmp support in 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
        
EoE

Now update the following with YOUR password and IP space and create the snmpd.conf file (copy paste from cat to EoF)

cat <<- EoF > /etc/snmp/snmpd.conf
        ## For Asterisk
        agentAddress udp:161
        rocommunity public 192.168.0.0/24
        
        # Asterisk SNMPv3 user
        createUser AsteriskMon MD5 "p@ZZwErd" 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
        
        sysLocation Building and Location
        
EoF

Next add the MIB configuration files to snmp.conf (copy paste from cat to EoD)

cat <<- EoD > /etc/snmp/snmp.conf
        # As the snmp packages come without MIB files due to license reasons, loading
        # of MIBs is disabled by default. If you added the MIBs you can reenable
        # loading them by commenting out the following line.
        #mibs :
        mibs +ASTERISK-MIB
        mibs +DIGIUM-MIB
        
EoD

Lets do a sanity check of all files to be sure they are formatted correctly (remove leading spaces if the TAB character didn’t make the copy paste)

    vim /etc/snmp/snmp.conf
    vim /etc/snmp/snmpd.conf
    vim /etc/asterisk/res_snmp.conf

Next, check the FreePBX “Admin|Asterisk Modules” menu and remove res_snmp.so from “Excluded Modules” then add it so it’s preloaded when Asterisk starts

    NOTE: if not using FreePBX, add to /etc/asterisk/modules.conf (preload = res_snmp.so)

We now enable and start snmpd and set permissions on the agentx directory

    systemctl enable snmpd
    systemctl start snmpd
    chmod 0755 /var/agentx
    fwconsole restart

Now let’s check Asterisk to verify the res_snmp.so module is available

    asterisk -rx "module show like res_snmp"

You should get this back from Asterisk or you may need to load or compile in res_snmp.so:

    Module                         Description                              Use Count  Status      Support Level
    res_snmp.so                    SNMP [Sub]Agent for Asterisk             0          Running          extended
    1 modules loaded

Finally lets test the SNMP (NOTE you have to use single quote when your password has special characters!!!)

    snmpwalk -v 3 -u AsteriskMon -l authPriv -a MD5 -A 'p@ZZwErd' -x DES -X 'p@ZZwErd' localhost ASTERISK-MIB::astConfigCallsActive

If all is well, snmpwalk should return the following:

    ASTERISK-MIB::astConfigCallsActive.0 = Gauge32: 0

TROUBLESHOOTING

If you get a authentication error, ie:

    snmpwalk: Authentication failure (incorrect password, community or key)

Check to ensure you’re using a single quote (') when using passwords containing special characters!

If you get no response from snmpwalk, ie:

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

Check the permissions on /var/agentx

    ls -ald /var/agentx
    drwxr-xr-x 2 root root 4096 Sep 25 09:43 /var/agentx/

Correct permissions are 0755 per the instructions above! You must restart snmpd once you fix it.

That’s All!

  • Andrew@Sayso
1 Like

This would be a good resource to contribute to the community documentation project. Ping me if you want a page there

Sounds fine. Let me know

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