Skip to content

Commit

Permalink
FusionInventory::Agent::Task::Inventory::Linux::Storages::MegacliWith…
Browse files Browse the repository at this point in the history
…Smartctl (#835)
  • Loading branch information
po1vo committed Oct 7, 2020
1 parent 9a1aeed commit d81b2d6
Show file tree
Hide file tree
Showing 9 changed files with 3,562 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use parent 'FusionInventory::Agent::Task::Inventory::Module';

use FusionInventory::Agent::Tools;

our $runMeIfTheseChecksFailed = ['FusionInventory::Agent::Task::Inventory::Linux::Storages::MegacliWithSmartctl'];

sub isEnabled {
return canRun('megacli');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package FusionInventory::Agent::Task::Inventory::Linux::Storages::MegacliWithSmartctl;

use strict;
use warnings;

use parent 'FusionInventory::Agent::Task::Inventory::Module';

use File::Basename qw(basename);
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Linux qw(getInfoFromSmartctl);

use constant RE => qr/^([^:]+?)\s*:\s*(.*\S)/;

sub isEnabled {
return canRun('megacli') && canRun('smartctl');
}

sub doInventory {
my (%params) = @_;

my $inventory = $params{inventory};

my $count = getFirstMatch(
command => "megacli -adpCount",
pattern => qr/Controller Count: (\d+)/
);
return unless $count;

for (my $adp = 0; $adp < $count; $adp++) {
my $adpinfo = _getAdpPciInfo(adp => $adp);
my $block = _adpInfoToBlock($adpinfo);
my $pdlist = _getPDlist(adp => $adp);
my $ldinfo = _getLDinfo(adp => $adp);

while (my ($id, $pd) = each %$pdlist) {
# JBOD and Non-RAID are processed by the parent module, skip.
next if (
(defined $pd->{__diskgroup} &&
defined $ldinfo->{ $pd->{__diskgroup} } &&
defined $ldinfo->{ $pd->{__diskgroup} }->{'Number Of Drives'} &&
defined $ldinfo->{ $pd->{__diskgroup} }->{'Name'} &&
$ldinfo->{ $pd->{__diskgroup} }->{'Number Of Drives'} eq '1' &&
$ldinfo->{ $pd->{__diskgroup} }->{'Name'} =~ /Non\s*\-*RAID/i)
||
$pd->{'Firmware state'} =~ /JBOD/i
);

my $storage = getInfoFromSmartctl(
device => '/dev/' . $block,
extra => '-d megaraid,' . $id);

$inventory->addEntry(
section => 'STORAGES',
entry => $storage,
);
}
}
}

sub _getPDlist {
my (%params) = @_;

$params{command} = defined $params{adp} ? "megacli -pdlist -a$params{adp}" : undef;

my %pdlist;
my $src = {};

foreach my $line (getAllLines(%params)) {
my ($key, $val) = $line =~ RE
or next;

if ($key eq 'Enclosure Device ID') {
$pdlist{ $src->{'Device Id'} } = $src if defined $src->{'Device Id'};
$src = {};
} elsif ($key eq 'Drive\'s position') {
($src->{__diskgroup}, $src->{__span}, $src->{__arm}) =
($val =~ /DiskGroup: (\d+), Span: (\d+), Arm: (\d+)/);
}

$src->{$key} = $val;
}
$pdlist{ $src->{'Device Id'} } = $src if defined $src->{'Device Id'};

return \%pdlist;
}

sub _getLDinfo {
my (%params) = @_;

$params{command} = defined $params{adp} ? "megacli -ldinfo -lAll -a$params{adp}" : undef;

my %ldinfo;
my $n = -1;

foreach my $line (getAllLines(%params)) {
my ($key, $val) = $line =~ RE
or next;

if ($key eq 'Virtual Drive') {
($n) = ($val =~ /^\s*(\d+)/);
}

$ldinfo{$n}->{$key} = $val;
}

return \%ldinfo;
}

sub _getAdpPciInfo {
my (%params) = @_;

$params{command} = defined $params{adp} ? "megacli -AdpGetPciInfo -a$params{adp}" : undef;

my %adpinfo;
foreach my $line (getAllLines(%params)) {
next unless $line =~ RE;
$adpinfo{$1} = $2;
}

return \%adpinfo;
}

sub _adpInfoToBlock {
my ($adpinfo) = @_;

my $pciid = sprintf "0000:%02s:%02s.%01s",
$adpinfo->{'Bus Number'}, $adpinfo->{'Device Number'}, $adpinfo->{'Function Number'};

my @blocks = glob "/sys/bus/pci/devices/$pciid/host*/target*/*/block/*";

# return first block device name
return basename(shift @blocks);
}

1;
__END__
=head1 NAME
FusionInventory::Agent::Task::Inventory::Linux::Storages::MegacliWithSmartctl - LSI Megaraid inventory
=head1 DESCRIPTION
Provides inventory of megaraid controllers using megacli and smartctl
9 changes: 9 additions & 0 deletions resources/linux/megacli/set6_AdpPciInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

PCI information for Controller 0
--------------------------------
Bus Number : 3
Device Number : 0
Function Number : 0


Exit Code: 0x00
Expand Down
82 changes: 82 additions & 0 deletions resources/linux/megacli/set6_LDinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@


Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name :Virtual Disk 0
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 558.375 GB
Sector Size : 512
Mirror Data : 558.375 GB
State : Optimal
Strip Size : 64 KB
Number Of Drives : 2
Span Depth : 1
Default Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: Yes
LD has drives that support T10 power conditions: Yes
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: Yes
Cache Cade Type : Read Only


Virtual Drive: 1 (Target Id: 1)
Name :Virtual Disk 1
RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
Size : 223.0 GB
Sector Size : 512
Parity Size : 0
State : Optimal
Strip Size : 64 KB
Number Of Drives : 1
Span Depth : 1
Default Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Enabled
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: No
LD has drives that support T10 power conditions: No
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: No


Virtual Drive: 2 (Target Id: 2)
Name :Virtual Disk 2
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 8.984 TB
Sector Size : 512
Mirror Data : 8.984 TB
State : Optimal
Strip Size : 64 KB
Number Of Drives per span:2
Span Depth : 5
Default Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAdaptive, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: Yes
LD has drives that support T10 power conditions: Yes
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: Yes
Cache Cade Type : Read Only



Exit Code: 0x00
Expand Down

0 comments on commit d81b2d6

Please sign in to comment.