February 17, 2006

324 words 2 mins read

Nagios Plugin

Recently I’ve been doing some work on Nagios. Its a really handy tool as it can check purdy much anything. I found a plugin called disk_by_snmp.sh, which was promising. The only problem is that the plugin was written along time ago, for nagios 1.0 (best I can tell), using Awk, DC and a few other misc apps. It just didnt work any more — very sadly. A friend of mine tried to update it, but it didn’t go too well. Instead of trying to get it working, I decided to re-write the script into perl (and update it a tiny bit to deal with nagios 2.0). I’m happy to present disk_by_snmp.pl (It requires Math::Round, and thats it).

I’m including some instructions in the extended body.

WLOD: Twinkie Defense

UPDATED: Fixed the link for the script. My Bad.

Add the following to

checkcommand.cfg:

define command {

command_name disk_by_snmp

command_line /usr/local/nagios/libexec/disk_by_snmp.pl $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$ $ARG4$

}

Do an SNMP Walk similar to the command below and get a result like the one below. The last number in the MIB is what you need to remember (in this case 2 for C:)

[[email protected]]# snmpwalk -O n -v 1 -c public MyServer .1.3.6.1.2.1.25.2.3.1.3

.1.3.6.1.2.1.25.2.3.1.3.1 = STRING: A:\

.1.3.6.1.2.1.25.2.3.1.3.2 = STRING: C:\ Label: Serial Number 386ec682

.1.3.6.1.2.1.25.2.3.1.3.3 = STRING: D:\ Label: Serial Number 8468ec06

.1.3.6.1.2.1.25.2.3.1.3.4 = STRING: E:\ Label: Serial Number 6c0d9f08

.1.3.6.1.2.1.25.2.3.1.3.5 = STRING: F:\

.1.3.6.1.2.1.25.2.3.1.3.6 = STRING: Virtual Memory

[[email protected]]#

Add something like the following to your services.cfg :

define service{

use generic-service ; Name of service template to use

host_name MyServer

service_description DISK_USAGE_C

is_volatile 0

check_period 24×7

max_check_attempts 5

normal_check_interval 10

retry_check_interval 5

contact_groups nagios-admins

notification_interval 240

notification_period 24×7

notification_options c,r

check_command disk_by_snmp!public!2!20!10

}

The check command options (in case you didn’t figure it out): disk_by_snmp!communityname!MIB_Number!WarningPercentage!CriticalPercentage!

Hopefully that explains enough to help anyone else use the script if they want. Oh, and remember — that I only updated the script originally written by Fredrik Wanglund.