From 8d053015a11dda4c794be4ca7578a112751c7f5d Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Thu, 6 Jul 2023 11:34:43 -0500 Subject: [PATCH 1/5] add -u option --- snmp/smart-v1 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index 91c2710f9..911829fc7 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -111,7 +111,7 @@ my $useSN = 1; $Getopt::Std::STANDARD_HELP_VERSION = 1; sub main::VERSION_MESSAGE { - print "SMART SNMP extend 0.2.0\n"; + print "SMART SNMP extend 0.3.0\n"; } sub main::HELP_MESSAGE { @@ -123,6 +123,7 @@ sub main::HELP_MESSAGE { -C Enable manual checking for guess and cciss. -S Set useSN to 0 when using -g -t Run the specified smart self test on all the devices. +-u When calling cciss_vol_status, call it with -u. -G Guess modes to use. This is a comma seperated list. Default :: scan-open,cciss-vol-status @@ -136,14 +137,15 @@ Scan Modes: - cciss-vol-status :: Freebsd/Linux specific and if it sees /dev/sg0(on Linux) or /dev/ciss0(on FreebSD) it will attempt to find drives via cciss-vol-status, and then optionally checking for disks via smrtctl if -C is given. Should be noted - though that -C will not find drives that are currently missing/failed. + though that -C will not find drives that are currently missing/failed. If -u is given, + cciss_vol_status will be called with -u. '; } ## end sub main::HELP_MESSAGE #gets the options my %opts = (); -getopts( 'ugc:pZhvCSGt:', \%opts ); +getopts( 'ugc:pZhvCSGt:u', \%opts ); if ( $opts{h} ) { &HELP_MESSAGE; @@ -314,6 +316,11 @@ if ( defined( $opts{g} ) ) { $cciss = 'sg'; } + my $uarg = ''; + if ($opts{u}) { + $uarg='-u'; + } + # generate the initial device path that will be checked my $sg_int = 0; my $device = '/dev/' . $cciss . $sg_int; @@ -335,7 +342,7 @@ if ( defined( $opts{g} ) ) { } ## end if ( -e $device ) my $seen_lines = {}; while ( -e $device && $sg_process ) { - my $output = `cciss_vol_status -V $device 2> /dev/null`; + my $output = `cciss_vol_status -V $uarg $device 2> /dev/null`; if ( $? != 0 && $output eq '' && !$opts{C} ) { # just empty here as we just want to skip it if it fails and there is no C # warning is above From 87d6cf79c6245f595d1d8398c2a23c28f0fac194 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Thu, 6 Jul 2023 11:42:56 -0500 Subject: [PATCH 2/5] add a small fix for when smart fails and useSN is false --- snmp/smart-v1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index 911829fc7..e59442b38 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -871,7 +871,7 @@ foreach my $line (@disks) { # only bother to save this if useSN is not being used if ( !$useSN ) { - $to_return->{data}{disks}{$disk_id} = \%IDs; + $to_return->{data}{disks}{$name} = \%IDs; } elsif ( $IDs{exit} == 0 ) { $to_return->{data}{disks}{$disk_id} = \%IDs; } From d38c514a6e30d36b143041a5814ff4d7b266c499 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Thu, 6 Jul 2023 11:57:07 -0500 Subject: [PATCH 3/5] some more possible cciss error handling --- snmp/smart-v1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index e59442b38..2fdc0b152 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -568,6 +568,7 @@ foreach my $line (@disks) { if ( $disk !~ /\// ) { $disk = '/dev/' . $disk; } + my $output = `$smartctl -A $disk`; my %IDs = ( '5' => 'null', @@ -871,9 +872,16 @@ foreach my $line (@disks) { # only bother to save this if useSN is not being used if ( !$useSN ) { - $to_return->{data}{disks}{$name} = \%IDs; - } elsif ( $IDs{exit} == 0 ) { $to_return->{data}{disks}{$disk_id} = \%IDs; + } elsif ( $IDs{exit} == 0 && defined($disk_id) ) { + $to_return->{data}{disks}{$disk_id} = \%IDs; + } + + # smartctl will in some cases exit zero when it can't pull data for cciss + # so if we get a zero exit, but no serial then it means something errored + # and the device is likely dead + if ($IDs{exit} == 0 && !defined($IDs{serial})) { + $to_return->{data}{unhealthy}++; } } ## end foreach my $line (@disks) From e4fbded253a571fe9f1e5217ed3154200db947db Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Thu, 6 Jul 2023 12:07:46 -0500 Subject: [PATCH 4/5] rename -u for with guess to -U to avoid conflict --- snmp/smart-v1 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index 2fdc0b152..579514993 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -77,6 +77,7 @@ Switches: -C Enable manual checking for guess and cciss. -S Set useSN to 0 when using -g -t Run the specified smart self test on all the devices. +-U When calling cciss_vol_status, call it with -u. -G Guess modes to use. This is a comma seperated list. Default :: scan-open,cciss-vol-status @@ -89,7 +90,8 @@ Guess Modes: - cciss-vol-status :: Freebsd/Linux specific and if it sees /dev/sg0(on Linux) or /dev/ciss0(on FreebSD) it will attempt to find drives via cciss-vol-status, and then optionally checking for disks via smrtctl if -C is given. Should be noted - though that -C will not find drives that are currently missing/failed. + though that -C will not find drives that are currently missing/failed. If -U is given, + cciss_vol_status will be called with -u. =cut @@ -123,7 +125,7 @@ sub main::HELP_MESSAGE { -C Enable manual checking for guess and cciss. -S Set useSN to 0 when using -g -t Run the specified smart self test on all the devices. --u When calling cciss_vol_status, call it with -u. +-U When calling cciss_vol_status, call it with -u. -G Guess modes to use. This is a comma seperated list. Default :: scan-open,cciss-vol-status @@ -137,7 +139,7 @@ Scan Modes: - cciss-vol-status :: Freebsd/Linux specific and if it sees /dev/sg0(on Linux) or /dev/ciss0(on FreebSD) it will attempt to find drives via cciss-vol-status, and then optionally checking for disks via smrtctl if -C is given. Should be noted - though that -C will not find drives that are currently missing/failed. If -u is given, + though that -C will not find drives that are currently missing/failed. If -U is given, cciss_vol_status will be called with -u. '; @@ -317,8 +319,8 @@ if ( defined( $opts{g} ) ) { } my $uarg = ''; - if ($opts{u}) { - $uarg='-u'; + if ( $opts{U} ) { + $uarg = '-u'; } # generate the initial device path that will be checked @@ -880,7 +882,7 @@ foreach my $line (@disks) { # smartctl will in some cases exit zero when it can't pull data for cciss # so if we get a zero exit, but no serial then it means something errored # and the device is likely dead - if ($IDs{exit} == 0 && !defined($IDs{serial})) { + if ( $IDs{exit} == 0 && !defined( $IDs{serial} ) ) { $to_return->{data}{unhealthy}++; } } ## end foreach my $line (@disks) From bc789c18cbef5de3bf8a4e08febec436cc94ddee Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Thu, 6 Jul 2023 12:08:18 -0500 Subject: [PATCH 5/5] add U to getopts --- snmp/smart-v1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index 579514993..fab2af3bd 100755 --- a/snmp/smart-v1 +++ b/snmp/smart-v1 @@ -147,7 +147,7 @@ Scan Modes: #gets the options my %opts = (); -getopts( 'ugc:pZhvCSGt:u', \%opts ); +getopts( 'ugc:pZhvCSGt:U', \%opts ); if ( $opts{h} ) { &HELP_MESSAGE;