# 2010-01-05 # Patch from Stuijn Gruwier stijn . gruwier at gmail . com # # Problem and Solution: # My only problem with this was that there is a global paramater (bandwidth) for # both up and download, so on an asymmetric line I didn't get warnings when the # upload was saturated. To solve this I've replaced the -b option for maximum # bandwidth with two options, one for maximum incoming (-I) and one for maximum # outgoing (-O) bandwidth. # --- check_iftraffic.pl 2010-01-06 09:38:03.463625309 +0100 +++ check_iftraffic.pl.1 2010-01-06 09:37:24.713515958 +0100 @@ -5,6 +5,9 @@ # Copyright (C) 2004 Gerd Mueller / Netways GmbH # Copyright (C) 2006,2007,2009 Herbert Straub # +# 2010-01-05 Stijn Gruwier +# - Replaced -b option with -O and -I for separete maximum bandwidth levels +# for incoming and outgoing traffic. Usefull for asymetric lines. # 2007-01-09 Herbert Straub # - correct Performance output with warn and critical (% and absolut) # 2006-10-01 Herbert Straub @@ -68,7 +71,8 @@ my $host_address; my $iface_number; my $iface_descr; -my $iface_speed; +my $iface_speed_in; +my $iface_speed_out; my ( $opt_h, $opt_license, $opt_version ); my $units; my ( $snmpIfInOctets, $snmpIfOutOctets ); @@ -95,7 +99,8 @@ my ( $in_bytes, $out_bytes ) = 0; my $warn_usage = 85; my $crit_usage = 98; -my ($warn_abs, $crit_abs); +my ($warn_abs_in, $crit_abs_in); +my ($warn_abs_out, $crit_abs_out); my $COMMUNITY = "public"; my $max_value; my $max_bytes; @@ -107,7 +112,9 @@ "s|snmp_version=s"=> \$snmp_version, "w|warning=s" => \$warn_usage, "c|critical=s" => \$crit_usage, - "b|bandwidth=i" => \$iface_speed, +# "b|bandwidth=i" => \$iface_speed, + "I|bandwidth_in=i" => \$iface_speed_in, + "O|bandwidth_out=i" => \$iface_speed_out, "p|port=i" => \$port, "u|units=s" => \$units, "i|interface=s" => \$iface_descr, @@ -133,7 +140,7 @@ exit $STATUS_CODE{"OK"}; } -if ( ( !$host_address ) or ( !$iface_descr ) or ( !$iface_speed ) ) { +if ( ( !$host_address ) or ( !$iface_descr ) or ( !$iface_speed_in ) or ( !$iface_speed_out ) ) { print_usage(); } @@ -177,7 +184,9 @@ $traffic_file=$DEF_DIR.$TRAFFIC_FILE; } -$iface_speed = bits2bytes( $iface_speed, $units ); +$iface_speed_in = bits2bytes( $iface_speed_in, $units ); +$iface_speed_out = bits2bytes( $iface_speed_out, $units ); + if ( !$max_value ) { #if no -M Parameter was set, set it to 32Bit Overflow $max_bytes = 4194304; # the value is (2^32/1024) @@ -235,8 +244,8 @@ my $in_traffic_absolut = sprintf( "%.0f", $last_in_bytes ); my $out_traffic_absolut = sprintf( "%.0f", $last_out_bytes ); -my $in_usage = sprintf( "%.1f", ( 1.0 * $in_traffic * 100 ) / $iface_speed ); -my $out_usage = sprintf( "%.1f", ( 1.0 * $out_traffic * 100 ) / $iface_speed ); +my $in_usage = sprintf( "%.1f", ( 1.0 * $in_traffic * 100 ) / $iface_speed_in ); +my $out_usage = sprintf( "%.1f", ( 1.0 * $out_traffic * 100 ) / $iface_speed_out ); $in_bytes = sprintf( "%.2f", $in_bytes); $out_bytes = sprintf( "%.2f", $out_bytes); @@ -266,12 +275,16 @@ $output .= "
$exit_status bandwidth utilization." if ( $exit_status ne "OK" ); -$warn_abs=sprintf("%.0f", $iface_speed/100*$warn_usage); -$crit_abs=sprintf("%.0f",$iface_speed/100*$crit_usage); +$warn_abs_in=sprintf("%.0f",$iface_speed_in/100*$warn_usage); +$crit_abs_in=sprintf("%.0f",$iface_speed_in/100*$crit_usage); + +$warn_abs_out=sprintf("%.0f",$iface_speed_out/100*$warn_usage); +$crit_abs_out=sprintf("%.0f",$iface_speed_out/100*$crit_usage); + $output .= "|inUsage=$in_usage%;$warn_usage;$crit_usage;; outUsage=$out_usage%;$warn_usage;$crit_usage;; " - . "inAbsolut=".$in_traffic_absolut."B;$warn_abs;$crit_abs;; " - . "outAbsolut=".$out_traffic_absolut."B;$warn_abs;$crit_abs;;\n"; + . "inAbsolut=".$in_traffic_absolut."B;$warn_abs_in;$crit_abs_in;; " + . "outAbsolut=".$out_traffic_absolut."B;$warn_abs_out;$crit_abs_out;;\n"; print $output; exit( $STATUS_CODE{$exit_status} );