More checks against format-changes in chronyc, dict exception handling fixed.
Dominik Schloesser committed
Sep 2, 2017 at 13:14 UTC
65ed2942ec3f302adb6520498858f7bea98d88fe
1 file changed
+4
-3
python.d/chrony.chart.py
+4
-3
@@ -81,8 +81,9 @@ class Service(ExecutableService):
81
chrony_dict = {}
82
for line in lines[1:]:
83
lparts = line.split(':', 1)
84
- value = lparts[1].strip().split(' ')[0]
85
- chrony_dict[lparts[0].strip()] = value
84
+ if (len(lparts) > 1):
85
+ value = lparts[1].strip().split(' ')[0]
86
+ chrony_dict[lparts[0].strip()] = value
87
return {'timediff': int(float(chrony_dict['System time']) * 1e9),
88
'lastoffset': int(float(chrony_dict['Last offset']) * 1e9),
89
'rmsoffset': int(float(chrony_dict['RMS offset']) * 1e9),
@@ -95,6 +96,6 @@ class Service(ExecutableService):
96
else:
97
self.error("No valid chronyc output")
98
return None
98
- except (ValueError, AttributeError):
99
+ except (ValueError, AttributeError, KeyError):
100
self.error("Chronyc data parser exception")
101
return None