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. Ive 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 dont 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 havent 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.