From dd431157057e9594008e55310ef33c25e9ea0a55 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Tue, 29 Apr 2008 13:01:57 +0000 Subject: [PATCH] [project @ peter@palfrader.org-20080429130157-1bm1hy9fy9no2y19] A raid check for master --- dsa-nagios-nrpe-config/debian/changelog | 6 ++ dsa-nagios-nrpe-config/debian/rules | 1 + dsa-nagios-nrpe-config/dsa-check-raid-mpt | 70 +++++++++++++++++++++++ nagios-master.cfg | 6 ++ 4 files changed, 83 insertions(+) create mode 100755 dsa-nagios-nrpe-config/dsa-check-raid-mpt diff --git a/dsa-nagios-nrpe-config/debian/changelog b/dsa-nagios-nrpe-config/debian/changelog index 57055c2..c089d2c 100644 --- a/dsa-nagios-nrpe-config/debian/changelog +++ b/dsa-nagios-nrpe-config/debian/changelog @@ -1,3 +1,9 @@ +dsa-nagios-nrpe-config (35) unstable; urgency=low + + * dsa-check-raid-mpt + + -- Peter Palfrader Tue, 29 Apr 2008 12:57:50 +0000 + dsa-nagios-nrpe-config (34) unstable; urgency=low * dsa-check-raid-3ware diff --git a/dsa-nagios-nrpe-config/debian/rules b/dsa-nagios-nrpe-config/debian/rules index 4e774a5..df8c8b0 100755 --- a/dsa-nagios-nrpe-config/debian/rules +++ b/dsa-nagios-nrpe-config/debian/rules @@ -15,6 +15,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-mpt $(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 diff --git a/dsa-nagios-nrpe-config/dsa-check-raid-mpt b/dsa-nagios-nrpe-config/dsa-check-raid-mpt new file mode 100755 index 0000000..5dd1155 --- /dev/null +++ b/dsa-nagios-nrpe-config/dsa-check-raid-mpt @@ -0,0 +1,70 @@ +#!/usr/bin/perl -Tw + +# Copyright (C) 2008 Peter Palfrader + +# Need to allow /usr/local/bin/tw_cli info c0 u0 status in sudoers: +# +# nagios ALL=(ALL) NOPASSWD: /usr/sbin/mpt-status -s +# + +use strict; +use English; +use Getopt::Long; + +$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin'; +delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; + +my $MPT_STATUS = '/usr/sbin/mpt-status'; + +# nagios exit codes +my $UNKNOWN = -1; +my $OK = 0; +my $WARNING = 1; +my $CRITICAL = 2; + +$SIG{'__DIE__'} = sub { + print STDERR @_; + exit $UNKNOWN; +}; + +unless (-e $MPT_STATUS) { + print "Cannot find '$MPT_STATUS'.\n"; + exit $UNKNOWN; +}; + +my $command = "sudo $MPT_STATUS -s"; +open (MPT, "$command|") or die ("Cannot run $command: $!\n"); +my @tw=; +close MPT; +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, $num, $status) = $line =~ m#^(vol_id|phys_id)\s+([0-9]+)\s+(.*)$#; + unless (defined($device) && defined($num) && defined($status)) { + print "Cannot parse line '$line'\n"; + exit $UNKNOWN; + }; + if ($status eq 'OPTIMAL' || + $status eq 'ONLINE') { + $msg .= ($msg eq '' ? '' : '; '). "$device $num: $status"; + $exit = $exit > $OK ? $exit : $OK; + } else { + $msg .= ($msg eq '' ? '' : '; '). "$device $num: $status"; + $exit = $exit > $CRITICAL ? $exit : $CRITICAL; + }; +}; + +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 7903356..1c9971c 100644 --- a/nagios-master.cfg +++ b/nagios-master.cfg @@ -1129,6 +1129,12 @@ services: servicegroups: raid nrpe: "/usr/lib/nagios/plugins/dsa-check-raid-3ware" hosts: puccini + ### + - + name: RAID - MPT + servicegroups: raid + nrpe: "/usr/lib/nagios/plugins/dsa-check-raid-mpt" + hosts: master ### - -- 2.20.1