Initial revision
[manu/check_lsiutil.git] / check_lsiutil
1 #!/usr/bin/perl -w
2 # Nagios plugin that checks LSI controllers RAID status via lsiutil program
3 # lsiutil may be found at ftp://ftp.lsil.com/HostAdapterDrivers/linux/lsiutil/
4
5 # Copyright (C) 2011 Emmanuel Lacour <elacour@home-dn.net>
6 #
7 # This file is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2, or (at your option) any
10 # later version.
11 #
12 # This file is distributed in the hope that it will be
13 # useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this file; see the file COPYING.  If not, write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21
22 use strict;
23 use lib qw(/usr/local/lib/nagios/plugins /usr/lib/nagios/plugins);
24 use utils qw(%ERRORS);
25
26 my $lsiutil = '/usr/sbin/lsiutil';
27 my $status = $ERRORS{'OK'};
28 my $output;
29 my @controllers;
30
31 unless ( -x $lsiutil ) {
32     print "$lsiutil not found or not executable\n";
33     exit ($ERRORS{'UNKNOWN'});
34 }
35
36 unless ( $> == 0 ) {
37     print "This program must be run as root. You may use wrappers like sudo to do this.\n";
38     exit ($ERRORS{'UNKNOWN'});
39 }
40
41 $output = `$lsiutil -p 0 -a 0`;
42 for (split /^/, $output) {
43     if ( m|^\s*(\d+)\..*/proc/mpt/ioc| ) {
44         push @controllers, $1;
45     }
46 }
47
48 unless ( scalar @controllers ) {
49     print "No controller found\n";
50     exit ($ERRORS{'UNKNOWN'});
51 }
52
53 foreach my $controller ( @controllers ) {
54     my @volumes;
55     $output = `$lsiutil -p $controller -a 21,3,0,0`;
56     for (split /^/, $output) {
57         chomp();
58         if ( m/^Volume.*State/ ) {
59             push @volumes, $_;
60         }
61     }
62     unless ( scalar @volumes ) {
63         push @volumes, "No volume found";
64     } else {
65         foreach my $volume_status ( @volumes ) {
66             $status = $ERRORS{'CRITICAL'} unless ( $volume_status =~ /^Volume \d+ State:  optimal, enabled$/ );
67         }
68     }
69     print "Ctrl $controller: ".join (' / ', @volumes)."\n";
70 }
71
72 exit ($status);
73