parent
4eb376b929
commit
4777b8274f
2 changed files with 53 additions and 51 deletions
@ -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); |
||||||
|
Loading…
Reference in new issue