From 4777b8274f758946669e54a5326c4626a331dcf4 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 23 Sep 2020 20:00:46 +0200 Subject: [PATCH] Update scripts to work with ssacli (in adition to hpacucli) --- zabbix_scripts/check_raid_hp_sudo | 73 ++++++++++++++++--------------- zabbix_scripts/disco_raid_hp_sudo | 31 ++++++------- 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/zabbix_scripts/check_raid_hp_sudo b/zabbix_scripts/check_raid_hp_sudo index a013814..f4383e0 100644 --- a/zabbix_scripts/check_raid_hp_sudo +++ b/zabbix_scripts/check_raid_hp_sudo @@ -1,10 +1,11 @@ #!/usr/bin/perl -w use strict; +use File::Which; use Getopt::Long; my $slot = ''; -my $hpacucli = '/usr/sbin/hpacucli'; +my $cli = which('hpacucli') || which('ssacli'); my @validchecks = qw/controller array logicaldrive physicaldrive/; my $check = join ',', @validchecks; @@ -14,67 +15,67 @@ GetOptions ('slot=s' => \$slot, ); sub usage(){ - print <<"EOF"; + print <<"EOF"; $0 --slot= --check= * 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 Valid values are: EOF - print "$_\n" foreach (@validchecks); - exit(0); + print "$_\n" foreach (@validchecks); + exit(0); } if ($slot !~ /^\d+$/){ - usage(); + usage(); } -unless (-x $hpacucli){ - die "Cannot run $hpacucli\n"; +unless (-x $cli){ + die "Cannot run $cli\n"; } my @checks = split /\s?,\s?/, $check; foreach my $check (@checks){ - usage() unless (grep { $_ eq $check} @validchecks); + usage() unless (grep { $_ eq $check} @validchecks); } foreach my $param (@checks){ - # Global controller checks - if ($param eq 'controller'){ - open HPACUCLI, "$hpacucli controller slot=$slot show status|" || - die "An error occured while running $hpacucli: $!"; - foreach my $line (){ - if ( $line =~ /Status\:\s*([\w\s]+)$/ ) { - my $res = $1; - chomp($res); - if ($res ne 'OK'){ - print "CRITICAL: $line\n"; - exit(0); - } - } + # Global controller checks + if ($param eq 'controller'){ + open CLI, "$cli controller slot=$slot show status|" || + die "An error occured while running $cli: $!"; + foreach my $line (){ + if ( $line =~ /Status\:\s*([\w\s]+)$/ ) { + my $res = $1; + chomp($res); + if ($res ne 'OK'){ + print "CRITICAL: $line\n"; + exit(0); } - close HPACUCLI; + } } - else{ - open HPACUCLI, "$hpacucli controller slot=$slot $param all show status|" || - die "An error occured while running $hpacucli: $!"; - foreach my $line (){ - if ( $line =~ /^\s*$param.*:\s*(\w+[\w\s]*)$/i ) { - my $res = $1; - chomp($res); - if ($res ne 'OK'){ - print "CRITICAL: $line\n"; - exit(0); - } - } + close CLI; + } + else{ + open CLI, "$cli controller slot=$slot $param all show status|" || + die "An error occured while running $cli: $!"; + foreach my $line (){ + if ( $line =~ /^\s*$param.*:\s*(\w+[\w\s]*)$/i ) { + my $res = $1; + chomp($res); + if ($res ne 'OK'){ + print "CRITICAL: $line\n"; + exit(0); } - close HPACUCLI; + } } + close CLI; + } } print 'OK'; diff --git a/zabbix_scripts/disco_raid_hp_sudo b/zabbix_scripts/disco_raid_hp_sudo index 4056e9b..0063e5e 100644 --- a/zabbix_scripts/disco_raid_hp_sudo +++ b/zabbix_scripts/disco_raid_hp_sudo @@ -1,30 +1,31 @@ #!/usr/bin/perl -w use strict; +use File::Which; use JSON; my $json; @{$json->{data}} = (); -my $hpacucli = '/usr/sbin/hpacucli'; +my $cli = which('hpacucli') || which('ssacli'); -# the hpacucli utility is needed -unless (-x $hpacucli){ - print to_json($json); - exit(0); +# hpacucli or ssacli utility is needed +if (not defined $cli){ + print to_json($json); + exit(0); } -open( HPACUCLI, "$hpacucli controller all show status|" ) - or die "An error occured while running $hpacucli: $!"; +open( CLI, "$cli controller all show status|" ) + or die "An error occured while running $cli: $!"; -foreach my $line (){ - if ( $line =~ m/Another instance of hpacucli is running! Stop it first\./i ){ - die "Another instance of hpacucli is running\n"; - } - elsif ( $line =~ m/(.*) in Slot (\d+)/i ) { - push @{$json->{data}}, {"{#MODEL}" => $1, "{#SLOT}" => $2}; - } +foreach my $line (){ + if ( $line =~ m/Another instance of hpacucli is running! Stop it first\./i ){ + die "Another instance of hpacucli is running\n"; + } + elsif ( $line =~ m/(.*) in Slot (\d+)/i ) { + push @{$json->{data}}, {"{#MODEL}" => $1, "{#SLOT}" => $2}; + } } -close HPACUCLI; +close CLI; print to_json($json); exit(0);