disks: parse smart attributes using RE

This commit is contained in:
Fabian Grünbichler
2016-09-28 13:42:24 +02:00
committed by Dietmar Maurer
parent 0c486b09df
commit 1c99955364

View File

@ -81,19 +81,20 @@ sub get_smart_data {
$returncode = run_command([$SMARTCTL, '-H', '-A', '-f', 'brief', $disk], noerr => 1, outfunc => sub{ $returncode = run_command([$SMARTCTL, '-H', '-A', '-f', 'brief', $disk], noerr => 1, outfunc => sub{
my ($line) = @_; my ($line) = @_;
if ($datastarted && $line =~ m/^[ \d]{2}\d/) { # ATA SMART attributes, e.g.:
$line = trim($line); # ID# ATTRIBUTE_NAME FLAGS VALUE WORST THRESH FAIL RAW_VALUE
my @data = split /\s+/, $line; # 1 Raw_Read_Error_Rate POSR-K 100 100 000 - 0
if ($datastarted && $line =~ m/^([ \d]{2}\d)\s+(\S+)\s+(\S{6})\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/) {
my $entry = {}; my $entry = {};
$entry->{name} = $data[1]; $entry->{name} = $2 if defined $2;
$entry->{flags} = $data[2]; $entry->{flags} = $3 if defined $3;
# the +0 makes a number out of the strings # the +0 makes a number out of the strings
$entry->{value} = $data[3] + 0; $entry->{value} = $4+0 if defined $4;
$entry->{worst} = $data[4] + 0; $entry->{worst} = $5+0 if defined $5;
$entry->{threshold} = $data[5] + 0; $entry->{threshold} = $6+0 if defined $6;
$entry->{fail} = $data[6]; $entry->{fail} = $7 if defined $7;
$entry->{raw} = $data[7]; $entry->{raw} = $8 if defined $8;
$entry->{id} = $data[0]; $entry->{id} = $1 if defined $1;
push @{$smartdata->{attributes}}, $entry; push @{$smartdata->{attributes}}, $entry;
} elsif ($line =~ m/self\-assessment test result: (.*)$/) { } elsif ($line =~ m/self\-assessment test result: (.*)$/) {
$smartdata->{health} = $1; $smartdata->{health} = $1;