From 24d7f0e5aaf2d3cba660d75c4f35e1b361dcfc05 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Thu, 24 Apr 2008 19:38:43 +0000 Subject: [PATCH] [project @ peter@palfrader.org-20080424193843-b2x3gvnxqe378ae8] A raid check for puccini --- dsa-nagios-nrpe-config/debian/changelog | 6 ++ dsa-nagios-nrpe-config/debian/copyright | 5 + dsa-nagios-nrpe-config/debian/rules | 1 + dsa-nagios-nrpe-config/dsa-check-raid-3ware | 111 ++++++++++++++++++++ nagios-master.cfg | 6 ++ 5 files changed, 129 insertions(+) create mode 100755 dsa-nagios-nrpe-config/dsa-check-raid-3ware diff --git a/dsa-nagios-nrpe-config/debian/changelog b/dsa-nagios-nrpe-config/debian/changelog index 7ce96e7..57055c2 100644 --- a/dsa-nagios-nrpe-config/debian/changelog +++ b/dsa-nagios-nrpe-config/debian/changelog @@ -1,3 +1,9 @@ +dsa-nagios-nrpe-config (34) unstable; urgency=low + + * dsa-check-raid-3ware + + -- Peter Palfrader Thu, 24 Apr 2008 19:37:47 +0000 + dsa-nagios-nrpe-config (33) unstable; urgency=low * Add dsa-check-raid-dac960 diff --git a/dsa-nagios-nrpe-config/debian/copyright b/dsa-nagios-nrpe-config/debian/copyright index 47cb89b..59e2523 100644 --- a/dsa-nagios-nrpe-config/debian/copyright +++ b/dsa-nagios-nrpe-config/debian/copyright @@ -17,3 +17,8 @@ dsa-check-dabackup: Copyright: 2007 Stephen Gran Copyright: 2008 Peter Palfrader License: MIT + +######################################################################## +dsa-check-raid-3ware + Copyright: 2006 Peter Palfrader + License: MIT diff --git a/dsa-nagios-nrpe-config/debian/rules b/dsa-nagios-nrpe-config/debian/rules index 1ab4ab4..4e774a5 100755 --- a/dsa-nagios-nrpe-config/debian/rules +++ b/dsa-nagios-nrpe-config/debian/rules @@ -16,6 +16,7 @@ install: install -m 644 nrpe_dsa.cfg $(CURDIR)/debian/dsa-nagios-nrpe-config/etc/nagios install -m 755 dsa-check-raid-dac960 $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-raid-sw $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins + install -m 755 dsa-check-raid-3ware $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-da-in-aliases $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-dabackup $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-udldap-freshness $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins diff --git a/dsa-nagios-nrpe-config/dsa-check-raid-3ware b/dsa-nagios-nrpe-config/dsa-check-raid-3ware new file mode 100755 index 0000000..a9887b9 --- /dev/null +++ b/dsa-nagios-nrpe-config/dsa-check-raid-3ware @@ -0,0 +1,111 @@ +#!/usr/bin/perl -Tw + +# Copyright (C) 2006 Peter Palfrader + +# Need to allow /usr/local/bin/tw_cli info c0 u0 status in sudoers: +# +# nagios ALL=(ALL) NOPASSWD: /usr/local/bin/tw_cli info c0 u0 status +# + +use strict; +use English; +use Getopt::Long; + +$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin'; +delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; + +my $TW_CLI = '/usr/local/bin/tw_cli'; +my $SVN_REVISION_STRING = '$Rev: 313 $'; +my ($SVN_REVISION) = ($SVN_REVISION_STRING =~ /([0-9]+)/); + $SVN_REVISION = 'unknown' unless defined $SVN_REVISION; +my $VERSION = '0.0.0.'.$SVN_REVISION; + +# nagios exit codes +my $UNKNOWN = -1; +my $OK = 0; +my $WARNING = 1; +my $CRITICAL = 2; + +my $params = { + 'no-sudo' => 0, + 'controller' => 0, + 'unit' => 0 + }; + +Getopt::Long::config('bundling'); +if (!GetOptions ( + '--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] [--no-sudo] [--controller=] [--unit=]\n"); +}; +if ($params->{'help'}) { + print "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose] [--no-sudo] [--controller=] [--unit=]\n"; + print "Checks status of 3ware raid arrays.\n"; + exit (0); +}; +if ($params->{'version'}) { + print "nagios-check-raid-3ware $VERSION\n"; + print "nagios check for 3ware raids\n"; + print "Copyright (c) 2006 Peter Palfrader \n"; + exit (0); +}; + +$SIG{'__DIE__'} = sub { + print STDERR @_; + exit $UNKNOWN; +}; + +unless (-e $TW_CLI) { + print "Cannot find '$TW_CLI'.\n"; + exit $UNKNOWN; +}; + +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=; +close TW; +if ($CHILD_ERROR) { # program failed + die("$command returned with non-zero exit code: ".($CHILD_ERROR / 256)."\n"); +}; + + +my $exit = $UNKNOWN; +my $msg = ''; +for my $line (@tw) { + chomp $line; + next if $line =~ /^$/; + my ($device, $status) = $line =~ m#^(/c[0-9]+/u[0-9]+) status = ([A-Z]+)$#; + unless (defined($device) && defined($status)) { + print "Cannot parse line '$line'\n"; + exit $UNKNOWN; + }; + if ($status eq 'OK' || + $status eq 'VERIFYING') { + $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; + $exit = $exit > $OK ? $exit : $OK; + } elsif ($status eq 'DEGRADED') { + $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; + $exit = $exit > $CRITICAL ? $exit : $CRITICAL; + } elsif ($status eq 'OFFLINE') { + $msg .= ($msg eq '' ? '' : '; '). "$device: $status"; + $exit = $exit > $CRITICAL ? $exit : $CRITICAL; + } else { + $msg .= ($msg eq '' ? '' : '; '). "$device: UNKNOWN STATUS '$status'"; + $exit = $exit > $UNKNOWN ? $exit : $UNKNOWN; + }; +}; + +if ($msg eq '') { + $msg = "No devices found"; + die ("exit is not UNKNOWN but $exit") if ($exit != $UNKNOWN); +} + +print $msg,"\n"; +exit $exit; diff --git a/nagios-master.cfg b/nagios-master.cfg index 2273e09..3b5ffbe 100644 --- a/nagios-master.cfg +++ b/nagios-master.cfg @@ -1092,6 +1092,12 @@ services: servicegroups: raid nrpe: "/usr/lib/nagios/plugins/dsa-check-raid-dac960" hosts: verdi + ### + - + name: RAID - 3ware + servicegroups: raid + nrpe: "/usr/lib/nagios/plugins/dsa-check-raid-3ware" + hosts: puccini ### - -- 2.20.1