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

smart-v1: add handling unknown cciss devs #482

Merged
merged 5 commits into from
Jul 6, 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
29 changes: 23 additions & 6 deletions snmp/smart-v1
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Switches:
-C Enable manual checking for guess and cciss.
-S Set useSN to 0 when using -g
-t <test> Run the specified smart self test on all the devices.
-U When calling cciss_vol_status, call it with -u.
-G <modes> Guess modes to use. This is a comma seperated list.
Default :: scan-open,cciss-vol-status

Expand All @@ -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

Expand All @@ -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 {
Expand All @@ -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 <test> Run the specified smart self test on all the devices.
-U When calling cciss_vol_status, call it with -u.
-G <modes> Guess modes to use. This is a comma seperated list.
Default :: scan-open,cciss-vol-status

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -561,6 +570,7 @@ foreach my $line (@disks) {
if ( $disk !~ /\// ) {
$disk = '/dev/' . $disk;
}

my $output = `$smartctl -A $disk`;
my %IDs = (
'5' => 'null',
Expand Down Expand Up @@ -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);
Expand Down