@@ -230,65 +230,68 @@ def _check_thresholds(self, ntp_info: Dict, thresholds: Dict) -> tuple:
230230 offset = float (ntp_info ["synced_offset" ])
231231 offset_text = f"Offset { ntp_info ['synced_offset' ]} secs"
232232
233- if thresholds ["offset_critical" ] is not None :
234- if abs (offset ) >= thresholds ["offset_critical" ]:
235- worst_status = STATE_CRITICAL
236- offset_text += " (CRITICAL)"
237- elif thresholds ["offset_warning" ] is not None :
238- if abs (offset ) >= thresholds ["offset_warning" ]:
239- worst_status = STATE_WARNING
240- offset_text += " (WARNING)"
233+ if (
234+ thresholds ["offset_critical" ] is not None
235+ and abs (offset ) >= thresholds ["offset_critical" ]
236+ ):
237+ worst_status = STATE_CRITICAL
238+ offset_text += " (CRITICAL)"
239+ elif (
240+ thresholds ["offset_warning" ] is not None and abs (offset ) >= thresholds ["offset_warning" ]
241+ ):
242+ worst_status = STATE_WARNING
243+ offset_text += " (WARNING)"
241244
242245 messages .append (offset_text )
243246
244247 # Check jitter
245248 jitter = ntp_info ["synced_jitter" ]
246249 jitter_text = f"jitter={ jitter } "
247250
248- if thresholds ["jitter_critical" ] is not None :
249- if jitter >= thresholds ["jitter_critical" ]:
250- if worst_status != STATE_CRITICAL :
251- worst_status = STATE_CRITICAL
252- jitter_text += " (CRITICAL)"
253- elif thresholds ["jitter_warning" ] is not None :
254- if jitter >= thresholds ["jitter_warning" ]:
255- if worst_status == STATE_OK :
256- worst_status = STATE_WARNING
257- jitter_text += " (WARNING)"
251+ if thresholds ["jitter_critical" ] is not None and jitter >= thresholds ["jitter_critical" ]:
252+ if worst_status != STATE_CRITICAL :
253+ worst_status = STATE_CRITICAL
254+ jitter_text += " (CRITICAL)"
255+ elif thresholds ["jitter_warning" ] is not None and jitter >= thresholds ["jitter_warning" ]:
256+ if worst_status == STATE_OK :
257+ worst_status = STATE_WARNING
258+ jitter_text += " (WARNING)"
258259
259260 messages .append (jitter_text )
260261
261262 # Check stratum (higher is worse)
262263 stratum = ntp_info ["synced_stratum" ]
263264 stratum_text = f"stratum={ stratum } "
264265
265- if thresholds ["stratum_critical" ] is not None :
266- if stratum > thresholds ["stratum_critical" ]:
267- if worst_status != STATE_CRITICAL :
268- worst_status = STATE_CRITICAL
269- stratum_text += " (CRITICAL)"
270- elif thresholds ["stratum_warning" ] is not None :
271- if stratum > thresholds ["stratum_warning" ]:
272- if worst_status == STATE_OK :
273- worst_status = STATE_WARNING
274- stratum_text += " (WARNING)"
266+ if thresholds ["stratum_critical" ] is not None and stratum > thresholds ["stratum_critical" ]:
267+ if worst_status != STATE_CRITICAL :
268+ worst_status = STATE_CRITICAL
269+ stratum_text += " (CRITICAL)"
270+ elif thresholds ["stratum_warning" ] is not None and stratum > thresholds ["stratum_warning" ]:
271+ if worst_status == STATE_OK :
272+ worst_status = STATE_WARNING
273+ stratum_text += " (WARNING)"
275274
276275 messages .append (stratum_text )
277276
278277 # Check truechimers (lower is worse)
279278 truechimers = ntp_info ["truechimers" ]
280279 truechimers_text = f"truechimers={ truechimers } "
281280
282- if thresholds ["truechimers_critical" ] is not None :
283- if truechimers <= thresholds ["truechimers_critical" ]:
284- if worst_status != STATE_CRITICAL :
285- worst_status = STATE_CRITICAL
286- truechimers_text += " (CRITICAL)"
287- elif thresholds ["truechimers_warning" ] is not None :
288- if truechimers <= thresholds ["truechimers_warning" ]:
289- if worst_status == STATE_OK :
290- worst_status = STATE_WARNING
291- truechimers_text += " (WARNING)"
281+ if (
282+ thresholds ["truechimers_critical" ] is not None
283+ and truechimers <= thresholds ["truechimers_critical" ]
284+ ):
285+ if worst_status != STATE_CRITICAL :
286+ worst_status = STATE_CRITICAL
287+ truechimers_text += " (CRITICAL)"
288+ elif (
289+ thresholds ["truechimers_warning" ] is not None
290+ and truechimers <= thresholds ["truechimers_warning" ]
291+ ):
292+ if worst_status == STATE_OK :
293+ worst_status = STATE_WARNING
294+ truechimers_text += " (WARNING)"
292295
293296 messages .append (truechimers_text )
294297
0 commit comments