summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-01-10 21:50:47 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-10 21:50:47 +0100
commit3fbcb1be0ff7dd667a082990efc3ee4f22d622c2 (patch)
tree07352164eb59997400e55e0559fb6e2ce13830e4
parent730a4b5a2e490733f4734c87acf7ce064d1384fe (diff)
downloadnet_if-3fbcb1be0ff7dd667a082990efc3ee4f22d622c2.tar.gz
net_if-3fbcb1be0ff7dd667a082990efc3ee4f22d622c2.tar.bz2
net_if-3fbcb1be0ff7dd667a082990efc3ee4f22d622c2.zip
replace ok, warning, critical subs with generic msg sub
-rwxr-xr-xnet_if39
1 files changed, 22 insertions, 17 deletions
diff --git a/net_if b/net_if
index 3ca31a8..62d1dab 100755
--- a/net_if
+++ b/net_if
@@ -6,19 +6,24 @@ use strict;
$ENV{'PATH'} = '/bin:/usr/bin:/sbin:/usr/sbin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
-sub critical {
- print "CRITICAL - @_\n";
- exit 2;
-}
-
-sub warning {
- print "WARNING - @_\n";
- exit 1;
-}
-
-sub ok {
- print "OK - @_\n";
- exit 0;
+# define nagios status codes
+my %nagios = (
+ 'ok' => ["OK", 0],
+ 'warn' => ["WARNING", 1],
+ 'crit' => ["CRITICAL", 2],
+ 'unknown' => ["UNKNOWN", 3]
+);
+
+# Print nagios compatible status message and terminat script
+# with apropiate return code.
+#
+# parameter: type of message
+sub msg ($@) {
+ my $type = shift;
+ my ($msg, $exit) = @{$nagios{$type}};
+
+ print $msg, " - ", @_, "\n";
+ exit $exit;
}
sub get_if_status {
@@ -30,7 +35,7 @@ sub get_if_status {
$if = $1;
my $pid = open(IFCONFIG, "-|");
- die "$0: fork: $!" unless defined $pid;
+ msg('crit', "fork: $!") unless defined $pid;
if ($pid == 0) {
# child
@@ -92,19 +97,19 @@ sub print_stats {
}
}
- ok("$count interfaces |$perfdata");
+ msg('ok', "$count interfaces |$perfdata");
}
my ($up, $down, $error) = get_if_status(@ARGV);
if (@$error) {
$error = join ", ", @$error;
- critical("Some interfaces does not exists: $error");
+ msg('crit', "Some interfaces does not exists: $error");
}
if (@$down) {
$down = join ", ", @$down;
- warning("Some interfaces are down: $down");
+ msg('warn', "Some interfaces are down: $down");
}
my $stats = {};