#!/usr/bin/perl -w # # check_ping1 - nagios plugin # # Copyright (C) 2006 AUTHOR, # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # # Report bugs to: usv15@gmx.at # # 13.09.2007 Version 1.0 # # use strict; use Getopt::Long; use lib "/usr/local/nagios/libexec"; # Pfad zur util.pm !! use utils qw ($TIMEOUT %ERRORS &print_revision &support); sub print_help (); sub print_usage (); my ($opt_h, $opt_H, $opt_C, $opt_w, $opt_c, $opt_o, $opt_t); my ($result, $value, $age, $size, $unit); my $PROGNAME="check_snmp1"; $opt_H=""; $opt_o=""; $opt_C="public"; $opt_t=5; $opt_w=0; $opt_c=0; Getopt::Long::Configure('bundling'); GetOptions( "h" => \$opt_h, "help" => \$opt_h, "H=s" => \$opt_H, "hostname" => \$opt_H, "C=s" => \$opt_C, "community" => \$opt_C, "o=s" => \$opt_o, "oid" => \$opt_o, "w=f" => \$opt_w, "warning=i" => \$opt_w, "c=f" => \$opt_c, "critical=i" => \$opt_c); if ($opt_t) { $TIMEOUT=$opt_t; } # Just in case of problems, let's not hang Nagios $SIG{'ALRM'} = sub { print "UNKNOWN - Plugin Timed out\n"; exit $ERRORS{"UNKNOWN"}; }; alarm($TIMEOUT); if ($opt_h) { print_help(); exit $ERRORS{'OK'}; } if (! $opt_H) { print "No Host/IP defined!\n\n"; print_usage(); exit $ERRORS{'UNKNOWN'}; } if (! $opt_o) { print "No OID defined!\n\n"; print_usage(); exit $ERRORS{'UNKNOWN'}; } if (! $opt_w) { print "No warning value defined!\n\n"; print_usage(); exit $ERRORS{'UNKNOWN'}; } if (! $opt_c) { print "No critical value defined!\n\n"; print_usage(); exit $ERRORS{'UNKNOWN'}; } sub print_usage () { print "Usage:\n"; print " .//check_ifspeed -H -C -o -w -c \n\n"; } sub print_help () { print "Copyright (c) 2007 Thomas Reichssoellner\n\n"; print_usage(); support(); } #################################################### my $speed = `snmpget -v1 -m all -O v -O q -c $opt_C $opt_H $opt_o`; chop($speed); my $speed_old = 0; my $time = time(); my $time_old = 0; my $file = "/tmp/snmp-$opt_H\-$opt_o\.dat"; if(!(-e "$file")) { open(DAT, ">$file"); print DAT "$speed;$time"; close(DAT); print "UNKNOWN - New file created ($file)"; exit 3; } open(DAT, "<$file"); ($speed_old,$time_old) = split(/;/,); close(DAT); open(DAT, ">$file"); print DAT "$speed;$time"; close(DAT); #print "speed: $speed\n"; #print "speed_old: $speed_old\n"; #print "time: $time\n"; #print "time_old: $time_old\t"; $value = ($speed - $speed_old) / (8 * ($time - $time_old)); if ($value > 1024*1024) { $result = $value / (1024*1024); $unit = "Mbps"; } elsif ($value > 1024) { $result = $value / (1024); $unit = "kbps"; } else { $result = $value; $unit = "bps"; } if ($value > $opt_c) { printf "CRITICAL - IfSpeed: %.2f $unit | IfSpeed=%.2fbps;$opt_w;$opt_c;0;", $result, $value; exit 2; } elsif ($value > $opt_w) { printf "WARNING - IfSpeed: %.2f $unit | IfSpeed=%.2fbps;$opt_w;$opt_c;0;", $result, $value; exit 1; } else { printf "OK - IfSpeed: %.2f $unit | IfSpeed=%.2fbps;$opt_w;$opt_c;0;", $result, $value; exit 0; } #Exit with Unknown if IF-Block fails: print "UNKNOWN - Correct execution of plugin failed!"; exit 3;