Update scripts to work with ssacli (in adition to hpacucli)

This commit is contained in:
Daniel Berteaud 2020-09-23 20:00:46 +02:00
parent 4eb376b929
commit 4777b8274f
2 changed files with 53 additions and 51 deletions

View File

@ -1,10 +1,11 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use strict; use strict;
use File::Which;
use Getopt::Long; use Getopt::Long;
my $slot = ''; my $slot = '';
my $hpacucli = '/usr/sbin/hpacucli'; my $cli = which('hpacucli') || which('ssacli');
my @validchecks = qw/controller array logicaldrive physicaldrive/; my @validchecks = qw/controller array logicaldrive physicaldrive/;
my $check = join ',', @validchecks; my $check = join ',', @validchecks;
@ -14,67 +15,67 @@ GetOptions ('slot=s' => \$slot,
); );
sub usage(){ sub usage(){
print <<"EOF"; print <<"EOF";
$0 --slot=<slot number> --check=<what to check> $0 --slot=<slot number> --check=<what to check>
* slot must be a number. You can find on which slot you have controllers with the command: * slot must be a number. You can find on which slot you have controllers with the command:
$hpacucli controller all show status $cli controller all show status
* check is a comma separated list of item to check. Default values (without --check option) will check everything * check is a comma separated list of item to check. Default values (without --check option) will check everything
Valid values are: Valid values are:
EOF EOF
print "$_\n" foreach (@validchecks); print "$_\n" foreach (@validchecks);
exit(0); exit(0);
} }
if ($slot !~ /^\d+$/){ if ($slot !~ /^\d+$/){
usage(); usage();
} }
unless (-x $hpacucli){ unless (-x $cli){
die "Cannot run $hpacucli\n"; die "Cannot run $cli\n";
} }
my @checks = split /\s?,\s?/, $check; my @checks = split /\s?,\s?/, $check;
foreach my $check (@checks){ foreach my $check (@checks){
usage() unless (grep { $_ eq $check} @validchecks); usage() unless (grep { $_ eq $check} @validchecks);
} }
foreach my $param (@checks){ foreach my $param (@checks){
# Global controller checks # Global controller checks
if ($param eq 'controller'){ if ($param eq 'controller'){
open HPACUCLI, "$hpacucli controller slot=$slot show status|" || open CLI, "$cli controller slot=$slot show status|" ||
die "An error occured while running $hpacucli: $!"; die "An error occured while running $cli: $!";
foreach my $line (<HPACUCLI>){ foreach my $line (<CLI>){
if ( $line =~ /Status\:\s*([\w\s]+)$/ ) { if ( $line =~ /Status\:\s*([\w\s]+)$/ ) {
my $res = $1; my $res = $1;
chomp($res); chomp($res);
if ($res ne 'OK'){ if ($res ne 'OK'){
print "CRITICAL: $line\n"; print "CRITICAL: $line\n";
exit(0); exit(0);
}
}
} }
close HPACUCLI; }
} }
else{ close CLI;
open HPACUCLI, "$hpacucli controller slot=$slot $param all show status|" || }
die "An error occured while running $hpacucli: $!"; else{
foreach my $line (<HPACUCLI>){ open CLI, "$cli controller slot=$slot $param all show status|" ||
if ( $line =~ /^\s*$param.*:\s*(\w+[\w\s]*)$/i ) { die "An error occured while running $cli: $!";
my $res = $1; foreach my $line (<CLI>){
chomp($res); if ( $line =~ /^\s*$param.*:\s*(\w+[\w\s]*)$/i ) {
if ($res ne 'OK'){ my $res = $1;
print "CRITICAL: $line\n"; chomp($res);
exit(0); if ($res ne 'OK'){
} print "CRITICAL: $line\n";
} exit(0);
} }
close HPACUCLI; }
} }
close CLI;
}
} }
print 'OK'; print 'OK';

View File

@ -1,30 +1,31 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use strict; use strict;
use File::Which;
use JSON; use JSON;
my $json; my $json;
@{$json->{data}} = (); @{$json->{data}} = ();
my $hpacucli = '/usr/sbin/hpacucli'; my $cli = which('hpacucli') || which('ssacli');
# the hpacucli utility is needed # hpacucli or ssacli utility is needed
unless (-x $hpacucli){ if (not defined $cli){
print to_json($json); print to_json($json);
exit(0); exit(0);
} }
open( HPACUCLI, "$hpacucli controller all show status|" ) open( CLI, "$cli controller all show status|" )
or die "An error occured while running $hpacucli: $!"; or die "An error occured while running $cli: $!";
foreach my $line (<HPACUCLI>){ foreach my $line (<CLI>){
if ( $line =~ m/Another instance of hpacucli is running! Stop it first\./i ){ if ( $line =~ m/Another instance of hpacucli is running! Stop it first\./i ){
die "Another instance of hpacucli is running\n"; die "Another instance of hpacucli is running\n";
} }
elsif ( $line =~ m/(.*) in Slot (\d+)/i ) { elsif ( $line =~ m/(.*) in Slot (\d+)/i ) {
push @{$json->{data}}, {"{#MODEL}" => $1, "{#SLOT}" => $2}; push @{$json->{data}}, {"{#MODEL}" => $1, "{#SLOT}" => $2};
} }
} }
close HPACUCLI; close CLI;
print to_json($json); print to_json($json);
exit(0); exit(0);