X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=dsa-nagios-nrpe-config%2Fdsa-check-hpacucli;h=ce0910e8760882c12c42e516198827195544ceeb;hb=69c98599490554a640c63013cd34b02ab071b6d8;hp=26a07fe1ed20345c4643628b269ee0c0c4103169;hpb=b0ceaa02d8c75566bd1f82a687690a0db7c5781c;p=mirror%2Fdsa-nagios.git diff --git a/dsa-nagios-nrpe-config/dsa-check-hpacucli b/dsa-nagios-nrpe-config/dsa-check-hpacucli index 26a07fe..ce0910e 100755 --- a/dsa-nagios-nrpe-config/dsa-check-hpacucli +++ b/dsa-nagios-nrpe-config/dsa-check-hpacucli @@ -84,32 +84,100 @@ my @resultstr; for my $slot (sort @controllers) { my $pds = runcmd("controller slot=$slot pd all show"); + my @drives; my $nodrives = 0; my %status; for (@$pds) { chomp; next if /^$/; - next if /^ *array [A-Z]$/; next if (/^\S.*in Slot $slot/); - if (/^Error: The specified controller does not have any physical drives on it.$/) { + next if /^ *array [A-Z]$/; + if (/^ *(array [A-Z]) \(Failed\)$/) { + record('CRITICAL'); + push @{$status{'Failed'}}, $1; + } elsif (/^Error: The specified controller does not have any physical drives on it.$/) { $nodrives = 1; - } elsif (/^ *physicaldrive (\S+) .* (OK|Predictive Failure|Failed)(?:, spare)?\)$/) { + } elsif (/^ *physicaldrive (\S+) .* (OK|Predictive Failure|Failed|Rebuilding)(?:, spare)?\)$/) { my $drive = $1; my $status = $2; push @{$status{$status}}, $drive; if ($status eq 'OK') { - } elsif ($status eq 'Predictive Failure') { + } elsif ($status eq 'Predictive Failure' || + $status eq 'Rebuilding') { record('WARNING'); } elsif ($status eq 'Failed') { record('CRITICAL'); } else { record('UNKNOWN'); }; + push @drives, $drive; } else { die ("Cannot read line '$_' gotten from hpacucli controller slot=$slot pd all show\n"); }; }; + # Check that all drives have the proper transfer speed. + # sometimes stuff breaks and they fall back to 10mb/sec. + for my $drive (@drives) { + # skip drives that are known to have failed + next if (exists $status{'Failed'} && grep {$drive eq $_} @{$status{'Failed'}}); + my $type; + if ($drive =~ /^[0-9]+:[0-9]+$/) { # scsi drives + $type = 'SCSI'; + } elsif ($drive =~ /^[0-9]+I:[0-9]+:[0-9]+$/) { # SAS + $type = 'SAS'; + } else { + # I'm not going to run pass arguments of unknown form to the shell.. + warn ("Unknown diskdrive ID $drive\n"); + next; + } + + my $pd = runcmd("controller slot=$slot pd $drive show"); + while (defined $pd->[0] && !($pd->[0] =~ /physicaldrive/)) { + shift @$pd; + }; + shift @$pd; + my %value; + for (@$pd) { + if (m/^\s*(.*?):\s*(.*?)\s*$/) { + $value{$1} = $2; + } + } + + my $key; + my $expected; + if ($type eq 'SCSI') { + $key = 'Transfer Speed'; + if (!defined $value{'Transfer Mode'}) { + record('WARNING'); + push @{$status{'unknown transfer mode'}}, $drive; + next; + } elsif ($value{'Transfer Mode'} eq 'Ultra 3 Wide') { + $expected = '160 MB/Sec'; + } elsif ($value{'Transfer Mode'} eq 'Ultra 320 Wide') { + $expected = '320 MB/Sec'; + } else { + record('WARNING'); + push @{$status{'unknown transfer mode'}}, $drive."(".$value{'Transfer Mode'}.")"; + next; + }; + } elsif ($type eq 'SAS') { + $key = 'PHY Transfer Rate'; + $expected = '3.0GBPS'; + } else { + warn "Should not be here. Do not know what to do with type '$type'\n"; + next; + } + + if (!defined $value{$key}) { + record('WARNING'); + push @{$status{'unknown transfer speed'}}, $drive; + } elsif ($value{$key} ne $expected) { + record('WARNING'); + push @{$status{'bad transfer speed'}}, $drive."(".$value{$key}.")"; + }; + }; + if ($nodrives && scalar keys %status > 0) { push @resultstr, "Slot $slot: have no drives but status results?"; record('UNKNOWN'); @@ -136,9 +204,9 @@ for my $slot (sort @controllers) { }; }; - my $status = join("; ", (map { $_.": ".join(", ", @{$status{$_}}) } keys %status)); + my $status = join(" - ", (map { $_.": ".join(", ", @{$status{$_}}) } keys %status)); push @resultstr, "Slot $slot: $status"; }; -print "$EXITCODE: ", join(" - ", @resultstr), "\n"; +print "$EXITCODE: ", join(" --- ", @resultstr), "\n"; exit $CODE{$EXITCODE};