Skip to content

Commit

Permalink
various smart-v1 fixes (#477)
Browse files Browse the repository at this point in the history
* use $sg_int when composing lines for cciss devs

* more cleanup for cciss stuff for when it does not recognize a device

* use -i with smart for the cciss -C test

* add in virt checking

* fix regex typos for virt check
  • Loading branch information
VVelox committed Jun 28, 2023
1 parent 442e691 commit 1328a11
Showing 1 changed file with 43 additions and 29 deletions.
72 changes: 43 additions & 29 deletions snmp/smart-v1
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,36 @@ if ( defined( $opts{g} ) ) {
# second pass, putting the lines together
my %current_disk;
foreach my $arguments (@argumentsA) {
my $not_virt = 1;

# check to see if we have a virtual device
my @virt_check = split( /\n/, `smartctl -i $arguments 2> /dev/null` );
foreach my $virt_check_line (@virt_check) {
if ( $virt_check_line =~ /(?i)Product\:.*LOGICAL VOLUME/ ) {
$not_virt = 0;
}
}

my $name = $arguments;
$name =~ s/ .*//;
$name =~ s/\/dev\///;

if ( $found_disks_names{$name} == 0 ) {
# If no other devices, just name it after the base device.
$drive_lines = $drive_lines . $name . " " . $arguments . "\n";
} else {
# if more than one, start at zero and increment, apennding comma number to the base device name
if ( defined( $current_disk{$name} ) ) {
$current_disk{$name}++;
# only add it if not a virtual RAID drive
# HP RAID virtual disks will show up with very basical but totally useless smart data
if ($not_virt) {
if ( $found_disks_names{$name} == 0 ) {
# If no other devices, just name it after the base device.
$drive_lines = $drive_lines . $name . " " . $arguments . "\n";
} else {
$current_disk{$name} = 0;
# if more than one, start at zero and increment, apennding comma number to the base device name
if ( defined( $current_disk{$name} ) ) {
$current_disk{$name}++;
} else {
$current_disk{$name} = 0;
}
$drive_lines = $drive_lines . $name . "," . $current_disk{$name} . " " . $arguments . "\n";
}
$drive_lines = $drive_lines . $name . "," . $current_disk{$name} . " " . $arguments . "\n";
}
} ## end if ($not_virt)

} ## end foreach my $arguments (@argumentsA)
} ## end if ( $scan_modes->{'scan-open'} || $scan_modes...)
Expand Down Expand Up @@ -333,25 +347,20 @@ if ( defined( $opts{g} ) ) {
my $drive_count = 0;
my $continue = 1;
while ($continue) {
my $output = `$smartctl -A $device -d cciss,$drive_count 2> /dev/null`;
my $output = `$smartctl -i $device -d cciss,$drive_count 2> /dev/null`;
if ( $? != 0 ) {
$continue = 0;
} else {
$continue = 0;
my $add_it = 0;
# if we have smart data for this device, process it
while ( $output =~ /(?i)START OF READ SMART DATA SECTION(.*)/g && !$continue ) {
$continue = 1;
my $id;
while ( $output =~ /(?i)Serial Number:(.*)/g ) {
$id = $1;
$id =~ s/^\s+|\s+$//g;
}
if ( defined($id) && !defined( $seen_lines->{$id} ) ) {
$add_it = 1;
$seen_lines->{$id} = 1;
}
} ## end while ( $output =~ /(?i)START OF READ SMART DATA SECTION(.*)/g...)
my $id;
while ( $output =~ /(?i)Serial Number:(.*)/g ) {
$id = $1;
$id =~ s/^\s+|\s+$//g;
}
if ( defined($id) && !defined( $seen_lines->{$id} ) ) {
$add_it = 1;
$seen_lines->{$id} = 1;
}
if ( $continue && $add_it ) {
$drive_lines
= $drive_lines
Expand All @@ -365,8 +374,7 @@ if ( defined( $opts{g} ) ) {
$drive_count++;
} ## end while ($continue)
} else {
my $sg_drive_int = 0;
my $drive_count = 0;
my $drive_count = 0;
# count the connector lines, this will make sure failed are founded as well
while ( $output =~ /(connector +\d.*box +\d.*bay +\d.*)/g ) {
if ( !defined( $seen_lines->{$1} ) ) {
Expand All @@ -377,10 +385,16 @@ if ( defined( $opts{g} ) ) {
my $drive_int = 0;
while ( $drive_int < $drive_count ) {
$drive_lines
= $drive_lines . $cciss . '0-' . $drive_int . ' ' . $device . ' -d cciss,' . $drive_int . "\n";
= $drive_lines
. $cciss
. $sg_int . '-'
. $drive_int . ' '
. $device
. ' -d cciss,'
. $drive_int . "\n";

$drive_int++;
}
} ## end while ( $drive_int < $drive_count )
} ## end else [ if ( $? != 0 && $output eq '' && !$opts{C})]

$sg_int++;
Expand Down

0 comments on commit 1328a11

Please sign in to comment.