aboutsummaryrefslogtreecommitdiff
path: root/text_collector_examples
diff options
context:
space:
mode:
authorEdgaras GiedrÄ— <edgaras.gie@gmail.com>2019-03-20 10:38:41 +0200
committerBen Kochie <superq@gmail.com>2019-03-20 09:38:41 +0100
commit2f87b7cba6d6eb729a78724335fd59e746fcdff4 (patch)
tree02922e9fe032b31cec724556eb3f47557c48732d /text_collector_examples
parentd2136aace052bef8bbdae930e7c41e2350e08055 (diff)
downloadprometheus_node_collector-2f87b7cba6d6eb729a78724335fd59e746fcdff4.tar.bz2
prometheus_node_collector-2f87b7cba6d6eb729a78724335fd59e746fcdff4.tar.xz
prometheus_node_collector-2f87b7cba6d6eb729a78724335fd59e746fcdff4.zip
Update smartmon.py to widen self_assessment_passed test (#1293)
Signed-off-by: EdgarasG <edgaras.giedre@hostinger.com>
Diffstat (limited to 'text_collector_examples')
-rwxr-xr-xtext_collector_examples/smartmon.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/text_collector_examples/smartmon.py b/text_collector_examples/smartmon.py
index 4eb1075..7dbf26e 100755
--- a/text_collector_examples/smartmon.py
+++ b/text_collector_examples/smartmon.py
@@ -5,14 +5,16 @@ import csv
5import datetime 5import datetime
6import decimal 6import decimal
7import re 7import re
8import subprocess
9import shlex 8import shlex
9import subprocess
10 10
11device_info_re = re.compile(r'^(?P<k>[^:]+?)(?:(?:\sis|):)\s*(?P<v>.*)$') 11device_info_re = re.compile(r'^(?P<k>[^:]+?)(?:(?:\sis|):)\s*(?P<v>.*)$')
12 12
13ata_error_count_re = re.compile( 13ata_error_count_re = re.compile(
14 r'^Error (\d+) \[\d+\] occurred', re.MULTILINE) 14 r'^Error (\d+) \[\d+\] occurred', re.MULTILINE)
15 15
16self_test_re = re.compile(r'^SMART.*(PASSED|OK)$', re.MULTILINE)
17
16device_info_map = { 18device_info_map = {
17 'Vendor': 'vendor', 19 'Vendor': 'vendor',
18 'Product': 'product', 20 'Product': 'product',
@@ -119,10 +121,12 @@ def smart_ctl(*args, check=True):
119 Returns: 121 Returns:
120 (str) Data piped to stdout by the smartctl subprocess. 122 (str) Data piped to stdout by the smartctl subprocess.
121 """ 123 """
122 return subprocess.run( 124 try:
123 ['smartctl', *args], stdout=subprocess.PIPE, check=check, 125 return subprocess.run(
124 ).stdout.decode('utf-8') 126 ['smartctl', *args], stdout=subprocess.PIPE, check=check
125 127 ).stdout.decode('utf-8')
128 except subprocess.CalledProcessError as e:
129 return e.output.decode('utf-8')
126 130
127def smart_ctl_version(): 131def smart_ctl_version():
128 return smart_ctl('-V').split('\n')[0].split()[1] 132 return smart_ctl('-V').split('\n')[0].split()[1]
@@ -237,12 +241,12 @@ def collect_device_health_self_assessment(device):
237 Yields: 241 Yields:
238 (Metric) Device health self assessment. 242 (Metric) Device health self assessment.
239 """ 243 """
240 out = smart_ctl( 244 out = smart_ctl('--health', *device.smartctl_select())
241 '--health', *device.smartctl_select()
242 ).strip().split('\n')
243 245
244 self_assessment_passed = \ 246 if self_test_re.search(out):
245 out[4].endswith('PASSED') or out[4].endswith('OK') 247 self_assessment_passed = True
248 else:
249 self_assessment_passed = False
246 250
247 yield Metric( 251 yield Metric(
248 'device_smart_healthy', device.base_labels, self_assessment_passed) 252 'device_smart_healthy', device.base_labels, self_assessment_passed)
@@ -372,4 +376,3 @@ def main():
372 376
373if __name__ == '__main__': 377if __name__ == '__main__':
374 main() 378 main()
375