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");
39 if ($CHILD_ERROR) { # program failed
40 die("$command returned with non-zero exit code: ".($CHILD_ERROR / 256)."\n");
48 next if $line =~ /^$/;
49 my ($device, $num, $status) = $line =~ m#^(log_id|vol_id|phys_id)\s+([0-9]+)\s+(.*)$#;
50 unless (defined($device) && defined($num) && defined($status)) {
51 print "Cannot parse line '$line'\n";
54 if ($status eq 'OPTIMAL' ||
55 $status eq 'ONLINE') {
56 $msg .= ($msg eq '' ? '' : '; '). "$device $num: $status";
57 $exit = $exit > $OK ? $exit : $OK;
59 $msg .= ($msg eq '' ? '' : '; '). "$device $num: $status";
60 $exit = $exit > $CRITICAL ? $exit : $CRITICAL;
65 $msg = "No devices found";
66 die ("exit is not UNKNOWN but $exit") if ($exit != $UNKNOWN);