diff --git a/stat_net.pl b/stat_net.pl deleted file mode 100644 index 2707cb0..0000000 --- a/stat_net.pl +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/perl -w - -################################################ -# -# Checks the net-stat (only for status). -# - warning state only for to much percent of errs or drop packages -# - unknown is for unknown device -# -# Thomas Sesselmann 2010 -# -# 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 3 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, see . -# -# -# Changelog: -# v0.10 2018.02.16 (Snel.com - Yavuz Aydin) Added -d flag for devices argument -# v0.9 2010.10.22 (ts) -# -#### - -use Getopt::Long; -&Getopt::Long::config('bundling'); - -my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); -my $help = 0; -my $warn = "10"; -my $proc_net_file = "/proc/net/dev"; -my %devices = (); -my $arg_devices = undef; - -my $status = GetOptions( - "h|help|?" => \$help, - "w=i" => \$warn, - "d|devices=s" => \$arg_devices -); - -&print_usage() if $help; - -if ( defined($arg_devices) ) { - foreach my $device ( split ' ', $arg_devices ) { - $devices{$device}=0; - } -} else { - $devices{all}=0; -} - -&test_net(); - -##################################################### - -sub test_net() { - - my $return_txt=''; - my $perfdata=''; - my $status = 'OK'; - - open FILE,"<$proc_net_file"; - while() { - chomp $_; - if ($_ =~ /^\s*(\w+):(.*)$/){ - my $key = lc $1; - if(( exists $devices{all} )or( exists $devices{$key} )) { - $devices{$key}=$2; - } - } - } - close FILE; - - foreach my $k ( sort keys %devices ) { - if ( $k eq "all" ) { next; } - - if ( $devices{$k} eq "0" ) { - $status = 'UNKNOWN'; - if ( $return_txt ne "" ) { $return_txt .= ", " } - $return_txt .= "$k=(-/-)"; - next; - } - - my @val = split " ",$devices{$k}; - my $rx = $val[0]; - my $tx = $val[8]; - - my $rx_pkg = $val[1]; - my $tx_pkg = $val[9]; - - $perfdata .= "${k}_in=${rx}c; "; #In Bytes (Counter) - $perfdata .= "${k}_out=${tx}c; "; #Out Bytes (Counter) - - ## calculate dops and errors to percent - if ( ( ($val[2]+$val[3]) * 100 > $warn * $rx_pkg ) or - ( ($val[10]+$val[11]) * 100 > $warn * $tx_pkg ) ) { - if ( $ERRORS{$status} < $ERRORS{'WARNING'} ) { $status ='WARNING'; } - } - - my $rx_unit = "B"; - if ( $rx > 1024 * 4 ) { $rx /= 1024; $rx_unit="kB"; } - if ( $rx > 1024 * 4 ) { $rx /= 1024; $rx_unit="MB"; } - if ( $rx > 1024 * 4 ) { $rx /= 1024; $rx_unit="GB"; } - if ( $rx > 1024 * 4 ) { $rx /= 1024; $rx_unit="TB"; } - - my $tx_unit = "B"; - if ( $tx > 1024 * 4 ) { $tx /= 1024; $tx_unit="kB"; } - if ( $tx > 1024 * 4 ) { $tx /= 1024; $tx_unit="MB"; } - if ( $tx > 1024 * 4 ) { $tx /= 1024; $tx_unit="GB"; } - if ( $tx > 1024 * 4 ) { $tx /= 1024; $tx_unit="TB"; } - - if ( $return_txt ne "" ) { $return_txt .= ", " } - $return_txt .= sprintf "$k=(%.1f$rx_unit/%.1f$tx_unit)",$rx,$tx; - - } - - $return_txt = "NET $status - (Rx/Tx) $return_txt|$perfdata\n"; - &print_exit($return_txt,$ERRORS{$status}); -} - -sub print_usage() { - print "Usage: $0 [-w ] -d [devices]*\n"; - exit $ERRORS{'UNKNOWN'}; -} - -sub print_exit() { - my $msg = shift; - my $return_code = shift; - - print "$msg"; - exit $return_code; -} - - -__END__ -