summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-01-11 04:05:57 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-11 04:05:57 +0100
commit61dc6720867b17adbf0b58d53723e082a7193115 (patch)
treea66438fd330733df293f3e4f34f4cd3f49bdbb25
parent65acfdc8b408dad17779fc686b14b3532e55476c (diff)
downloadnet_if-61dc6720867b17adbf0b58d53723e082a7193115.tar.gz
net_if-61dc6720867b17adbf0b58d53723e082a7193115.tar.bz2
net_if-61dc6720867b17adbf0b58d53723e082a7193115.zip
allways print performance data (even on WARNING or CRITICAL)
-rwxr-xr-xnet_if54
1 files changed, 43 insertions, 11 deletions
diff --git a/net_if b/net_if
index 265ad80..6f25770 100755
--- a/net_if
+++ b/net_if
@@ -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");