2 # Nagios plugin that checks LSI SAS2 controllers RAID status via sas2ircu
5 # Copyright (C) 2011 Emmanuel Lacour <elacour@home-dn.net>
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
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.
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
25 use lib qw(/usr/local/lib/nagios/plugins /usr/lib/nagios/plugins);
26 use utils qw(%ERRORS);
28 my $sas2ircu = '/usr/sbin/sas2ircu';
29 my $status = $ERRORS{'OK'};
33 unless ( -x $sas2ircu ) {
34 print "$sas2ircu not found or not executable\n";
35 exit ($ERRORS{'UNKNOWN'});
39 print "This program must be run as root. You may use wrappers like sudo to do this.\n";
40 exit ($ERRORS{'UNKNOWN'});
43 foreach my $line (split /\n/, `$sas2ircu LIST`) {
44 if ( $line =~ /^\s+(\d+)\s+(.+)\s+(.+)\s+(.+)\s+(.+)\s+(.+)\s+(.+)\s*$/ ) {
47 $controllers{$ctrl_id}{type} = $ctrl_type;
51 unless ( scalar keys %controllers ) {
52 print "No controller found\n";
53 exit ($ERRORS{'UNKNOWN'});
56 foreach my $ctrl_id (keys %controllers) {
57 my $infos = `$sas2ircu $ctrl_id DISPLAY`;
61 foreach my $line (split /\n/, $infos) {
63 if ( $line =~ /^Controller information/ ) {
67 next unless ( $ctrl_start );
68 if ( $line =~ /^-/ && $ctrl_start == 1 ) {
72 if ( $line =~ /^-/ && $ctrl_start == 2 ) {
76 next unless ( $ctrl_start == 2 );
77 if ( $line =~ /^\s*(.*)\s+:\s+(.*)$/ ) {
84 $ctrl_infos{$key} = $value;
90 my $volume_id = undef;
91 foreach my $line (split /\n/, $infos) {
93 if ( $line =~ /^IR volume (\d+)\s*$/ ) {
97 if ( defined($volume_id) && $line =~ /^\s*$/ ) {
101 next unless ( defined($volume_id) );
102 if ( $line =~ /^\s*(.*)\s+:\s+(.*)\s*$/ ) {
109 if ( $key =~ /^PHY/ ) {
110 push @{$volumes_infos{$volume_id}{'disks'}}, $value;
112 $volumes_infos{$volume_id}{$key} = $value;
117 unless ( scalar keys %volumes_infos ) {
118 print "\tNo volume found\n";
125 my $disk_encl = undef;
126 my $disk_slot = undef;
127 foreach my $line (split /\n/, $infos) {
129 if ( $line =~ /^Device is a Hard disk/ ) {
133 if ( $disk_start && $line =~ /^\s*$/ ) {
139 next unless ( $disk_start );
140 if ( $line =~ /^\s*(.*)\s+:\s+(.*)\s*$/ ) {
147 if ( $key eq 'Enclosure #' ) {
151 if ( $key eq 'Slot #' ) {
155 if ( defined($disk_encl) && defined($disk_slot) ) {
156 $disks_infos{$disk_encl.':'.$disk_slot}{$key} = $value;
161 foreach my $volume_id (keys %volumes_infos) {
162 unless ( $volumes_infos{$volume_id}{'Status of volume'} eq 'Okay (OKY)' ) {
163 $errors_message .= "Ctrl $ctrl_id: vol $volume_id ".$volumes_infos{$volume_id}{'Status of volume'};
164 $status = $ERRORS{'CRITICAL'} unless ( $volumes_infos{$volume_id}{'Status of volume'} eq 'Okay (OKY)' );
167 unless ( scalar @{$volumes_infos{$volume_id}{disks}} ) {
168 # FIXME is this critical, can this happens ?
172 foreach my $disk (@{$volumes_infos{$volume_id}{disks}}) {
173 unless ( $disks_infos{$disk} ) {
174 $errors_message .= ", disk $disk not found!";
175 $status = $ERRORS{'CRITICAL'};
178 unless ( $disks_infos{$disk}{'State'} eq 'Optimal (OPT)' ) {
179 $errors_message .= ", disk: ".$disk." : ".$disks_infos{$disk}{'State'};
180 $status = $ERRORS{'CRITICAL'} unless ( $disks_infos{$disk}{'State'} eq 'Optimal (OPT)' );
186 if ( $status == $ERRORS{'OK'} ) {
187 print "All arrays OK\n";
188 } elsif ( $errors_message ) {
189 print "$errors_message\n";