Skip to content
Snippets Groups Projects
Commit 19b86685 authored by ale's avatar ale
Browse files

Fix sorting of SMART self-tests

parent b882361d
Branches
No related tags found
No related merge requests found
Pipeline #83715 passed
...@@ -196,10 +196,10 @@ def _wrap_hours(power_on_hours, n): ...@@ -196,10 +196,10 @@ def _wrap_hours(power_on_hours, n):
# wraps around. Try to put it back in the range of the current # wraps around. Try to put it back in the range of the current
# value of power_on_hours, although now we're just making up data # value of power_on_hours, although now we're just making up data
# and this will fail spectacularly in certain circumstances. # and this will fail spectacularly in certain circumstances.
if power_on_hours < 65536: up = power_on_hours & 0xffff0000
return n n = up + n
if n < (power_on_hours & 0xffff): while n > power_on_hours:
return (power_on_hours & 0xffff0000) + n n -= 65536
return n return n
...@@ -214,6 +214,8 @@ def collect_self_test_status(device, data): ...@@ -214,6 +214,8 @@ def collect_self_test_status(device, data):
# Attempt to extract the most recent self test status by type. # Attempt to extract the most recent self test status by type.
most_recent_test_by_type = {} most_recent_test_by_type = {}
for test in data['ata_smart_self_test_log']['standard']['table']: for test in data['ata_smart_self_test_log']['standard']['table']:
# Fix the timestamp
test['lifetime_hours'] = _wrap_hours(power_on_hours, test['lifetime_hours'])
key = test['type']['value'] key = test['type']['value']
if (key not in most_recent_test_by_type) or \ if (key not in most_recent_test_by_type) or \
(test['lifetime_hours'] > most_recent_test_by_type[key]['lifetime_hours']): (test['lifetime_hours'] > most_recent_test_by_type[key]['lifetime_hours']):
...@@ -222,8 +224,7 @@ def collect_self_test_status(device, data): ...@@ -222,8 +224,7 @@ def collect_self_test_status(device, data):
labels = {'test': to_label_value(test['type']['string'])} labels = {'test': to_label_value(test['type']['string'])}
labels.update(device.labels) labels.update(device.labels)
yield Gauge('self_test_status', labels, test['status']['passed']) yield Gauge('self_test_status', labels, test['status']['passed'])
yield Gauge('self_test_hours', labels, yield Gauge('self_test_hours', labels, test['lifetime_hours'])
_wrap_hours(power_on_hours, test['lifetime_hours']))
def collect_ata_attributes(device, data): def collect_ata_attributes(device, data):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment