Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various smart-v1 fixes #477

Merged
merged 5 commits into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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