summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-01-14 04:06:56 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-14 04:06:56 +0100
commite9f416e431daf16c86f62b589fd0d98aef31d6c9 (patch)
tree4dd800c73f41c7b5dab780a873739587ce9ba750
parent61dc6720867b17adbf0b58d53723e082a7193115 (diff)
downloadnet_if-master.tar.gz
net_if-master.tar.bz2
net_if-master.zip
net_if: use Nagios::Plugin for outputHEADmaster
-rwxr-xr-xnet_if34
1 files changed, 8 insertions, 26 deletions
diff --git a/net_if b/net_if
index 6f25770..702de79 100755
--- a/net_if
+++ b/net_if
@@ -2,30 +2,12 @@
use warnings;
use strict;
+use Nagios::Plugin;
$ENV{'PATH'} = '/bin:/usr/bin:/sbin:/usr/sbin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
-# 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;
-}
+my $n = Nagios::Plugin->new;
# Check the status of the given network interface and return
# three lists of the interfaces sorted by status (all, down, error).
@@ -48,7 +30,7 @@ sub get_if_status (@) {
# necessary to pipe stderr of the child process away, while
# using the list syntax for open and exec.
my $pid = open(IFCONFIG, "-|");
- msg('crit', "fork: $!") unless defined $pid;
+ $n->nagois_exit(CRITICAL, "fork: $!") unless defined $pid;
if ($pid == 0) {
# redirect stderr
@@ -119,7 +101,7 @@ sub print_stats ($$$) {
}
}
- msg($status, "$count interfaces$msg |$perfdata");
+ $n->nagios_exit($status, "$count interfaces$msg |$perfdata");
}
# This function generate a nagios status code and an additional
@@ -134,7 +116,7 @@ sub print_stats ($$$) {
sub get_status ($$) {
my $down = shift;
my $error = shift;
- my ($status, $msg) = ('ok', '');
+ my ($status, $msg) = (OK, '');
# Order matters! LAST MATCH WINS.
if (@$down) {
@@ -143,7 +125,7 @@ sub get_status ($$) {
my $count = @$down;
$down = join ", ", @$down;
- $status = 'warn';
+ $status = WARNING;
$msg = ", $count interface(s) are down ($down)";
}
@@ -154,7 +136,7 @@ sub get_status ($$) {
my $count = @$error;
$error = join ", ", @$error;
- $status = 'crit';
+ $status = CRITICAL;
$msg = ", $count interface(s) does not exists ($error)";
}
@@ -171,4 +153,4 @@ for my $if (@$interfaces) {
}
print_stats($status, $msg, $stats);
-msg('crit', "End of script");
+$n->nagios_exit(CRITICAL, "End of script");