diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-11 04:05:57 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-11 04:05:57 +0100 |
commit | 61dc6720867b17adbf0b58d53723e082a7193115 (patch) | |
tree | a66438fd330733df293f3e4f34f4cd3f49bdbb25 | |
parent | 65acfdc8b408dad17779fc686b14b3532e55476c (diff) | |
download | net_if-61dc6720867b17adbf0b58d53723e082a7193115.tar.gz net_if-61dc6720867b17adbf0b58d53723e082a7193115.tar.bz2 net_if-61dc6720867b17adbf0b58d53723e082a7193115.zip |
allways print performance data (even on WARNING or CRITICAL)
-rwxr-xr-x | net_if | 54 |
1 files changed, 43 insertions, 11 deletions
@@ -105,7 +105,9 @@ sub get_if_stats ($) { # nagios status code # additional message # interface statistics -sub print_stats ($) { +sub print_stats ($$$) { + my $status = shift; + my $msg = shift; my $stats = shift; my ($count, $perfdata); @@ -117,26 +119,56 @@ sub print_stats ($) { } } - msg('ok', "$count interfaces |$perfdata"); + msg($status, "$count interfaces$msg |$perfdata"); } +# This function generate a nagios status code and an additional +# message, based on the counts of the interfaces, that are down +# or does not exist. +# +# parameter: +# list of down interfaces +# list of interfaces, that does not exists +# returns: +# (status, msg) for nagios +sub get_status ($$) { + my $down = shift; + my $error = shift; + my ($status, $msg) = ('ok', ''); + + # Order matters! LAST MATCH WINS. + if (@$down) { + # Chech whether some interfaces are down and we have to + # issue a warning. + my $count = @$down; + $down = join ", ", @$down; + + $status = 'warn'; + $msg = ", $count interface(s) are down ($down)"; + } -my ($interfaces, $down, $error) = get_if_status(@ARGV); + if (@$error) { + # Chech whether some interface or interface group, specified + # on the command line, does not exists and we should return a + # critical error. + my $count = @$error; + $error = join ", ", @$error; -if (@$error) { - $error = join ", ", @$error; - msg('crit', "Some interfaces does not exists: $error"); -} + $status = 'crit'; + $msg = ", $count interface(s) does not exists ($error)"; + } -if (@$down) { - $down = join ", ", @$down; - msg('warn', "Some interfaces are down: $down"); + return ($status, $msg); } + +my ($interfaces, $down, $error) = get_if_status(@ARGV); +my ($status, $msg) = get_status($down, $error); + my $stats = {}; for my $if (@$interfaces) { $stats->{$if} = get_if_stats($if); } -print_stats($stats); +print_stats($status, $msg, $stats); msg('crit', "End of script"); |