Nagios3

Configure Nagios in Ubuntu

to install Nagios:

sudo apt-get install nagios3 nagios-plugins nagios-plugins-standard nagios-plugins-extra

after that you can access nagios in:

http://localhost/nagios3

in your browser.

Traps on Nagios

Configuring traps on Nagios is not so simple. An agent to handle traps and call Nagios trap handler is needed. This task is done by snmptt and snmptrapd

Trap Handling

This describes the basics of trap handling.  Snmptt increases complexity by adding another layer behind nagios but it also increases the readability of the incoming traps. What do you need is:

  • Snmptrapd,
  • Snmptt,
  • MIB's for any devices you want traps sent for. A MIB basically allows the OID of the trap sent into something more descriptive.


Most hardware manufactuers have MIBs available on their site, or you can check out a site like mibdepot. In the case that the MIB does not exist for the hardware we want to monitor, we will need to develop it.

Configuration

to install snmptrapd and snmptt you can:

sudo apt-get install snmpd snmptt

In your /etc/snmp/snmptrapd.conf file you'll want it to read simply:

traphandle default /usr/local/sbin/snmptt
disableAuthorization yes


In the /etc/snmp/snmptt.ini file I set the following options.

mode = standalone

description_mode = 1

unknown_trap_exec = /etc/snmp/traphandle.sh

Convert your MIB to something that can be read by snmptt


Given your MIB file you want one conf file that snmptt can handle. You can convert the MIB to a conf file by running the following command:

snmpttconvertmib --in=/where/your/mib/is/NAME.mib --out=/etc/snmp/myMIB.conf --exec='/etc/snmp/traphandle.sh $r $s "$D"'

We used "--exec" in the MIB convert process. This will give a command that will be executed when that OID is found. This command could be something like a Nagios event handler, or a shell script (which is what I'm using). You can choose the variables you want passed to your traps. There's a a lot in the documentation. In this example I used:

$R, $r  - Trap hostname
$s  - Severity
$D - Description text from SNMPTT.CONF or MIB file

After that you have to change your /etc/snmp/snmptt.ini:

snmptt_conf_files = <<END
/etc/snmp/miMIB.conf

If you make more conf files you can just add new ones on a new line:

snmptt_conf_files = <<END
/etc/snmp/miMIB.conf
/etc/snmp/miMIB2.conf

Handling Traps

The shell script (/etc/snmp/traphandle.sh) used in the --event line during the MIB conversion process could be anything you want:

#!/bin/sh
#
echo "$4

Host: $1
Severity: $2

Description:
$3
" | mail -s "$2 Error from: $1" trap@openwsn.org

This will send a simple e-mail out when a trap is received.

To use the Nagios Handler instead of calling /etc/snmp/the traphandle.sh shell script, we can replace --event entry by:

/usr/share/nagios3/plugins/eventhandlers/submit_check_result

Creating a MIB

To create a MIB for openwsn I used a very friendly gui program named snmpb.

As a reference other MIBs can be used. Using snmpb you can load them (located at /usr/share/apps/snmpb/mib) and modify the fields according to your needs. The following example is a very simple approximation to what we want to monitor from motes. Note that in some cases, instead of single values we want to deal with arrays as a mote can have more than one neighbor.

OPENWSN-MIB DEFINITIONS ::= BEGIN


IMPORTS

MODULE-IDENTITY, OBJECT-TYPE,

experimental FROM SNMPv2-SMI

TimeInterval, DisplayString

FROM SNMPv2-TC;
 

openwsnMIB MODULE-IDENTITY

LAST-UPDATED "9801290000Z"

ORGANIZATION "UC Berkeley"

CONTACT-INFO

	" Xavi Vilajosana

	Postal: Cory Hall

	Swarm Lab.UC Berkeley.

	Berkeley, CA 94720.

	US

 	Email: xvilajosana@eecs.berkeley.edu"


DESCRIPTION

"The MIB module for entities running OpenWSN."

	::= { experimental 88 }

 
nodeId OBJECT-TYPE

	SYNTAX DisplayString (SIZE (0..8))

	MAX-ACCESS read-only

	STATUS current

	DESCRIPTION

	"The 64bit ID of the mote"

	::= { openwsnMIB 1 }

 
rank OBJECT-TYPE

	SYNTAX INTEGER

	MAX-ACCESS read-only

	STATUS current

	DESCRIPTION

	"The rank in the network."

	::= { openwsnMIB 2 }

 
nodeType OBJECT-TYPE

	SYNTAX INTEGER {

	base-station(1),

	node(2)

	}

	MAX-ACCESS read-only

	STATUS current

	DESCRIPTION

	"whether it is base station or not."

	::= { openwsnMIB 3 }

 

numTx OBJECT-TYPE

	SYNTAX INTEGER

	MAX-ACCESS read-only

	STATUS current

	DESCRIPTION

	"The number of tx packets."

	::= { openwsnMIB 4 }

 
numRx OBJECT-TYPE

	SYNTAX INTEGER

	MAX-ACCESS read-only

	STATUS current

	DESCRIPTION

	"The number of rx packets."

	::= { openwsnMIB 5 }

 

numTxAck OBJECT-TYPE

	SYNTAX INTEGER

	MAX-ACCESS read-only

	STATUS current

	DESCRIPTION

	"The number of acks received."

	::= { openwsnMIB 6 }

END

(download this mib)

 

Conclusion

TBD...

References

http://www.nagios.org/

http://snmptt.sourceforge.net/

http://xavier.dusart.free.fr/nagios/en/snmptraps.html

http://tutorials.section6.net/home/setting-up-snmp-trap-handling-using-snmptrapd-and-snmptt

http://askaralikhan.blogspot.com/2010/12/receiving-snmp-traps-in-nagios.html