Net Snmp

net-snmp enables a snmp service that can be used to monitor the device CPU, network activity, …. and perhaps more.

Notice: this page is derived from this thread, help out!

Installing net-snmp

As root, do the following.
It is advised to get the latest net-snmp source from http://net-snmp.sourceforge.net/download.html

Setting up:

# create a tmp folder
mkdir /root/netsnmp
cd /root/netsnmp

# get latest source as of 20080330
wget http://surfnet.dl.sourceforge.net/sourceforge/net-snmp/net-snmp-5.4.1.tar.gz

# unpack (creates folder net-snmp-5.4.1)
tar xfz net-snmp-5.4.1.tar.gz

Compiling: configure

# go to the folder containing the sources
cd net-snmp-5.4.1

./configure

After 10 minutes it presented a net-snmp configuration trivia.
Since trivia is not my hobby i accepted the defaults.

Compiling: make & make install

make
make-install

These need respectivly 2 hours and 20 minutes.

Make it run:

1. Create start/stop script

Place in /etc/init.d a file named snmpd.sh:

#!/bin/sh
#
# Start snmpd
#

start() {
        export LD_LIBRARY_PATH=.:/lib:/usr/lib:/usr/local/lib
        echo "Starting SNMPD"
        /usr/local/sbin/snmpd
}

stop() {
        echo "Stopping SNMPD"
        killall snmpd > /dev/null 2>&1
        killall snmpd > /dev/null 2>&1
}
restart() {
        stop
        start
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                restart
                ;;
        cleanup)
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart}"
                exit 1
esac

exit $?

and make it executable:
chmod +x /etc/init.d/snmpd.sh

2. Initiate on startup

Modify the post_network_start.sh script as below to include the start stop reference to snmpd

(only part of the file is shown)

start() {
        if [ ! -e "$POST_NETWORK_STARTED_FILE" ]
        then
                $SCRIPTS_PATH/crond.sh start
                $SCRIPTS_PATH/mionet.sh start
                $SCRIPTS_PATH/snmpd.sh start
                touch $POST_NETWORK_STARTED_FILE
        fi
}

stop() {
        if [ -e "$POST_NETWORK_STARTED_FILE" ]
        then
                $SCRIPTS_PATH/mionet.sh stop
                $SCRIPTS_PATH/crond.sh stop
                $SCRIPTS_PATH/snmpd.sh stop
                rm $POST_NETWORK_STARTED_FILE
        fi
}

3. Test it

Using the script you just created:

/etc/init.d/snmpd.sh start

Or manually:
/usr/local/sbin/snmpd

Now check that port 161 UDP is listening by doing

netstat -an
you should see "udp 0 0 0.0.0.0:161 0.0.0.0:*" somewhere in the results.

Another way is doing a snmpwalk
(you might have to run export LD_LIBRARY_PATH=.:/lib:/usr/lib:/usr/local/lib first. )

snmpwalk localhost -c public -v1

i for example got this result (with example strings replacing privacy stuff)
SNMPv2-MIB::sysDescr.0 = STRING: Linux mybook 2.6.17.14 #1 PREEMPT Mon Mar 26 12:36:33 BST 2007 armv5tejl
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (34353) 0:05:43.53
SNMPv2-MIB::sysContact.0 = STRING: your-email.here
SNMPv2-MIB::sysName.0 = STRING: mybook
SNMPv2-MIB::sysLocation.0 = STRING: MyHouseInTheTrees
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (7) 0:00:00.07
SNMPv2-MIB::sysORID.1 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.2 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.3 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.5 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.6 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.7 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.8 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORDescr.1 = STRING: The SNMP Management Architecture MIB.
SNMPv2-MIB::sysORDescr.2 = STRING: The MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.3 = STRING: The management information definitions for the SNMP User-based Security Model.
SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities
SNMPv2-MIB::sysORDescr.5 = STRING: The MIB module for managing TCP implementations
SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing IP and ICMP implementations
SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing UDP implementations
SNMPv2-MIB::sysORDescr.8 = STRING: View-based Access Control Model for SNMP.
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (5) 0:00:00.05
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (5) 0:00:00.05
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (7) 0:00:00.07
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (7) 0:00:00.07
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (7) 0:00:00.07
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (7) 0:00:00.07
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (7) 0:00:00.07
End of MIB

Configuring net-snmp

The file /usr/local/share/snmp/snmpd.conf contains the juice.

Here is a working example, a very minimal snmpd.conf file.
This uses the "public" community name, only allowed from a specific IP and from localhost.
This config could be improved by adding disk IOs, temperature monitoring, etc…

com2sec local localhost public
com2sec localnet your-monitoring-ip public

group MyROSystem v1 local
group MyROSystem v2c local
group MyROSystem usm local
group MyROGroup v1 localnet
group MyROGroup v2c localnet
group MyROGroup usm localnet
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local

view all included .1 80
view system included .iso.org.dod.internet.mgmt.mib-2.system

access MyROSystem "" any noauth exact system none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none

syslocation MyHouseInTheTrees
syscontact your-email.here

disk /var 10000
disk /shares/internal 10000
disk / 10000

!! If you can make a more feature-complete snmpd.conf example please contribute.

What will you get

Screenshots of Cacti showing mybook graphs can be found in this thread.

SNMP Agents

There are several available. Many will find that MRTG and Cacti suit the needs.
You can install these yourself.

  • STG - Ideal small tool for quick tests or debugging. Windows only, no installation required.

Virtual appliances:

Other SNMP Deamons

net-snmp is a deamon that provides a service. Other interesting deamons are:

  • Windows SNMP Service - Enable SNMP in Windows Server 2003.
  • optware/gumstix1151 - To save some compilation time you can also use this package.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License