From 4e78072daf24066ec9d176d299f0a364d205f975 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Thu, 6 Jul 2023 13:27:56 -0500 Subject: [PATCH] smart-v1: add handling unknown cciss devs (#482) * add -u option * add a small fix for when smart fails and useSN is false * some more possible cciss error handling * rename -u for with guess to -U to avoid conflict * add U to getopts --- snmp/smart-v1 | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/snmp/smart-v1 b/snmp/smart-v1 index 91c2710f9..fab2af3bd 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 @@ -111,7 +113,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 +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. -G Guess modes to use. This is a comma seperated list. Default :: scan-open,cciss-vol-status @@ -136,14 +139,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 +318,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 +344,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 @@ -561,6 +570,7 @@ foreach my $line (@disks) { if ( $disk !~ /\// ) { $disk = '/dev/' . $disk; } + my $output = `$smartctl -A $disk`; my %IDs = ( '5' => 'null', @@ -865,9 +875,16 @@ foreach my $line (@disks) { # only bother to save this if useSN is not being used if ( !$useSN ) { $to_return->{data}{disks}{$disk_id} = \%IDs; - } elsif ( $IDs{exit} == 0 ) { + } 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) my $toReturn = $json->encode($to_return);