|
@@ -6,11 +6,10 @@ use Carp;
|
|
|
use Math::Round;
|
|
use Math::Round;
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
- $Disk::SMART::VERSION = '0.10'
|
|
|
|
|
|
|
+ $Disk::SMART::VERSION = '0.11'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-our $smartctl = qx(which smartctl);
|
|
|
|
|
-chomp($smartctl);
|
|
|
|
|
|
|
+chomp( our $smartctl = qx(which smartctl) );
|
|
|
|
|
|
|
|
=head1 NAME
|
|
=head1 NAME
|
|
|
|
|
|
|
@@ -154,7 +153,7 @@ sub get_disk_temp {
|
|
|
|
|
|
|
|
Updates the SMART output and attributes of a device. Returns undef.
|
|
Updates the SMART output and attributes of a device. Returns undef.
|
|
|
|
|
|
|
|
-C<DEVICE> - Device identifier of SSD/ Hard Drive
|
|
|
|
|
|
|
+C<DEVICE> - Device identifier of SSD Hard Drive
|
|
|
|
|
|
|
|
$smart->update_data('/dev/sda');
|
|
$smart->update_data('/dev/sda');
|
|
|
|
|
|
|
@@ -178,7 +177,7 @@ sub update_data {
|
|
|
$self->_process_disk_model($device);
|
|
$self->_process_disk_model($device);
|
|
|
$self->_process_disk_temp($device);
|
|
$self->_process_disk_temp($device);
|
|
|
|
|
|
|
|
- return 1;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
=head2 B<run_short_test(DEVICE)>
|
|
=head2 B<run_short_test(DEVICE)>
|
|
@@ -201,12 +200,12 @@ sub run_short_test {
|
|
|
sleep( $short_test_time * 60 );
|
|
sleep( $short_test_time * 60 );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- my $smart_output = ( defined $ENV{'MOCK_TEST_DATA'} ) ? $ENV{'MOCK_TEST_DATA'} : qx($smartctl -a $device);
|
|
|
|
|
|
|
+ my $smart_output = $ENV{'MOCK_TEST_DATA'} // qx($smartctl -a $device);
|
|
|
($smart_output) = $smart_output =~ /(SMART Self-test log.*)\nSMART Selective self-test/s;
|
|
($smart_output) = $smart_output =~ /(SMART Self-test log.*)\nSMART Selective self-test/s;
|
|
|
my @device_tests = split /\n/, $smart_output;
|
|
my @device_tests = split /\n/, $smart_output;
|
|
|
my $short_test_number = $device_tests[2];
|
|
my $short_test_number = $device_tests[2];
|
|
|
my $short_test_status = substr $short_test_number, 25, +30;
|
|
my $short_test_status = substr $short_test_number, 25, +30;
|
|
|
- $short_test_status =~ s/\s+$//g; #trim beginning and ending whitepace
|
|
|
|
|
|
|
+ $short_test_status = _trim($short_test_status);
|
|
|
|
|
|
|
|
return $short_test_status;
|
|
return $short_test_status;
|
|
|
}
|
|
}
|
|
@@ -225,8 +224,8 @@ sub _process_disk_attributes {
|
|
|
foreach my $attribute (@attributes) {
|
|
foreach my $attribute (@attributes) {
|
|
|
my $name = substr $attribute, 4, +24;
|
|
my $name = substr $attribute, 4, +24;
|
|
|
my $value = substr $attribute, 83, +50;
|
|
my $value = substr $attribute, 83, +50;
|
|
|
- $name =~ s/\s+$//g; # trim ending whitespace
|
|
|
|
|
- $value =~ s/^\s+//g; # trim beginning and ending whitepace
|
|
|
|
|
|
|
+ $name = _trim($name);
|
|
|
|
|
+ $value = _trim($value);
|
|
|
$self->{'devices'}->{$device}->{'attributes'}->{$name} = $value;
|
|
$self->{'devices'}->{$device}->{'attributes'}->{$name} = $value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -238,8 +237,8 @@ sub _process_disk_errors {
|
|
|
$self->_validate_param($device);
|
|
$self->_validate_param($device);
|
|
|
|
|
|
|
|
my $smart_output = $self->{'devices'}->{$device}->{'SMART_OUTPUT'};
|
|
my $smart_output = $self->{'devices'}->{$device}->{'SMART_OUTPUT'};
|
|
|
- my ($errors) = $smart_output =~ /SMART Error Log Version: [1-9](.*)SMART Self-test log/s;
|
|
|
|
|
- $errors =~ s/^\s+|\s+$//g; #trim beginning and ending whitepace
|
|
|
|
|
|
|
+ my ($errors) = $smart_output =~ /SMART Error Log Version: [1-9](.*)SMART Self-test log/s;
|
|
|
|
|
+ $errors = _trim($errors);
|
|
|
$errors = 'N/A' if !$errors;
|
|
$errors = 'N/A' if !$errors;
|
|
|
|
|
|
|
|
return $self->{'devices'}->{$device}->{'errors'} = $errors;
|
|
return $self->{'devices'}->{$device}->{'errors'} = $errors;
|
|
@@ -250,8 +249,8 @@ sub _process_disk_health {
|
|
|
$self->_validate_param($device);
|
|
$self->_validate_param($device);
|
|
|
|
|
|
|
|
my $smart_output = $self->{'devices'}->{$device}->{'SMART_OUTPUT'};
|
|
my $smart_output = $self->{'devices'}->{$device}->{'SMART_OUTPUT'};
|
|
|
- my ($health) = $smart_output =~ /SMART overall-health self-assessment test result:(.*)\n/;
|
|
|
|
|
- $health =~ s/^\s+|\s+$//g; #trim beginning and ending whitepace
|
|
|
|
|
|
|
+ my ($health) = $smart_output =~ /SMART overall-health self-assessment test result:(.*)\n/;
|
|
|
|
|
+ $health = _trim($health);
|
|
|
$health = 'N/A' if !$health || $health !~ /PASSED|FAILED/x;
|
|
$health = 'N/A' if !$health || $health !~ /PASSED|FAILED/x;
|
|
|
|
|
|
|
|
return $self->{'devices'}->{$device}->{'health'} = $health;
|
|
return $self->{'devices'}->{$device}->{'health'} = $health;
|
|
@@ -262,8 +261,8 @@ sub _process_disk_model {
|
|
|
$self->_validate_param($device);
|
|
$self->_validate_param($device);
|
|
|
|
|
|
|
|
my $smart_output = $self->{'devices'}->{$device}->{'SMART_OUTPUT'};
|
|
my $smart_output = $self->{'devices'}->{$device}->{'SMART_OUTPUT'};
|
|
|
- my ($model) = $smart_output =~ /Device\ Model:(.*)\n/;
|
|
|
|
|
- $model =~ s/^\s+|\s+$//g; #trim beginning and ending whitepace
|
|
|
|
|
|
|
+ my ($model) = $smart_output =~ /Device\ Model:(.*)\n/;
|
|
|
|
|
+ $model = _trim($model);
|
|
|
$model = 'N/A' if !$model;
|
|
$model = 'N/A' if !$model;
|
|
|
|
|
|
|
|
return $self->{'devices'}->{$device}->{'model'} = $model;
|
|
return $self->{'devices'}->{$device}->{'model'} = $model;
|
|
@@ -279,7 +278,7 @@ sub _process_disk_temp {
|
|
|
|
|
|
|
|
if ($temp_c) {
|
|
if ($temp_c) {
|
|
|
$temp_c = substr $temp_c, 83, +3;
|
|
$temp_c = substr $temp_c, 83, +3;
|
|
|
- $temp_c =~ s/^\s+|\s+$//g; #trim beginning and ending whitepace
|
|
|
|
|
|
|
+ $temp_c = _trim($temp_c);
|
|
|
$temp_f = round( ( $temp_c * 9 ) / 5 + 32 );
|
|
$temp_f = round( ( $temp_c * 9 ) / 5 + 32 );
|
|
|
$temp_c = int $temp_c;
|
|
$temp_c = int $temp_c;
|
|
|
$temp_f = int $temp_f;
|
|
$temp_f = int $temp_f;
|
|
@@ -292,6 +291,12 @@ sub _process_disk_temp {
|
|
|
return $self->{'devices'}->{$device}->{'temp'} = [ ( $temp_c, $temp_f ) ];
|
|
return $self->{'devices'}->{$device}->{'temp'} = [ ( $temp_c, $temp_f ) ];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+sub _trim {
|
|
|
|
|
+ my $string = shift;
|
|
|
|
|
+ $string =~ s/^\s+|\s+$//g; #trim beginning and ending whitepace
|
|
|
|
|
+ return $string;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
sub _validate_param {
|
|
sub _validate_param {
|
|
|
my ( $self, $device ) = @_;
|
|
my ( $self, $device ) = @_;
|
|
|
croak "$device not found in object. Verify you specified the right device identifier.\n"
|
|
croak "$device not found in object. Verify you specified the right device identifier.\n"
|