Archive for the ‘Nagios’ Category

Nagios plugin: check_snmp_ifstatus.pl (redux)

Thursday, July 1st, 2010

Some time ago I posted a nagios plugin I had knocked together for monitoring network interfaces using snmp. Much to my surprise, a number of people have found the plugin useful and suggested some enhancements to make it more useful. I’ve finally taken some time to implement those changes and here are the results

# ./check_snmp_ifstatus.pl --help

Usage: check_snmp_ifstatus.pl -H hostaddress -i "if_description" [-b if_max_bps] [-C snmp_community] [-v 1|2] [-p snmp_port] [-w warn] [-c crit]Options:
  -H --host STRING or IPADDRESS
  IP Address of host to check. Required.
  -i --interface STRING
  Full name or numeric index number of the interface to check. Required.
  Examples would be "eth0", "FastEthernet0/1", 1 or 65539
  -C --community STRING
  SNMP Community string. Optional. Defaults to 'public'
  -v --version INTEGER
  SNMP Version ( 1 or 2 ). Optional. Defaults to 1
  -p --port INTEGER
  SNMP port. Optional. Defaults to 161
  -b --bandwidth INTEGER
  Interface maximum speed in bits per second. Optional.
  Use this to override the value returned by SNMP if it lies about
  the max speed of the interface.
  -6 --64bit
  Use 64bit counters for bandwidth usage. Not available on all devices.
  -w --warning INTEGER
  % of bandwidth usage necessary to result in warning status. Optional.
  Defaults to 85%
  -c --critical INTEGER
  % of bandwidth usage necessary to result in critical status. Optional.
  Defaults to 98%

The major difference for this new version is that it now allows you to input the ifIndex number of the interface you wish test directly rather than relying on the device supporting the ifDesc oid. This means you can now use it to test interfaces on Microsoft Windows computers and devices that don’t have unique descriptions for each interface. For example, if the result of an snmpwalk of the device showed “IF-MIB::ifIndex.1 = INTEGER: 1” and “IF-MIB::ifDescr.1 = STRING: eth0” you would be able to refer to this interface as either ‘-i eth0’ or ‘-i 1’. For a MS Windows computer, you would typically use ‘-i 65539’ for the first LAN interface.

You may also notice that I have added some preliminary support for reading the 64bit counters on devices that support this. Please note that this is entirely untested, as I do not have any devices to test it on. If you do try this out and it works for you, please let me know.

Installing the plugin is very straight-forward. First, download the check_snmp_ifstatus_v2.tar file and extract the check_snmp_ifstatus.pl file from it.

# tar -xf check_snmp_ifstatus_v2.tar

Copy the check_snmp_ifstatus.pl file to your /usr/lib/nagios/plugins/contrib folder.
Add a command to reference the plugin in your “/etc/nagios/objects/commands.cfg” file, like so…

define command {
command_name check_snmp_ifstatus
command_line /usr/bin/perl $USER1$/contrib/check_snmp_ifstatus.pl -H $HOSTADDRESS$ -i $ARG1$ -w $ARG2$ -c $ARG3$ $ARG4$
}

Add a service entry for each host you want to check in your “/etc/nagios/objects/services.cfg” file, like so…

define service{
use generic-service
check_command check_snmp_ifstatus!"Ethernet0/0"!85!98
service_description Network Status: e0/0
normal_check_interval 5
retry_check_interval 1
host_name cisco1
}

define service{
use generic-service
check_command check_snmp_ifstatus!"eth0"!50!90!-b 1000000000
service_description Network Status: eth0
normal_check_interval 1
retry_check_interval 1
host_name linux1,linux2
}

define service{
use generic-service
check_command check_snmp_ifstatus!65539!25!80
service_description Network Status: LAN
normal_check_interval 1
retry_check_interval 1
host_name winserver1
}

Now verify that you haven’t made any mistakes in the nagios configuration files…

# nagios -v nagios.cfg

And restart the nagios service if all looks well…

# /sbin/service nagios restart

You should now see new service entries for your hosts listing the current interface status. Enjoy.

Nagios plugin: check_cpu.sh and check_mem.sh

Saturday, August 23rd, 2008

I have written a couple more Nagios plugins for use with NRPE on linux machines. The first one, “check_cpu.sh ,” grabs the cpu state from “/proc/stats” and sends back a status result and perfdata. You can tell it to send back either the aggregate data from all cpus as a single total or can have it return all cpus individually. Be aware though, that if you wish to have it send data on all cpu’s you will need to patch Nagios to allow for a larger perfdata return buffer. I didn’t want to mess with doing that, so I just have it watch the aggregate data.

check_cpu.sh preview

The second plugin, “check_mem.sh,” will parse the output of “free -mt” to give you a look at the current memory and swap utilization.

check_mem.sh preview

Nagios plugin: check_snmp_ifstatus.pl

Wednesday, August 13th, 2008

While looking around for a nagios plugin to monitor the ethernet interfaces on my equipment, I just could not find one that did exactly what I wanted. So… I did exactly what OSS was designed for.  I took a plugin that had similar functionality as a starting point and re-wrote it to operate the way I needed. This is the result of my re-write of check_iftraffic.pl found on NagiosExchange.

“check_snmp_ifstatus.pl” will take a host IP address and interface name and return the current status of the interface. The returned data includes the UP/DOWN status, the interface line speed, and the current RX/TX bps. This status is returned as both an OK/Warning/Critical description and performance data usable with rrdtool. I have also created a pnp4nagios template for use with the plugin so that the perfdata can be easily viewed.

# check_snmp_ifstatus.pl -H 10.0.0.1 -i "Ethernet0/0"
OK: Ethernet0/0 is UP at 10Mbps. RX=72.27Kbps (0.72%), TX=4.094Kbps (0.04%) | RXbps=72271;8500000;9800000;0;10000000 TXbps=4094;8500000;9800000;0;10000000 RXpct=0.72%;85;98;0;100 TXpct=0.04%;85;98;0;100 elapsed=30s;3435;;;

(more…)