Module: monitoring-plugins
Branch: master
Commit: 99351f0560a5f457e499417366bdfdec0172a428
Author: Lorenz Kästle <[email protected]>
Date: Wed Nov 5 11:54:34 2025 +0100
URL:
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=99351f05
check_ntp_peer: fix several missing things and errors
---
plugins/check_ntp_peer.c | 16 ++++++++++++++--
plugins/check_ntp_peer.d/config.h | 5 +++--
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index 68b2fa9c..032f8ea4 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -689,6 +689,7 @@ int main(int argc, char *argv[]) {
/* if there's no sync peer (this overrides ntp_request output):
*/
sc_offset =
mp_set_subcheck_state(sc_offset, (config.quiet ?
STATE_UNKNOWN : STATE_CRITICAL));
+ xasprintf(&sc_offset.output, "%s unknown", sc_offset.output);
} else {
/* Be quiet if there's no candidates either */
mp_state_enum tmp = STATE_OK;
@@ -696,9 +697,14 @@ int main(int argc, char *argv[]) {
tmp = STATE_UNKNOWN;
}
+ xasprintf(&sc_offset.output, "%s: %.6fs", sc_offset.output,
ntp_res.offset);
+
mp_perfdata pd_offset = perfdata_init();
pd_offset.value = mp_create_pd_value(fabs(ntp_res.offset));
pd_offset = mp_pd_set_thresholds(pd_offset,
config.offset_thresholds);
+ pd_offset.label = "offset";
+ pd_offset.uom = "s";
+ mp_add_perfdata_to_subcheck(&sc_offset, pd_offset);
tmp = max_state_alt(tmp, mp_get_pd_status(pd_offset));
sc_offset = mp_set_subcheck_state(sc_offset, tmp);
@@ -708,12 +714,14 @@ int main(int argc, char *argv[]) {
// truechimers
if (config.do_truechimers) {
- mp_subcheck sc_truechimers;
+ mp_subcheck sc_truechimers = mp_subcheck_init();
xasprintf(&sc_truechimers.output, "truechimers: %i",
ntp_res.num_truechimers);
mp_perfdata pd_truechimers = perfdata_init();
pd_truechimers.value =
mp_create_pd_value(ntp_res.num_truechimers);
- mp_pd_set_thresholds(pd_truechimers,
config.truechimer_thresholds);
+ pd_truechimers.label = "truechimers";
+ pd_truechimers = mp_pd_set_thresholds(pd_truechimers,
config.truechimer_thresholds);
+
mp_add_perfdata_to_subcheck(&sc_truechimers, pd_truechimers);
sc_truechimers = mp_set_subcheck_state(sc_truechimers,
mp_get_pd_status(pd_truechimers));
@@ -728,6 +736,8 @@ int main(int argc, char *argv[]) {
mp_perfdata pd_stratum = perfdata_init();
pd_stratum.value = mp_create_pd_value(ntp_res.stratum);
pd_stratum = mp_pd_set_thresholds(pd_stratum,
config.stratum_thresholds);
+ pd_stratum.label = "stratum";
+
mp_add_perfdata_to_subcheck(&sc_stratum, pd_stratum);
sc_stratum = mp_set_subcheck_state(sc_stratum,
mp_get_pd_status(pd_stratum));
@@ -742,6 +752,8 @@ int main(int argc, char *argv[]) {
mp_perfdata pd_jitter = perfdata_init();
pd_jitter.value = mp_create_pd_value(ntp_res.jitter);
pd_jitter = mp_pd_set_thresholds(pd_jitter,
config.jitter_thresholds);
+ pd_jitter.label = "jitter";
+
mp_add_perfdata_to_subcheck(&sc_jitter, pd_jitter);
sc_jitter = mp_set_subcheck_state(sc_jitter,
mp_get_pd_status(pd_jitter));
diff --git a/plugins/check_ntp_peer.d/config.h
b/plugins/check_ntp_peer.d/config.h
index 396edea6..a6dd5c4c 100644
--- a/plugins/check_ntp_peer.d/config.h
+++ b/plugins/check_ntp_peer.d/config.h
@@ -66,10 +66,11 @@ check_ntp_peer_config check_ntp_peer_config_init() {
tmp.jitter_thresholds = mp_thresholds_set_crit(tmp.jitter_thresholds,
jitter_c_default);
mp_range offset_w_default = mp_range_init();
- offset_w_default = mp_range_set_start(offset_w_default,
mp_create_pd_value(60));
+ offset_w_default = mp_range_set_end(offset_w_default,
mp_create_pd_value(60));
tmp.offset_thresholds = mp_thresholds_set_warn(tmp.offset_thresholds,
offset_w_default);
+
mp_range offset_c_default = mp_range_init();
- offset_c_default = mp_range_set_start(offset_c_default,
mp_create_pd_value(120));
+ offset_c_default = mp_range_set_end(offset_c_default,
mp_create_pd_value(120));
tmp.offset_thresholds = mp_thresholds_set_crit(tmp.offset_thresholds,
offset_c_default);
return tmp;
}