Home

Snmp interface check
Script : check_snmp_int.pl Last update : March 17 2007

Description :

Checks by snmp (v1, v2c or v3) host interface state and usage.
Interfaces can be selected by regexp ( 'eth' will check eth0, eth1, eth2, ...).
If multiple interfaces are selected, all must be up to get an OK result
Vérifie par snmp v1, v2c ou v3 l'état des interfaces d'un hôte, leur utilisation (bande passante, erreurs, pertes) et sortir des informations de performances.
Ce script permet d'utiliser des expressions régulières pour sélectionner les interfaces : ex 'eth' va vérifier eth0, eth1, ...
Il permet également de lister toutes les interfaces disponibles sur la machine cible (option -v) pour voir leur nom en SNMP.
Pour les francophones, je ferais un manuel en Français quand j'aurais le temps... (et toute aide est bienvenue).
Standard checks

The script will check interface operationnal status using the MIB-II table. The interface is (are) selected by the -n option.
This option will be treated as a regular expression (eth will match eth0, eth1, eth2...). You can disable this with the -r option : the interface will be selected if it's description exactly matches the name given by -n

The interfaces are selected by their description in the MIB-II table.
To see how interface looks like by snmp, you can list all of them with the '-v' switch.

The script will return OK if ALL interfaces selected are UP, or CRITICAL if at least one interface is down.
You can make the script return a OK value when all interfaces are down (and CRITICAL when at least one is up) with the -i option.

You can make the same tests on administrative status instead with the -a option.

To make output shorter, specially when you have multiple interface, you can put the -s option.
It will get only the first <n> caracters of the interface descrition. If the number is negative then get the last <n> caracters.

Ex : EL20005 3Com Gigabit NIC (3C2000 Family)
-s 4 will output : "EL20".
-s -4 will output : "ily)".

Performance output

-f option : activate performance output (default the In/out octet as a counter).
-e option : in/out errors and discarded packets. -f must also be set.
-S option : Include speed in performance output in bits/s as '<interface_name>_speed_bps'
-y option : output performance data in % of interface speed
-Y option : output performance data in bits/s or Bytes/s (depending on -B)

Note : -y and -Y options need the usage check to ba active (-k)

Warning : the counters needed by -e are not always available on all machines (ex Nokia IP)

Usage check (-k)
A temporary file will be created in "/tmp" by default : this can be changed at the beginning of the script.
The file name will be : tmp_Nagios_int.<host IP>.<Interface name>. One file will be created by interface.
The status UNKNOWN is returned when the script doesn't have enough information (see -d option).
You will have to tell the warning and critical levels, separated with "," and you can use decimal (ex : 10.3).
For standard checks (no "-q" option) :
-w <In warn>,<Out warn> -c <In warn>,<Out warn>
In warn : warning level for incomming traffic
Out warn : warning level for outgoing traffic
In crit : critical level for incomming traffic
Out crit : critical level for outgoing traffic

The unit for the check depends on the -B, -M and -G option :

| -B set | -B not set
-M & -G not set | Kbps | KBps
-M set | Mbps | MBps
-G set | Gbps | GBps

It is possible to put warning and critical levels with -b option.
0 means no warning or critical level checks

When the extended checks are activated (-q option), the warning levels are
-w <In bytes>,<Out bytes>,<In error>,<Out error>,<In disc>,<Out disc> -c <In warn>,<Out warn>, .....
In error : warn/crit level in inboud error/minute
Out error : warn/crit level in outbound error/minute
In disc : warn/crit level in inboud discarded packets/minute
Out disc : warn/crit level in outbound discarded packets/minute

-k : activates the standard usage feature
-q : activates the extended usage
-d : delta in seconds (default is 300s)
-w : warning levels
-c : critical levels

-d: delta time
You can put the delta time as an option : the "delta" is the prefered time between two values that the script will use to calculate the average Kbytes/s or error/min. The delta time should (not must) be bigger than the check interval.
Here is an example : Check interval of 2 minutes and delta of 4min

T0 : value 1 : can't calculate usage
T0+2 : value 2 : can't calculate usage
T0+4 : value 3 : usage=(value3-value1)/((T0+4)-T0)
T0+6 : value 4 : usage=(value4-value2)/((T0+6)-T0+2)
(Yes I know TO+4-T0=4, it's just to explain..)
.........

The script will allow 10% less of the delta and 300% more than delta as a correct interval.
For example, with a delta of 5 minutes, the acceptable interval will be between 4'30" and 15 minutes.

Msg size option (-o option)

In case you get a "ERROR: running table : Message size exceeded maxMsgSize" error, you may need to adjust the maxMsgSize, i.e. the maximum size of snmp message with the -o option. Try a value with the -o AND the -v option : the script will output the actual value so you can add some octets to it with the -o option.

--label option

This option just put label before the speed output :
Without : eth1:UP (10.3Kbps/4.4Kbps), eth0:UP (10.9Kbps/16.4Kbps):2 UP: OK
With : eth1:UP (in=14.4Kbps/out=6.2Kbps), eth0:UP (in=15.3Kbps/out=22.9Kbps):2 UP: OK

SNMP Login

See snmp info page

Requirements :

- Perl in /usr/bin/perl - or just run 'perl script'
- Net::SNMP
- file 'utils.pm' in plugin diretory (/usr/local/nagios/libexec)

Dowload latest version : 1.4.5

Configuration examples

Examples :

All examples below are considering the script is local directory. Host to be checked is 127.0.0.1 with snmp community "public".

If multiple interfaces are selected, all must be up to get an OK result

Get help | ./check_snmp_int.pl -h
List all interfaces | ./check_snmp_int.pl -H 127.0.0.1 -C public -n zzzz -v
snmpv3 login | ./check_snmp_int.pl -H 127.0.0.1 -l login -w passwd
Check eth0 interface is up | ./check_snmp_int.pl -H 127.0.0.1 -C public -n eth0 -r
Check that all eth interface are up | ./check_snmp_int.pl -H 127.0.0.1 -C public -n eth
Check that all ppp interface are down | ./check_snmp_int.pl -H 127.0.0.1 -C public -n ppp -i
Check that all eth interface are administratively up | ./check_snmp_int.pl -H 127.0.0.1 -C public -n eth -a
Check that FastEternet0/11 to 0/14 are up (Cisco) | ./check_snmp_int.pl -H 127.0.0.1 -C public -n "Fast.*0.1[1234]"
Check the eth0 usage Note : no critical inbound (0) | ./check_snmp_int.pl -H 127.0.0.1 -C public -n eth0 -k -w 200,400 -c 0,600

Changelog : On CVS repository on sourceforge : http://nagios-snmp.cvs.sourceforge.net/nagios-snmp/plugins/.

Output of check_snmp_int.pl -h

SNMP Network Interface Monitor for Nagios version 1.4.5
GPL licence, (c)2004-2007 Patrick Proy

Usage: ./check_snmp_int.pl [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd [-X pass -L <authp>,<privp>) [-p <port>] -n <name in desc_oid> [-i] [-a] [-r] [-f[eSyY]] [-k[qBMGu] -g -w<warn levels> -c<crit levels> -d<delta>] [-o <octet_length>] [-t <timeout>] [-s] [-V]
-v, --verbose
print extra debugging information (including interface list on the system)
-h, --help
print this help message
-H, --hostname=HOST
name or IP address of host to check
-C, --community=COMMUNITY NAME
community name for the host's SNMP agent (implies v1 protocol)
-l, --login=LOGIN ; -x, --passwd=PASSWD, -2, --v2c
Login and auth password for snmpv3 authentication
If no priv password exists, implies AuthNoPriv
-2 : use snmp v2c
-X, --privpass=PASSWD
Priv password for snmpv3 (AuthPriv protocol)
-L, --protocols=<authproto>,<privproto>
<authproto> : Authentication protocol (md5|sha : default md5)
<privproto> : Priv protocole (des|aes : default des)
-P, --port=PORT
SNMP port (Default 161)
-n, --name=NAME
Name in description OID (eth0, ppp0 ...).
This is treated as a regexp : -n eth will match eth0,eth1,...
Test it before, because there are known bugs (ex : trailling /)
-r, --noregexp
Do not use regexp to match NAME in description OID
-i, --inverse
Make critical when up
-a, --admin
Use administrative status instead of operational
-o, --octetlength=INTEGER
max-size of the SNMP message, usefull in case of Too Long responses.
Be carefull with network filters. Range 484 - 65535, default are
usually 1472,1452,1460 or 1440.
-f, --perfparse, --perfdata
Performance data output (no output when interface is down).
-e, --error
Add error & discard to Perfparse output
-S, --intspeed
Include speed in performance output in bits/s
-y, --perfprct ; -Y, --perfspeed
-y : output performance data in % of max speed
-Y : output performance data in bits/s or Bytes/s (depending on -B)
-k, --perfcheck ; -q, --extperfcheck
-k check the input/ouput bandwidth of the interface
-q also check the error and discard input/output
-g, --64bits
Use 64 bits counters instead of the standard counters
when checking bandwidth & performance data.
-d, --delta=seconds
make an average of <delta> seconds (default 300=5min)
-B, --kbits
Make the warning and critical levels in K|M|G Bits/s instead of K|M|G Bytes/s
-G, --giga ; -M, --mega ; -u, --prct
-G : Make the warning and critical levels in Gbps (with -B) or GBps
-M : Make the warning and critical levels in Mbps (with -B) or MBps
-u : Make the warning and critical levels in % of reported interface speed.
-w, --warning=input,output[,error in,error out,discard in,discard out]
warning level for input / output bandwidth (0 for no warning)
unit depends on B,M,G,u options
warning for error & discard input / output in error/min (need -q)
-c, --critical=input,output[,error in,error out,discard in,discard out]
critical level for input / output bandwidth (0 for no critical)
unit depends on B,M,G,u options
critical for error & discard input / output in error/min (need -q)
-s, --short=int
Make the output shorter : only the first <n> chars of the interface(s)
If the number is negative, then get the <n> LAST caracters.
-t, --timeout=INTEGER
timeout for SNMP in seconds (Default: 5)
-V, --version
prints version number
Note : when multiple interface are selected with regexp,
all be must be up (or down with -i) to get an OK result.

This project is hosted on : http://sourceforge.net/projects/nagios-snmp Nagios and the Nagios logo are registered trademarks of Ethan Galstad.