]> git.proxmox.com Git - pve-storage.git/commitdiff
disks: parse smart attributes using RE
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 28 Sep 2016 11:42:24 +0000 (13:42 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 29 Sep 2016 06:42:06 +0000 (08:42 +0200)
PVE/Diskmanage.pm

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