new functionnality : if interface down, a message is printed

git-svn-id: http://svn.centreon.com/Plugins/Dev@2768 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Mat Sugumaran 2007-07-25 12:01:05 +00:00
parent bae9070afb
commit b2df2a7365
1 changed files with 470 additions and 453 deletions

View File

@ -1,453 +1,470 @@
#! /usr/bin/perl -w #! /usr/bin/perl -w
################################################################### ###################################################################
# Oreon is developped with GPL Licence 2.0 # Oreon is developped with GPL Licence 2.0
# #
# GPL License: http://www.gnu.org/licenses/gpl.txt # GPL License: http://www.gnu.org/licenses/gpl.txt
# #
# Developped by : Julien Mathis - Romain Le Merlus # Developped by : Julien Mathis - Romain Le Merlus
# Christophe Coraboeuf - Sugumaran Mathavarajan # Christophe Coraboeuf - Sugumaran Mathavarajan
# #
################################################################### ###################################################################
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# For information : contact@merethis.com # For information : contact@merethis.com
#################################################################### ####################################################################
# #
# Script init # Script init
# #
use strict; use strict;
use Net::SNMP qw(:snmp oid_lex_sort); use Net::SNMP qw(:snmp oid_lex_sort);
use FindBin; use FindBin;
use lib "$FindBin::Bin"; use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@"; use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support); use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) { if (eval "require oreon" ) {
use oreon qw(get_parameters); use oreon qw(get_parameters);
use vars qw(%oreon); use vars qw(%oreon);
%oreon=get_parameters(); %oreon=get_parameters();
} else { } else {
print "Unable to load oreon perl module\n"; print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
use vars qw($PROGNAME); use vars qw($PROGNAME);
use Getopt::Long; use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_b $opt_k $opt_u $opt_p $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T); use vars qw($opt_V $opt_h $opt_v $opt_C $opt_b $opt_k $opt_u $opt_p $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T);
# Plugin var init # Plugin var init
my($proc, $proc_run, @test, $row, @laste_values, $last_check_time, $last_in_bits, $last_out_bits, @last_values, $update_time, $db_file, $in_traffic, $out_traffic, $in_usage, $out_usage); my($proc, $proc_run, @test, $row, @laste_values, $last_check_time, $last_in_bits, $last_out_bits, @last_values, $update_time, $db_file, $in_traffic, $out_traffic, $in_usage, $out_usage);
$PROGNAME = "$0"; $PROGNAME = "$0";
sub print_help (); sub print_help ();
sub print_usage (); sub print_usage ();
Getopt::Long::Configure('bundling'); Getopt::Long::Configure('bundling');
GetOptions GetOptions
("h" => \$opt_h, "help" => \$opt_h, ("h" => \$opt_h, "help" => \$opt_h,
"u=s" => \$opt_u, "username=s" => \$opt_u, "u=s" => \$opt_u, "username=s" => \$opt_u,
"p=s" => \$opt_p, "password=s" => \$opt_p, "p=s" => \$opt_p, "password=s" => \$opt_p,
"k=s" => \$opt_k, "key=s" => \$opt_k, "k=s" => \$opt_k, "key=s" => \$opt_k,
"s" => \$opt_s, "show" => \$opt_s, "s" => \$opt_s, "show" => \$opt_s,
"V" => \$opt_V, "version" => \$opt_V, "V" => \$opt_V, "version" => \$opt_V,
"i=s" => \$opt_i, "interface=s" => \$opt_i, "i=s" => \$opt_i, "interface=s" => \$opt_i,
"n" => \$opt_n, "name" => \$opt_n, "n" => \$opt_n, "name" => \$opt_n,
"v=s" => \$opt_v, "snmp=s" => \$opt_v, "v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C, "C=s" => \$opt_C, "community=s" => \$opt_C,
"b=s" => \$opt_b, "bps=s" => \$opt_b, "b=s" => \$opt_b, "bps=s" => \$opt_b,
"w=s" => \$opt_w, "warning=s" => \$opt_w, "w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c, "c=s" => \$opt_c, "critical=s" => \$opt_c,
"T=s" => \$opt_T, "T=s" => \$opt_T,
"H=s" => \$opt_H, "hostname=s" => \$opt_H); "H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) { if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $'); print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
if ($opt_h) { if ($opt_h) {
print_help(); print_help();
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
Getopt::Long::Configure('bundling'); Getopt::Long::Configure('bundling');
} }
################################################## ##################################################
##### Verify Options ##### Verify Options
## ##
if (!$opt_H) { if (!$opt_H) {
print_usage(); print_usage();
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
my $snmp = "1"; my $snmp = "1";
if ($opt_v && $opt_v =~ /^[0-9]$/) { if ($opt_v && $opt_v =~ /^[0-9]$/) {
$snmp = $opt_v; $snmp = $opt_v;
} }
if ($snmp eq "3") { if ($snmp eq "3") {
if (!$opt_u) { if (!$opt_u) {
print "Option -u (--username) is required for snmpV3\n"; print "Option -u (--username) is required for snmpV3\n";
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
if (!$opt_p && !$opt_k) { if (!$opt_p && !$opt_k) {
print "Option -k (--key) or -p (--password) is required for snmpV3\n"; print "Option -k (--key) or -p (--password) is required for snmpV3\n";
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
}elsif ($opt_p && $opt_k) { }elsif ($opt_p && $opt_k) {
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n"; print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
} }
if ($opt_n && !$opt_i) { if ($opt_n && !$opt_i) {
print "Option -n (--name) need option -i (--interface)\n"; print "Option -n (--name) need option -i (--interface)\n";
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
if (!$opt_C) { if (!$opt_C) {
$opt_C = "public"; $opt_C = "public";
} }
if (!$opt_i) { if (!$opt_i) {
$opt_i = 2; $opt_i = 2;
} }
if (!$opt_b) { if (!$opt_b) {
$opt_b = 95; $opt_b = 95;
} }
if ($opt_b =~ /([0-9]+)/) { if ($opt_b =~ /([0-9]+)/) {
my $bps = $1; my $bps = $1;
} }
my $critical = 95; my $critical = 95;
if ($opt_c && $opt_c =~ /[0-9]+/) { if ($opt_c && $opt_c =~ /[0-9]+/) {
$critical = $opt_c; $critical = $opt_c;
} }
my $warning = 80; my $warning = 80;
if ($opt_w && $opt_w =~ /[0-9]+/) { if ($opt_w && $opt_w =~ /[0-9]+/) {
$warning = $opt_w; $warning = $opt_w;
} }
my $interface = 0; my $interface = 0;
if ($opt_i =~ /([0-9]+)/ && !$opt_n){ if ($opt_i =~ /([0-9]+)/ && !$opt_n){
$interface = $1; $interface = $1;
} elsif (!$opt_n) { } elsif (!$opt_n) {
print "Unknown -i number expected... or it doesn't exist, try another interface - number\n"; print "Unknown -i number expected... or it doesn't exist, try another interface - number\n";
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
if ($critical <= $warning){ if ($critical <= $warning){
print "(--crit) must be superior to (--warn)"; print "(--crit) must be superior to (--warn)";
print_usage(); print_usage();
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
################################################# #################################################
##### Plugin snmp requests ##### Plugin snmp requests
## ##
my $OID_DESC =$oreon{MIB2}{IF_DESC}; my $OID_DESC =$oreon{MIB2}{IF_DESC};
my $OID_OPERSTATUS =$oreon{MIB2}{IF_OPERSTATUS};
# create a SNMP session my @operstatus = ("up","down","testing", "unknown", "dormant", "notPresent", "lowerLayerDown");
my ($session, $error);
if ($snmp eq "1" || $snmp eq "2") { # create a SNMP session
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); my ($session, $error);
if (!defined($session)) { if ($snmp eq "1" || $snmp eq "2") {
print("UNKNOWN: SNMP Session : $error\n"); ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
exit $ERRORS{'UNKNOWN'}; if (!defined($session)) {
} print("UNKNOWN: SNMP Session : $error\n");
}elsif ($opt_k) { exit $ERRORS{'UNKNOWN'};
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); }
if (!defined($session)) { }elsif ($opt_k) {
print("UNKNOWN: SNMP Session : $error\n"); ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
exit $ERRORS{'UNKNOWN'}; if (!defined($session)) {
} print("UNKNOWN: SNMP Session : $error\n");
}elsif ($opt_p) { exit $ERRORS{'UNKNOWN'};
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p); }
if (!defined($session)) { }elsif ($opt_p) {
print("UNKNOWN: SNMP Session : $error\n"); ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
exit $ERRORS{'UNKNOWN'}; if (!defined($session)) {
} print("UNKNOWN: SNMP Session : $error\n");
} exit $ERRORS{'UNKNOWN'};
}
#getting interface using its name instead of its oid index }
if ($opt_n) { #getting interface using its name instead of its oid index
my $result = $session->get_table(Baseoid => $OID_DESC);
if (!defined($result)) { if ($opt_n) {
printf("ERROR: Description Table : %s.\n", $session->error); my $result = $session->get_table(Baseoid => $OID_DESC);
$session->close; if (!defined($result)) {
exit $ERRORS{'UNKNOWN'}; printf("ERROR: Description Table : %s.\n", $session->error);
} $session->close;
foreach my $key ( oid_lex_sort(keys %$result)) { exit $ERRORS{'UNKNOWN'};
if ($result->{$key} =~ m/$opt_i/) { }
my @oid_list = split (/\./,$key); foreach my $key ( oid_lex_sort(keys %$result)) {
$interface = pop (@oid_list) ; if ($result->{$key} =~ m/$opt_i/) {
} my @oid_list = split (/\./,$key);
} $interface = pop (@oid_list) ;
} }
}
my $OID_IN =$oreon{MIB2}{IF_IN_OCTET}.".".$interface; }
my $OID_OUT = $oreon{MIB2}{IF_OUT_OCTET}.".".$interface;
my $OID_SPEED = $oreon{MIB2}{IF_SPEED}.".".$interface; my $OID_IN =$oreon{MIB2}{IF_IN_OCTET}.".".$interface;
my $OID_OUT = $oreon{MIB2}{IF_OUT_OCTET}.".".$interface;
# Get desctiption table my $OID_SPEED = $oreon{MIB2}{IF_SPEED}.".".$interface;
if ($opt_s) { # Get desctiption table
my $result = $session->get_table(Baseoid => $OID_DESC);
if (!defined($result)) { if ($opt_s) {
printf("ERROR: Description Table : %s.\n", $session->error); my $result = $session->get_table(Baseoid => $OID_DESC);
$session->close; if (!defined($result)) {
exit $ERRORS{'UNKNOWN'}; printf("ERROR: Description Table : %s.\n", $session->error);
} $session->close;
foreach my $key ( oid_lex_sort(keys %$result)) { exit $ERRORS{'UNKNOWN'};
my @oid_list = split (/\./,$key); }
my $index = pop (@oid_list) ; foreach my $key ( oid_lex_sort(keys %$result)) {
print "Interface $index :: $$result{$key}\n"; my @oid_list = split (/\./,$key);
} my $index = pop (@oid_list) ;
exit $ERRORS{'OK'}; my $interface_status = $session->get_request(-varbindlist => [$OID_OPERSTATUS.".".$index]);
} if (!defined($result)) {
printf("ERROR: Interface Status Request : %s", $session->error);
exit $ERRORS{'UNKNOWN'};
####### Get IN bytes }
print "Interface $index :: $$result{$key} :: ".$operstatus[$interface_status->{$OID_OPERSTATUS.".".$index} - 1]."\n";
my $in_bits; }
my $result = $session->get_request(-varbindlist => [$OID_IN]); exit $ERRORS{'OK'};
if (!defined($result)) { }
printf("ERROR: IN Bits : %s", $session->error);
if ($opt_n) { print " - You must specify interface name when option -n is used";} my $interface_status = $session->get_request(-varbindlist => [$OID_OPERSTATUS.".".$interface]);
print ".\n"; if (!defined($interface_status)) {
$session->close; printf("ERROR: Interface Status Request : %s", $session->error);
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
$in_bits = $result->{$OID_IN} * 8; if ($operstatus[$interface_status->{$OID_OPERSTATUS.".".$interface} - 1] ne "up") {
print "Error : interface is not ready - status : ".$operstatus[$interface_status->{$OID_OPERSTATUS.".".$interface} - 1]."\n";
exit $ERRORS{'CRITICAL'};
####### Get OUT bytes }
my $out_bits;
$result = $session->get_request(-varbindlist => [$OID_OUT]); ####### Get IN bytes
if (!defined($result)) {
printf("ERROR: Out Bits : %s", $session->error); my $in_bits;
if ($opt_n) { print " - You must specify interface name when option -n is used";} my $result = $session->get_request(-varbindlist => [$OID_IN]);
print ".\n"; if (!defined($result)) {
$session->close; printf("ERROR: IN Bits : %s", $session->error);
exit $ERRORS{'UNKNOWN'}; if ($opt_n) { print " - You must specify interface name when option -n is used";}
} print ".\n";
$out_bits = $result->{$OID_OUT} * 8; $session->close;
exit $ERRORS{'UNKNOWN'};
}
####### Get SPEED of interface $in_bits = $result->{$OID_IN} * 8;
my $speed_card;
$result = $session->get_request(-varbindlist => [$OID_SPEED]); ####### Get OUT bytes
if (!defined($result)) {
printf("ERROR: Interface Speed : %s", $session->error); my $out_bits;
if ($opt_n) { print " - You must specify interface name when option -n is used";} $result = $session->get_request(-varbindlist => [$OID_OUT]);
print ".\n"; if (!defined($result)) {
$session->close; printf("ERROR: Out Bits : %s", $session->error);
exit $ERRORS{'UNKNOWN'}; if ($opt_n) { print " - You must specify interface name when option -n is used";}
} print ".\n";
$session->close;
if (defined($opt_T)){ exit $ERRORS{'UNKNOWN'};
$speed_card = $opt_T * 1000000; }
} else { $out_bits = $result->{$OID_OUT} * 8;
$speed_card = $result->{$OID_SPEED};
}
####### Get SPEED of interface
#############################################
##### Plugin return code my $speed_card;
## $result = $session->get_request(-varbindlist => [$OID_SPEED]);
if (!defined($result)) {
$last_in_bits = 0; printf("ERROR: Interface Speed : %s", $session->error);
$last_out_bits = 0; if ($opt_n) { print " - You must specify interface name when option -n is used";}
print ".\n";
my $flg_created = 0; $session->close;
exit $ERRORS{'UNKNOWN'};
if (-e "/tmp/oreon_traffic_if".$interface."_".$opt_H) { }
open(FILE,"<"."/tmp/oreon_traffic_if".$interface."_".$opt_H);
while($row = <FILE>){ if (defined($opt_T)){
@last_values = split(":",$row); $speed_card = $opt_T * 1000000;
$last_check_time = $last_values[0]; } else {
$last_in_bits = $last_values[1]; $speed_card = $result->{$OID_SPEED};
$last_out_bits = $last_values[2]; }
$flg_created = 1;
} #############################################
close(FILE); ##### Plugin return code
} else { ##
$flg_created = 0;
} $last_in_bits = 0;
$last_out_bits = 0;
$update_time = time();
my $flg_created = 0;
unless (open(FILE,">"."/tmp/oreon_traffic_if".$interface."_".$opt_H)){
print "Unknown - /tmp/oreon_traffic_if".$interface."_".$opt_H. " !\n"; if (-e "/tmp/oreon_traffic_if".$interface."_".$opt_H) {
exit $ERRORS{"UNKNOWN"}; open(FILE,"<"."/tmp/oreon_traffic_if".$interface."_".$opt_H);
} while($row = <FILE>){
print FILE "$update_time:$in_bits:$out_bits"; @last_values = split(":",$row);
close(FILE); $last_check_time = $last_values[0];
$last_in_bits = $last_values[1];
if ($flg_created == 0){ $last_out_bits = $last_values[2];
print "First execution : Buffer in creation.... \n"; $flg_created = 1;
exit($ERRORS{"UNKNOWN"}); }
} close(FILE);
} else {
$flg_created = 0;
## Bandwith = IN + OUT / Delta(T) = 6 Mb/s }
## (100 * Bandwith) / (2(si full duplex) * Ispeed)
## Count must round at 4294967296 $update_time = time();
##
unless (open(FILE,">"."/tmp/oreon_traffic_if".$interface."_".$opt_H)){
if (($in_bits - $last_in_bits > 0) && defined($last_in_bits)) { print "Unknown - /tmp/oreon_traffic_if".$interface."_".$opt_H. " !\n";
my $total = 0; exit $ERRORS{"UNKNOWN"};
if ($in_bits - $last_in_bits < 0){ }
$total = 4294967296 - $last_in_bits + $in_bits; print FILE "$update_time:$in_bits:$out_bits";
} else { close(FILE);
$total = $in_bits - $last_in_bits;
} if ($flg_created == 0){
my $diff = time() - $last_check_time; print "First execution : Buffer in creation.... \n";
if ($diff == 0){$diff = 1;} exit($ERRORS{"UNKNOWN"});
my $pct_in_traffic = $in_traffic = abs($total / $diff); }
} else {
$in_traffic = 0;
} ## Bandwith = IN + OUT / Delta(T) = 6 Mb/s
## (100 * Bandwith) / (2(si full duplex) * Ispeed)
if ($out_bits - $last_out_bits > 0 && defined($last_out_bits)) { ## Count must round at 4294967296
my $total = 0; ##
if ($out_bits - $last_out_bits < 0){
$total = 4294967296 - $last_out_bits + $out_bits; if (($in_bits - $last_in_bits > 0) && defined($last_in_bits)) {
} else { my $total = 0;
$total = $out_bits - $last_out_bits; if ($in_bits - $last_in_bits < 0){
} $total = 4294967296 - $last_in_bits + $in_bits;
my $diff = time() - $last_check_time; } else {
if ($diff == 0){$diff = 1;} $total = $in_bits - $last_in_bits;
my $pct_out_traffic = $out_traffic = abs($total / $diff); }
} else { my $diff = time() - $last_check_time;
$out_traffic = 0; if ($diff == 0){$diff = 1;}
} my $pct_in_traffic = $in_traffic = abs($total / $diff);
} else {
if ( $speed_card != 0 ) { $in_traffic = 0;
$in_usage = sprintf("%.1f",($in_traffic*100) / $speed_card); }
$out_usage = sprintf("%.1f",($out_traffic*100) / $speed_card);
} if ($out_bits - $last_out_bits > 0 && defined($last_out_bits)) {
my $total = 0;
my $in_prefix = ""; if ($out_bits - $last_out_bits < 0){
my $out_prefix = ""; $total = 4294967296 - $last_out_bits + $out_bits;
} else {
my $in_perfparse_traffic = $in_traffic; $total = $out_bits - $last_out_bits;
my $out_perfparse_traffic = $out_traffic; }
my $diff = time() - $last_check_time;
if ($in_traffic > 1000) { if ($diff == 0){$diff = 1;}
$in_traffic = $in_traffic / 1000; my $pct_out_traffic = $out_traffic = abs($total / $diff);
$in_prefix = "k"; } else {
if($in_traffic > 1000){ $out_traffic = 0;
$in_traffic = $in_traffic / 1000; }
$in_prefix = "M";
} if ( $speed_card != 0 ) {
if($in_traffic > 1000){ $in_usage = sprintf("%.1f",($in_traffic*100) / $speed_card);
$in_traffic = $in_traffic / 1000; $out_usage = sprintf("%.1f",($out_traffic*100) / $speed_card);
$in_prefix = "G"; }
}
} my $in_prefix = "";
my $out_prefix = "";
if ($out_traffic > 1000){
$out_traffic = $out_traffic / 1000; my $in_perfparse_traffic = $in_traffic;
$out_prefix = "k"; my $out_perfparse_traffic = $out_traffic;
if ($out_traffic > 1000){
$out_traffic = $out_traffic / 1000; if ($in_traffic > 1000) {
$out_prefix = "M"; $in_traffic = $in_traffic / 1000;
} $in_prefix = "k";
if ($out_traffic > 1000){ if($in_traffic > 1000){
$out_traffic = $out_traffic / 1000; $in_traffic = $in_traffic / 1000;
$out_prefix = "G"; $in_prefix = "M";
} }
} if($in_traffic > 1000){
$in_traffic = $in_traffic / 1000;
my $in_bits_unit = ""; $in_prefix = "G";
$in_bits = $in_bits/1048576; }
if ($in_bits > 1000){ }
$in_bits = $in_bits / 1000;
$in_bits_unit = "G"; if ($out_traffic > 1000){
} else { $out_traffic = $out_traffic / 1000;
$in_bits_unit = "M"; $out_prefix = "k";
} if ($out_traffic > 1000){
$out_traffic = $out_traffic / 1000;
my $out_bits_unit = ""; $out_prefix = "M";
$out_bits = $out_bits/1048576; }
if ($out_bits > 1000){ if ($out_traffic > 1000){
$out_bits = $out_bits / 1000; $out_traffic = $out_traffic / 1000;
$out_bits_unit = "G"; $out_prefix = "G";
} else { }
$out_bits_unit = "M"; }
}
my $in_bits_unit = "";
$in_bits = $in_bits/1048576;
if ( $speed_card == 0 ) { if ($in_bits > 1000){
print "CRITICAL: Interface speed equal 0! Interface must be down.|traffic_in=0B/s traffic_out=0B/s\n"; $in_bits = $in_bits / 1000;
exit($ERRORS{"CRITICAL"}); $in_bits_unit = "G";
} } else {
$in_bits_unit = "M";
##################################### }
##### Display result
## my $out_bits_unit = "";
$out_bits = $out_bits/1048576;
if ($out_bits > 1000){
my $in_perfparse_traffic_str = sprintf("%.1f",abs($in_perfparse_traffic)); $out_bits = $out_bits / 1000;
my $out_perfparse_traffic_str = sprintf("%.1f",abs($out_perfparse_traffic)); $out_bits_unit = "G";
} else {
$in_perfparse_traffic_str =~ s/\./,/g; $out_bits_unit = "M";
$out_perfparse_traffic_str =~ s/\./,/g; }
my $status = "OK";
if ( $speed_card == 0 ) {
if(($in_usage > $warning) or ($out_usage > $warning)){ print "CRITICAL: Interface speed equal 0! Interface must be down.|traffic_in=0B/s traffic_out=0B/s\n";
$status = "WARNING"; exit($ERRORS{"CRITICAL"});
} }
if (($in_usage > $critical) or ($out_usage > $critical)){ #####################################
$status = "CRITICAL"; ##### Display result
} ##
printf("Traffic In : %.2f ".$in_prefix."b/s (".$in_usage." %%), Out : %.2f ".$out_prefix."b/s (".$out_usage." %%) - ", $in_traffic, $out_traffic); my $in_perfparse_traffic_str = sprintf("%.1f",abs($in_perfparse_traffic));
printf("Total RX Bits In : %.2f ".$in_bits_unit."B, Out : %.2f ".$out_bits_unit."b", $in_bits, $out_bits); my $out_perfparse_traffic_str = sprintf("%.1f",abs($out_perfparse_traffic));
printf("|traffic_in=".$in_perfparse_traffic_str."Bits/s traffic_out=".$out_perfparse_traffic_str."Bits/s\n");
exit($ERRORS{$status}); $in_perfparse_traffic_str =~ s/\./,/g;
$out_perfparse_traffic_str =~ s/\./,/g;
sub print_usage () {
print "\nUsage:\n"; my $status = "OK";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n"; if(($in_usage > $warning) or ($out_usage > $warning)){
print " -C (--community) SNMP read community (defaults to public,\n"; $status = "WARNING";
print " used with SNMP v1 and v2c\n"; }
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n"; if (($in_usage > $critical) or ($out_usage > $critical)){
print " -s (--show) Describes all interfaces number (debug mode)\n"; $status = "CRITICAL";
print " -i (--interface) Set the interface number (2 by default)\n"; }
print " -n (--name) Allows to use interface name with option -d instead of interface oid index\n";
print " (ex: -i \"eth0\" -n, -i \"VMware Virtual Ethernet Adapter for VMnet8\" -n\n";
print " (choose an unique expression for each interface)\n"; printf("Traffic In : %.2f ".$in_prefix."b/s (".$in_usage." %%), Out : %.2f ".$out_prefix."b/s (".$out_usage." %%) - ", $in_traffic, $out_traffic);
print " -w (--warn) Signal strength at which a warning message will be generated\n"; printf("Total RX Bits In : %.2f ".$in_bits_unit."B, Out : %.2f ".$out_bits_unit."b", $in_bits, $out_bits);
print " (default 80)\n"; printf("|traffic_in=".$in_perfparse_traffic_str."Bits/s traffic_out=".$out_perfparse_traffic_str."Bits/s\n");
print " -c (--crit) Signal strength at which a critical message will be generated\n"; exit($ERRORS{$status});
print " -T Max Banwidth\n";
print " (default 95)\n"; sub print_usage () {
print " -V (--version) Plugin version\n"; print "\nUsage:\n";
print " -h (--help) usage help\n"; print "$PROGNAME\n";
} print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
sub print_help () { print " used with SNMP v1 and v2c\n";
print "######################################################\n"; print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n"; print " 2 for SNMP v2c\n";
print "# Bugs to http://www.oreon-project.org/ #\n"; print " -s (--show) Describes all interfaces number (debug mode)\n";
print "######################################################\n"; print " -i (--interface) Set the interface number (2 by default)\n";
print_usage(); print " -n (--name) Allows to use interface name with option -d instead of interface oid index\n";
print "\n"; print " (ex: -i \"eth0\" -n, -i \"VMware Virtual Ethernet Adapter for VMnet8\" -n\n";
} print " (choose an unique expression for each interface)\n";
print " -w (--warn) Signal strength at which a warning message will be generated\n";
print " (default 80)\n";
print " -c (--crit) Signal strength at which a critical message will be generated\n";
print " -T Max Banwidth\n";
print " (default 95)\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "######################################################\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "######################################################\n";
print_usage();
print "\n";
}