3 # Copyright (C) 2008 Peter Palfrader <peter@palfrader.org>
5 # Need to allow /usr/local/bin/tw_cli info c0 u0 status in sudoers:
7 # nagios ALL=(ALL) NOPASSWD: /usr/sbin/mpt-status -s
14 $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin';
15 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
17 my $MPT_STATUS = '/usr/sbin/mpt-status';
25 $SIG{'__DIE__'} = sub {
30 unless (-e $MPT_STATUS) {
31 print "Cannot find '$MPT_STATUS'.\n";
35 my $command = "sudo $MPT_STATUS -s";
36 open (MPT, "$command|") or die ("Cannot run $command: $!\n");
40 my $command_exitcode = $CHILD_ERROR;
46 next if $line =~ /^$/;
47 my ($device, $num, $status) = $line =~ m/^(log_id|vol_id|phys_id)\s+([0-9]+)\s+(.*)$/;
48 unless (defined($device) && defined($num) && defined($status)) {
49 print "Cannot parse line '$line'\n";
52 if ($status eq 'OPTIMAL' ||
53 $status eq 'ONLINE') {
54 $msg .= ($msg eq '' ? '' : '; '). "$device $num: $status";
55 $exit = $exit > $OK ? $exit : $OK;
57 $msg .= ($msg eq '' ? '' : '; '). "$device $num: $status";
58 $exit = $exit > $CRITICAL ? $exit : $CRITICAL;
63 $msg = "No devices found";
64 die ("exit is not UNKNOWN but $exit") if ($exit != $UNKNOWN);
67 if ($command_exitcode && ($exit == $OK || $exit == $UNKNOWN)) {
69 $msg .= ($msg eq '' ? '' : '; '). "$command returned with non-zero exit code: ".($command_exitcode / 256);