3 # Copyright (C) 2008 Peter Palfrader <peter@palfrader.org>
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 # Need to allow /usr/local/bin/tw_cli info c0 u0 status in sudoers:
26 # nagios ALL=(ALL) NOPASSWD: /usr/sbin/mpt-status -s
33 $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin';
34 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
36 my $MPT_STATUS = '/usr/sbin/mpt-status';
44 $SIG{'__DIE__'} = sub {
49 unless (-e $MPT_STATUS) {
50 print "Cannot find '$MPT_STATUS'.\n";
54 my $command = "sudo $MPT_STATUS -s";
55 open (MPT, "$command|") or die ("Cannot run $command: $!\n");
59 my $command_exitcode = $CHILD_ERROR;
65 next if $line =~ /^$/;
66 my ($device, $num, $status) = $line =~ m/^(log_id|vol_id|phys_id)\s+([0-9]+)\s+(.*)$/;
67 unless (defined($device) && defined($num) && defined($status)) {
68 print "Cannot parse line '$line'\n";
71 if ($status eq 'OPTIMAL' ||
72 $status eq 'ONLINE') {
73 $msg .= ($msg eq '' ? '' : '; '). "$device $num: $status";
74 $exit = $exit > $OK ? $exit : $OK;
76 $msg .= ($msg eq '' ? '' : '; '). "$device $num: $status";
77 $exit = $exit > $CRITICAL ? $exit : $CRITICAL;
82 $msg = "No devices found";
83 die ("exit is not UNKNOWN but $exit") if ($exit != $UNKNOWN);
86 if ($command_exitcode && ($exit == $OK || $exit == $UNKNOWN)) {
88 $msg .= ($msg eq '' ? '' : '; '). "$command returned with non-zero exit code: ".($command_exitcode / 256);