From 778467a6e7afae14541f0cbdf7fff70f8547de85 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 15 Feb 2006 00:06:11 +0000 Subject: Minor updates to raid 3ware git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@58 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- nagios-check-raid-3ware | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'nagios-check-raid-3ware') diff --git a/nagios-check-raid-3ware b/nagios-check-raid-3ware index 4a37fc0..6073a78 100755 --- a/nagios-check-raid-3ware +++ b/nagios-check-raid-3ware @@ -14,7 +14,7 @@ use Getopt::Long; $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; -my $TW_CLI = 'sudo /usr/local/bin/tw_cli'; +my $TW_CLI = '/usr/local/bin/tw_cli'; my $VERSION = '0.0.0'; # nagios exit codes @@ -24,29 +24,31 @@ my $WARNING = 1; my $CRITICAL = 2; my $params = { - controller => 0, - unit => 0 + 'no-sudo' => 0, + 'controller' => 0, + 'unit' => 0 }; Getopt::Long::config('bundling'); if (!GetOptions ( - '--help' => \$params->{'help'}, - '--version' => \$params->{'version'}, - '--verbose' => \$params->{'verbose'}, - '--controller' => \$params->{'controller'}, - '--unit' => \$params->{'unit'}, + '--help' => \$params->{'help'}, + '--version' => \$params->{'version'}, + '--verbose' => \$params->{'verbose'}, + '--controller=i' => \$params->{'controller'}, + '--unit=i' => \$params->{'unit'}, + '--no-sudo' => \$params->{'no-sudo'}, )) { - die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose]\n"); + die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose] [--no-sudo] [--controller=] [--unit=]\n"); }; if ($params->{'help'}) { - print "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose]\n"; + print "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose] [--no-sudo] [--controller=] [--unit=]\n"; print "Reports processes that are linked against libraries that no longer exist.\n"; exit (0); }; if ($params->{'version'}) { - print "nagios-check-libs $VERSION\n"; - print "nagios check for availability of debian (security) updates\n"; - print "Copyright (c) 2005 Peter Palfrader \n"; + print "nagios-check-raid-3ware $VERSION\n"; + print "nagios check for 3ware raids\n"; + print "Copyright (c) 2006 Peter Palfrader \n"; exit (0); }; @@ -55,8 +57,13 @@ $SIG{'__DIE__'} = sub { exit $UNKNOWN; }; +unless (-x $TW_CLI) { + print "Cannot find '$TW_CLI'.\n"; + exit $UNKNOWN; +}; -my $command = "$TW_CLI info c$params->{'controller'} u$params->{'unit'} status"; +my $sudo = $params->{'no-sudo'} ? '' : 'sudo '; +my $command = "$sudo $TW_CLI info c$params->{'controller'} u$params->{'unit'} status"; print STDERR "Running $command\n" if $params->{'verbose'}; open (TW, "$command|") or die ("Cannot run $command: $!\n"); my @tw=; @@ -77,16 +84,16 @@ for my $line (@tw) { exit $UNKNOWN; }; if ($status eq 'OK') { - $msg .= "$device: $status; "; + $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; $exit = $exit > $OK ? $exit : $OK; } elsif ($status eq 'DEGRADED') { - $msg .= "$device: $status; "; + $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; $exit = $exit > $CRITICAL ? $exit : $CRITICAL; } elsif ($status eq 'OFFLINE') { - $msg .= "$device: $status; "; + $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; $exit = $exit > $CRITICAL ? $exit : $CRITICAL; } else { - $msg .= "$device: UKNOWN STATUS '$status'; "; + $msg .= ($msg eq '' ? '' : '; '). "$device: UKNOWN STATUS '$status'"; $exit = $exit > $UNKNOWN ? $exit : $UNKNOWN; }; }; -- cgit v1.2.3