mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-02-02 08:42:31 -08:00
Update smartmon.py to widen self_assessment_passed test (#1293)
Signed-off-by: EdgarasG <edgaras.giedre@hostinger.com>
This commit is contained in:
parent
d2136aace0
commit
2f87b7cba6
|
@ -5,14 +5,16 @@ import csv
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
import re
|
import re
|
||||||
import subprocess
|
|
||||||
import shlex
|
import shlex
|
||||||
|
import subprocess
|
||||||
|
|
||||||
device_info_re = re.compile(r'^(?P<k>[^:]+?)(?:(?:\sis|):)\s*(?P<v>.*)$')
|
device_info_re = re.compile(r'^(?P<k>[^:]+?)(?:(?:\sis|):)\s*(?P<v>.*)$')
|
||||||
|
|
||||||
ata_error_count_re = re.compile(
|
ata_error_count_re = re.compile(
|
||||||
r'^Error (\d+) \[\d+\] occurred', re.MULTILINE)
|
r'^Error (\d+) \[\d+\] occurred', re.MULTILINE)
|
||||||
|
|
||||||
|
self_test_re = re.compile(r'^SMART.*(PASSED|OK)$', re.MULTILINE)
|
||||||
|
|
||||||
device_info_map = {
|
device_info_map = {
|
||||||
'Vendor': 'vendor',
|
'Vendor': 'vendor',
|
||||||
'Product': 'product',
|
'Product': 'product',
|
||||||
|
@ -119,10 +121,12 @@ def smart_ctl(*args, check=True):
|
||||||
Returns:
|
Returns:
|
||||||
(str) Data piped to stdout by the smartctl subprocess.
|
(str) Data piped to stdout by the smartctl subprocess.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
return subprocess.run(
|
return subprocess.run(
|
||||||
['smartctl', *args], stdout=subprocess.PIPE, check=check,
|
['smartctl', *args], stdout=subprocess.PIPE, check=check
|
||||||
).stdout.decode('utf-8')
|
).stdout.decode('utf-8')
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
return e.output.decode('utf-8')
|
||||||
|
|
||||||
def smart_ctl_version():
|
def smart_ctl_version():
|
||||||
return smart_ctl('-V').split('\n')[0].split()[1]
|
return smart_ctl('-V').split('\n')[0].split()[1]
|
||||||
|
@ -237,12 +241,12 @@ def collect_device_health_self_assessment(device):
|
||||||
Yields:
|
Yields:
|
||||||
(Metric) Device health self assessment.
|
(Metric) Device health self assessment.
|
||||||
"""
|
"""
|
||||||
out = smart_ctl(
|
out = smart_ctl('--health', *device.smartctl_select())
|
||||||
'--health', *device.smartctl_select()
|
|
||||||
).strip().split('\n')
|
|
||||||
|
|
||||||
self_assessment_passed = \
|
if self_test_re.search(out):
|
||||||
out[4].endswith('PASSED') or out[4].endswith('OK')
|
self_assessment_passed = True
|
||||||
|
else:
|
||||||
|
self_assessment_passed = False
|
||||||
|
|
||||||
yield Metric(
|
yield Metric(
|
||||||
'device_smart_healthy', device.base_labels, self_assessment_passed)
|
'device_smart_healthy', device.base_labels, self_assessment_passed)
|
||||||
|
@ -372,4 +376,3 @@ def main():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue