From ada96136d479ba790ab14c2bbc1cca00cfc985cc Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Tue, 27 Jun 2023 09:19:18 -0500 Subject: [PATCH 1/5] use $sg_int when composing lines for cciss devs --- snmp/smart-v1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index d3b9bbdd6..b487a5e64 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -365,7 +365,6 @@ if ( defined( $opts{g} ) ) { $drive_count++; } ## end while ($continue) } else { - my $sg_drive_int = 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 ) { @@ -377,7 +376,7 @@ 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++; } From 1623e78e76c50374b053af2f71b214a91a790eaf Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Tue, 27 Jun 2023 10:00:53 -0500 Subject: [PATCH 2/5] more cleanup for cciss stuff for when it does not recognize a device --- snmp/smart-v1 | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index b487a5e64..975540542 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -269,6 +269,7 @@ if ( defined( $opts{g} ) ) { # second pass, putting the lines together my %current_disk; foreach my $arguments (@argumentsA) { + my $name = $arguments; $name =~ s/ .*//; $name =~ s/\/dev\///; @@ -337,21 +338,16 @@ if ( defined( $opts{g} ) ) { 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 @@ -365,7 +361,7 @@ if ( defined( $opts{g} ) ) { $drive_count++; } ## end while ($continue) } else { - 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} ) ) { @@ -376,10 +372,16 @@ if ( defined( $opts{g} ) ) { my $drive_int = 0; while ( $drive_int < $drive_count ) { $drive_lines - = $drive_lines . $cciss . $sg_int . '-' . $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++; From b396c5b04fc6da74a798eb990064acffe1995028 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Tue, 27 Jun 2023 10:02:57 -0500 Subject: [PATCH 3/5] use -i with smart for the cciss -C test --- snmp/smart-v1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index 975540542..4fb15cd1a 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -334,7 +334,7 @@ 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 { From 8b7b5958d3210b70ddd7e975015578bf12036ca9 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Tue, 27 Jun 2023 10:58:44 -0500 Subject: [PATCH 4/5] add in virt checking --- snmp/smart-v1 | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index 4fb15cd1a..481c777f5 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -269,23 +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 =~ /($?)Prouct\:.*LOGICATAL 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...) From 97902630c21e77a2e880eebc10621c46e07939b7 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Tue, 27 Jun 2023 11:02:24 -0500 Subject: [PATCH 5/5] fix regex typos for virt check --- snmp/smart-v1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index 481c777f5..9e58e1d96 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -274,7 +274,7 @@ if ( defined( $opts{g} ) ) { # 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 =~ /($?)Prouct\:.*LOGICATAL VOLUME.*/ ) { + if ( $virt_check_line =~ /(?i)Product\:.*LOGICAL VOLUME/ ) { $not_virt = 0; } }