summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-12 13:36:04 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-12 13:36:04 +0100
commitab2c2f525987dba8d314644d9eeeb48f9ae4d70c (patch)
tree70d52cbc7bf17209933d6ed92310793d55bd7391 /plugins
parentdbfd6568658869c017feb518e50c574f0b928d6f (diff)
downloadmonitoring-plugins-ab2c2f525987dba8d314644d9eeeb48f9ae4d70c.tar.gz
More refactoring
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_ntp_peer.c186
-rw-r--r--plugins/check_ntp_peer.d/config.h13
2 files changed, 109 insertions, 90 deletions
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index fcd06b8e..19e8a11f 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -35,6 +35,7 @@
35 * 35 *
36 *****************************************************************************/ 36 *****************************************************************************/
37 37
38#include "thresholds.h"
38const char *progname = "check_ntp_peer"; 39const char *progname = "check_ntp_peer";
39const char *copyright = "2006-2024"; 40const char *copyright = "2006-2024";
40const char *email = "devel@monitoring-plugins.org"; 41const char *email = "devel@monitoring-plugins.org";
@@ -54,10 +55,6 @@ typedef struct {
54 check_ntp_peer_config config; 55 check_ntp_peer_config config;
55} check_ntp_peer_config_wrapper; 56} check_ntp_peer_config_wrapper;
56static check_ntp_peer_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); 57static check_ntp_peer_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
57static thresholds *offset_thresholds = NULL;
58static thresholds *jitter_thresholds = NULL;
59static thresholds *stratum_thresholds = NULL;
60static thresholds *truechimer_thresholds = NULL;
61static void print_help(void); 58static void print_help(void);
62void print_usage(void); 59void print_usage(void);
63 60
@@ -149,25 +146,25 @@ typedef struct {
149 printf("%u.%u.%u.%u", (x >> 24) & 0xff, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); \ 146 printf("%u.%u.%u.%u", (x >> 24) & 0xff, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); \
150 } while (0); 147 } while (0);
151 148
152void print_ntp_control_message(const ntp_control_message *p) { 149void print_ntp_control_message(const ntp_control_message *message) {
153 printf("control packet contents:\n"); 150 printf("control packet contents:\n");
154 printf("\tflags: 0x%.2x , 0x%.2x\n", p->flags, p->op); 151 printf("\tflags: 0x%.2x , 0x%.2x\n", message->flags, message->op);
155 printf("\t li=%d (0x%.2x)\n", LI(p->flags), p->flags & LI_MASK); 152 printf("\t li=%d (0x%.2x)\n", LI(message->flags), message->flags & LI_MASK);
156 printf("\t vn=%d (0x%.2x)\n", VN(p->flags), p->flags & VN_MASK); 153 printf("\t vn=%d (0x%.2x)\n", VN(message->flags), message->flags & VN_MASK);
157 printf("\t mode=%d (0x%.2x)\n", MODE(p->flags), p->flags & MODE_MASK); 154 printf("\t mode=%d (0x%.2x)\n", MODE(message->flags), message->flags & MODE_MASK);
158 printf("\t response=%d (0x%.2x)\n", (p->op & REM_RESP) > 0, p->op & REM_RESP); 155 printf("\t response=%d (0x%.2x)\n", (message->op & REM_RESP) > 0, message->op & REM_RESP);
159 printf("\t more=%d (0x%.2x)\n", (p->op & REM_MORE) > 0, p->op & REM_MORE); 156 printf("\t more=%d (0x%.2x)\n", (message->op & REM_MORE) > 0, message->op & REM_MORE);
160 printf("\t error=%d (0x%.2x)\n", (p->op & REM_ERROR) > 0, p->op & REM_ERROR); 157 printf("\t error=%d (0x%.2x)\n", (message->op & REM_ERROR) > 0, message->op & REM_ERROR);
161 printf("\t op=%d (0x%.2x)\n", p->op & OP_MASK, p->op & OP_MASK); 158 printf("\t op=%d (0x%.2x)\n", message->op & OP_MASK, message->op & OP_MASK);
162 printf("\tsequence: %d (0x%.2x)\n", ntohs(p->seq), ntohs(p->seq)); 159 printf("\tsequence: %d (0x%.2x)\n", ntohs(message->seq), ntohs(message->seq));
163 printf("\tstatus: %d (0x%.2x)\n", ntohs(p->status), ntohs(p->status)); 160 printf("\tstatus: %d (0x%.2x)\n", ntohs(message->status), ntohs(message->status));
164 printf("\tassoc: %d (0x%.2x)\n", ntohs(p->assoc), ntohs(p->assoc)); 161 printf("\tassoc: %d (0x%.2x)\n", ntohs(message->assoc), ntohs(message->assoc));
165 printf("\toffset: %d (0x%.2x)\n", ntohs(p->offset), ntohs(p->offset)); 162 printf("\toffset: %d (0x%.2x)\n", ntohs(message->offset), ntohs(message->offset));
166 printf("\tcount: %d (0x%.2x)\n", ntohs(p->count), ntohs(p->count)); 163 printf("\tcount: %d (0x%.2x)\n", ntohs(message->count), ntohs(message->count));
167 164
168 int numpeers = ntohs(p->count) / (sizeof(ntp_assoc_status_pair)); 165 int numpeers = ntohs(message->count) / (sizeof(ntp_assoc_status_pair));
169 if (p->op & REM_RESP && p->op & OP_READSTAT) { 166 if (message->op & REM_RESP && message->op & OP_READSTAT) {
170 const ntp_assoc_status_pair *peer = (ntp_assoc_status_pair *)p->data; 167 const ntp_assoc_status_pair *peer = (ntp_assoc_status_pair *)message->data;
171 for (int i = 0; i < numpeers; i++) { 168 for (int i = 0; i < numpeers; i++) {
172 printf("\tpeer id %.2x status %.2x", ntohs(peer[i].assoc), ntohs(peer[i].status)); 169 printf("\tpeer id %.2x status %.2x", ntohs(peer[i].assoc), ntohs(peer[i].status));
173 if (PEER_SEL(peer[i].status) >= PEER_SYNCSOURCE) { 170 if (PEER_SEL(peer[i].status) >= PEER_SYNCSOURCE) {
@@ -182,13 +179,13 @@ void print_ntp_control_message(const ntp_control_message *p) {
182 } 179 }
183} 180}
184 181
185void setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq) { 182void setup_control_request(ntp_control_message *message, uint8_t opcode, uint16_t seq) {
186 memset(p, 0, sizeof(ntp_control_message)); 183 memset(message, 0, sizeof(ntp_control_message));
187 LI_SET(p->flags, LI_NOWARNING); 184 LI_SET(message->flags, LI_NOWARNING);
188 VN_SET(p->flags, VN_RESERVED); 185 VN_SET(message->flags, VN_RESERVED);
189 MODE_SET(p->flags, MODE_CONTROLMSG); 186 MODE_SET(message->flags, MODE_CONTROLMSG);
190 OP_SET(p->op, opcode); 187 OP_SET(message->op, opcode);
191 p->seq = htons(seq); 188 message->seq = htons(seq);
192 /* Remaining fields are zero for requests */ 189 /* Remaining fields are zero for requests */
193} 190}
194 191
@@ -203,11 +200,23 @@ void setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq)
203 * status is pretty much useless as syncsource_found is a global variable 200 * status is pretty much useless as syncsource_found is a global variable
204 * used later in main to check is the server was synchronized. It works 201 * used later in main to check is the server was synchronized. It works
205 * so I left it alone */ 202 * so I left it alone */
206mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, int *stratum, int *num_truechimers, 203typedef struct {
207 const check_ntp_peer_config config) { 204 mp_state_enum state;
208 *offset_result = STATE_UNKNOWN; 205 mp_state_enum offset_result;
209 *jitter = *stratum = -1; 206 double offset;
210 *num_truechimers = 0; 207 double jitter;
208 long stratum;
209 int num_truechimers;
210} ntp_request_result;
211ntp_request_result ntp_request(const check_ntp_peer_config config) {
212
213 ntp_request_result result = {
214 .state = STATE_OK,
215 .offset_result = STATE_UNKNOWN,
216 .jitter = -1,
217 .stratum = -1,
218 .num_truechimers = 0,
219 };
211 220
212 /* Long-winded explanation: 221 /* Long-winded explanation:
213 * Getting the sync peer offset, jitter and stratum requires a number of 222 * Getting the sync peer offset, jitter and stratum requires a number of
@@ -230,8 +239,8 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
230 void *tmp; 239 void *tmp;
231 ntp_assoc_status_pair *peers = NULL; 240 ntp_assoc_status_pair *peers = NULL;
232 int peer_offset = 0; 241 int peer_offset = 0;
233 int peers_size = 0; 242 size_t peers_size = 0;
234 int npeers = 0; 243 size_t npeers = 0;
235 int conn = -1; 244 int conn = -1;
236 my_udp_connect(config.server_address, config.port, &conn); 245 my_udp_connect(config.server_address, config.port, &conn);
237 246
@@ -269,7 +278,7 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
269 free(peers), die(STATE_UNKNOWN, "can not (re)allocate 'peers' buffer\n"); 278 free(peers), die(STATE_UNKNOWN, "can not (re)allocate 'peers' buffer\n");
270 } 279 }
271 peers = tmp; 280 peers = tmp;
272 memcpy((void *)((ptrdiff_t)peers + peer_offset), (void *)req.data, ntohs(req.count)); 281 memcpy((peers + peer_offset), (void *)req.data, ntohs(req.count));
273 npeers = peers_size / sizeof(ntp_assoc_status_pair); 282 npeers = peers_size / sizeof(ntp_assoc_status_pair);
274 peer_offset += ntohs(req.count); 283 peer_offset += ntohs(req.count);
275 } while (req.op & REM_MORE); 284 } while (req.op & REM_MORE);
@@ -277,9 +286,9 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
277 /* first, let's find out if we have a sync source, or if there are 286 /* first, let's find out if we have a sync source, or if there are
278 * at least some candidates. In the latter case we'll issue 287 * at least some candidates. In the latter case we'll issue
279 * a warning but go ahead with the check on them. */ 288 * a warning but go ahead with the check on them. */
280 for (int i = 0; i < npeers; i++) { 289 for (size_t i = 0; i < npeers; i++) {
281 if (PEER_SEL(peers[i].status) >= PEER_TRUECHIMER) { 290 if (PEER_SEL(peers[i].status) >= PEER_TRUECHIMER) {
282 (*num_truechimers)++; 291 result.num_truechimers++;
283 if (PEER_SEL(peers[i].status) >= PEER_INCLUDED) { 292 if (PEER_SEL(peers[i].status) >= PEER_INCLUDED) {
284 num_candidates++; 293 num_candidates++;
285 if (PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE) { 294 if (PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE) {
@@ -297,15 +306,14 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
297 printf("synchronization source found\n"); 306 printf("synchronization source found\n");
298 } 307 }
299 308
300 int status = STATE_OK;
301 if (!syncsource_found) { 309 if (!syncsource_found) {
302 status = STATE_WARNING; 310 result.state = STATE_WARNING;
303 if (verbose) { 311 if (verbose) {
304 printf("warning: no synchronization source found\n"); 312 printf("warning: no synchronization source found\n");
305 } 313 }
306 } 314 }
307 if (li_alarm) { 315 if (li_alarm) {
308 status = STATE_WARNING; 316 result.state = STATE_WARNING;
309 if (verbose) { 317 if (verbose) {
310 printf("warning: LI_ALARM bit is set\n"); 318 printf("warning: LI_ALARM bit is set\n");
311 } 319 }
@@ -313,7 +321,7 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
313 321
314 const char *getvar = "stratum,offset,jitter"; 322 const char *getvar = "stratum,offset,jitter";
315 char *data; 323 char *data;
316 for (int i = 0; i < npeers; i++) { 324 for (size_t i = 0; i < npeers; i++) {
317 /* Only query this server if it is the current sync source */ 325 /* Only query this server if it is the current sync source */
318 /* If there's no sync.peer, query all candidates and use the best one */ 326 /* If there's no sync.peer, query all candidates and use the best one */
319 if (PEER_SEL(peers[i].status) >= min_peer_sel) { 327 if (PEER_SEL(peers[i].status) >= min_peer_sel) {
@@ -396,9 +404,9 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
396 if (verbose) { 404 if (verbose) {
397 printf("%.10g\n", tmp_offset); 405 printf("%.10g\n", tmp_offset);
398 } 406 }
399 if (*offset_result == STATE_UNKNOWN || fabs(tmp_offset) < fabs(*offset)) { 407 if (result.offset_result == STATE_UNKNOWN || fabs(tmp_offset) < fabs(result.offset)) {
400 *offset = tmp_offset; 408 result.offset = tmp_offset;
401 *offset_result = STATE_OK; 409 result.offset_result = STATE_OK;
402 } else { 410 } else {
403 /* Skip this one; move to the next */ 411 /* Skip this one; move to the next */
404 continue; 412 continue;
@@ -415,16 +423,16 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
415 nptr = NULL; 423 nptr = NULL;
416 /* Convert the value if we have one */ 424 /* Convert the value if we have one */
417 if (value != NULL) { 425 if (value != NULL) {
418 *jitter = strtod(value, &nptr); 426 result.jitter = strtod(value, &nptr);
419 } 427 }
420 /* If value is null or no conversion was performed */ 428 /* If value is null or no conversion was performed */
421 if (value == NULL || value == nptr) { 429 if (value == NULL || value == nptr) {
422 if (verbose) { 430 if (verbose) {
423 printf("error: unable to read server jitter/dispersion response.\n"); 431 printf("error: unable to read server jitter/dispersion response.\n");
424 } 432 }
425 *jitter = -1; 433 result.jitter = -1;
426 } else if (verbose) { 434 } else if (verbose) {
427 printf("%.10g\n", *jitter); 435 printf("%.10g\n", result.jitter);
428 } 436 }
429 } 437 }
430 438
@@ -437,16 +445,16 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
437 nptr = NULL; 445 nptr = NULL;
438 /* Convert the value if we have one */ 446 /* Convert the value if we have one */
439 if (value != NULL) { 447 if (value != NULL) {
440 *stratum = strtol(value, &nptr, 10); 448 result.stratum = strtol(value, &nptr, 10);
441 } 449 }
442 if (value == NULL || value == nptr) { 450 if (value == NULL || value == nptr) {
443 if (verbose) { 451 if (verbose) {
444 printf("error: unable to read server stratum response.\n"); 452 printf("error: unable to read server stratum response.\n");
445 } 453 }
446 *stratum = -1; 454 result.stratum = -1;
447 } else { 455 } else {
448 if (verbose) { 456 if (verbose) {
449 printf("%i\n", *stratum); 457 printf("%li\n", result.stratum);
450 } 458 }
451 } 459 }
452 } 460 }
@@ -458,7 +466,7 @@ mp_state_enum ntp_request(double *offset, int *offset_result, double *jitter, in
458 free(peers); 466 free(peers);
459 } 467 }
460 468
461 return status; 469 return result;
462} 470}
463 471
464check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) { 472check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) {
@@ -564,25 +572,30 @@ check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) {
564 usage4(_("Hostname was not supplied")); 572 usage4(_("Hostname was not supplied"));
565 } 573 }
566 574
575 set_thresholds(&result.config.offset_thresholds, result.config.owarn, result.config.ocrit);
576 set_thresholds(&result.config.jitter_thresholds, result.config.jwarn, result.config.jcrit);
577 set_thresholds(&result.config.stratum_thresholds, result.config.swarn, result.config.scrit);
578 set_thresholds(&result.config.truechimer_thresholds, result.config.twarn, result.config.tcrit);
579
567 return result; 580 return result;
568} 581}
569 582
570char *perfd_offset(double offset) { 583char *perfd_offset(double offset, thresholds *offset_thresholds) {
571 return fperfdata("offset", offset, "s", true, offset_thresholds->warning->end, true, offset_thresholds->critical->end, false, 0, false, 584 return fperfdata("offset", offset, "s", true, offset_thresholds->warning->end, true, offset_thresholds->critical->end, false, 0, false,
572 0); 585 0);
573} 586}
574 587
575char *perfd_jitter(double jitter, bool do_jitter) { 588char *perfd_jitter(double jitter, bool do_jitter, thresholds *jitter_thresholds) {
576 return fperfdata("jitter", jitter, "", do_jitter, jitter_thresholds->warning->end, do_jitter, jitter_thresholds->critical->end, true, 0, 589 return fperfdata("jitter", jitter, "", do_jitter, jitter_thresholds->warning->end, do_jitter, jitter_thresholds->critical->end, true, 0,
577 false, 0); 590 false, 0);
578} 591}
579 592
580char *perfd_stratum(int stratum, bool do_stratum) { 593char *perfd_stratum(int stratum, bool do_stratum, thresholds *stratum_thresholds) {
581 return perfdata("stratum", stratum, "", do_stratum, (int)stratum_thresholds->warning->end, do_stratum, 594 return perfdata("stratum", stratum, "", do_stratum, (int)stratum_thresholds->warning->end, do_stratum,
582 (int)stratum_thresholds->critical->end, true, 0, true, 16); 595 (int)stratum_thresholds->critical->end, true, 0, true, 16);
583} 596}
584 597
585char *perfd_truechimers(int num_truechimers, const bool do_truechimers) { 598char *perfd_truechimers(int num_truechimers, const bool do_truechimers, thresholds *truechimer_thresholds) {
586 return perfdata("truechimers", num_truechimers, "", do_truechimers, (int)truechimer_thresholds->warning->end, do_truechimers, 599 return perfdata("truechimers", num_truechimers, "", do_truechimers, (int)truechimer_thresholds->warning->end, do_truechimers,
587 (int)truechimer_thresholds->critical->end, true, 0, false, 0); 600 (int)truechimer_thresholds->critical->end, true, 0, false, 0);
588} 601}
@@ -603,26 +616,17 @@ int main(int argc, char *argv[]) {
603 616
604 const check_ntp_peer_config config = tmp_config.config; 617 const check_ntp_peer_config config = tmp_config.config;
605 618
606 set_thresholds(&offset_thresholds, config.owarn, config.ocrit);
607 set_thresholds(&jitter_thresholds, config.jwarn, config.jcrit);
608 set_thresholds(&stratum_thresholds, config.swarn, config.scrit);
609 set_thresholds(&truechimer_thresholds, config.twarn, config.tcrit);
610
611 /* initialize alarm signal handling */ 619 /* initialize alarm signal handling */
612 signal(SIGALRM, socket_timeout_alarm_handler); 620 signal(SIGALRM, socket_timeout_alarm_handler);
613 621
614 /* set socket timeout */ 622 /* set socket timeout */
615 alarm(socket_timeout); 623 alarm(socket_timeout);
616 624
617 int offset_result;
618 int stratum;
619 int num_truechimers;
620 double offset = 0;
621 double jitter = 0;
622 /* This returns either OK or WARNING (See comment preceding ntp_request) */ 625 /* This returns either OK or WARNING (See comment preceding ntp_request) */
623 mp_state_enum result = ntp_request(&offset, &offset_result, &jitter, &stratum, &num_truechimers, config); 626 ntp_request_result ntp_res = ntp_request(config);
627 mp_state_enum result = STATE_UNKNOWN;
624 628
625 if (offset_result == STATE_UNKNOWN) { 629 if (ntp_res.offset_result == STATE_UNKNOWN) {
626 /* if there's no sync peer (this overrides ntp_request output): */ 630 /* if there's no sync peer (this overrides ntp_request output): */
627 result = (config.quiet ? STATE_UNKNOWN : STATE_CRITICAL); 631 result = (config.quiet ? STATE_UNKNOWN : STATE_CRITICAL);
628 } else { 632 } else {
@@ -630,28 +634,28 @@ int main(int argc, char *argv[]) {
630 if (config.quiet && result == STATE_WARNING) { 634 if (config.quiet && result == STATE_WARNING) {
631 result = STATE_UNKNOWN; 635 result = STATE_UNKNOWN;
632 } 636 }
633 result = max_state_alt(result, get_status(fabs(offset), offset_thresholds)); 637 result = max_state_alt(result, get_status(fabs(ntp_res.offset), config.offset_thresholds));
634 } 638 }
635 639
636 mp_state_enum oresult = result; 640 mp_state_enum oresult = result;
637 mp_state_enum tresult = STATE_UNKNOWN; 641 mp_state_enum tresult = STATE_UNKNOWN;
638 642
639 if (config.do_truechimers) { 643 if (config.do_truechimers) {
640 tresult = get_status(num_truechimers, truechimer_thresholds); 644 tresult = get_status(ntp_res.num_truechimers, config.truechimer_thresholds);
641 result = max_state_alt(result, tresult); 645 result = max_state_alt(result, tresult);
642 } 646 }
643 647
644 mp_state_enum sresult = STATE_UNKNOWN; 648 mp_state_enum sresult = STATE_UNKNOWN;
645 649
646 if (config.do_stratum) { 650 if (config.do_stratum) {
647 sresult = get_status(stratum, stratum_thresholds); 651 sresult = get_status((double)ntp_res.stratum, config.stratum_thresholds);
648 result = max_state_alt(result, sresult); 652 result = max_state_alt(result, sresult);
649 } 653 }
650 654
651 mp_state_enum jresult = STATE_UNKNOWN; 655 mp_state_enum jresult = STATE_UNKNOWN;
652 656
653 if (config.do_jitter) { 657 if (config.do_jitter) {
654 jresult = get_status(jitter, jitter_thresholds); 658 jresult = get_status(ntp_res.jitter, config.jitter_thresholds);
655 result = max_state_alt(result, jresult); 659 result = max_state_alt(result, jresult);
656 } 660 }
657 661
@@ -678,50 +682,52 @@ int main(int argc, char *argv[]) {
678 } 682 }
679 683
680 char *perfdata_line; 684 char *perfdata_line;
681 if (offset_result == STATE_UNKNOWN) { 685 if (ntp_res.offset_result == STATE_UNKNOWN) {
682 xasprintf(&result_line, "%s %s", result_line, _("Offset unknown")); 686 xasprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
683 xasprintf(&perfdata_line, ""); 687 xasprintf(&perfdata_line, "");
684 } else if (oresult == STATE_WARNING) { 688 } else if (oresult == STATE_WARNING) {
685 xasprintf(&result_line, "%s %s %.10g secs (WARNING)", result_line, _("Offset"), offset); 689 xasprintf(&result_line, "%s %s %.10g secs (WARNING)", result_line, _("Offset"), ntp_res.offset);
686 } else if (oresult == STATE_CRITICAL) { 690 } else if (oresult == STATE_CRITICAL) {
687 xasprintf(&result_line, "%s %s %.10g secs (CRITICAL)", result_line, _("Offset"), offset); 691 xasprintf(&result_line, "%s %s %.10g secs (CRITICAL)", result_line, _("Offset"), ntp_res.offset);
688 } else { 692 } else {
689 xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); 693 xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), ntp_res.offset);
690 } 694 }
691 xasprintf(&perfdata_line, "%s", perfd_offset(offset)); 695 xasprintf(&perfdata_line, "%s", perfd_offset(ntp_res.offset, config.offset_thresholds));
692 696
693 if (config.do_jitter) { 697 if (config.do_jitter) {
694 if (jresult == STATE_WARNING) { 698 if (jresult == STATE_WARNING) {
695 xasprintf(&result_line, "%s, jitter=%f (WARNING)", result_line, jitter); 699 xasprintf(&result_line, "%s, jitter=%f (WARNING)", result_line, ntp_res.jitter);
696 } else if (jresult == STATE_CRITICAL) { 700 } else if (jresult == STATE_CRITICAL) {
697 xasprintf(&result_line, "%s, jitter=%f (CRITICAL)", result_line, jitter); 701 xasprintf(&result_line, "%s, jitter=%f (CRITICAL)", result_line, ntp_res.jitter);
698 } else { 702 } else {
699 xasprintf(&result_line, "%s, jitter=%f", result_line, jitter); 703 xasprintf(&result_line, "%s, jitter=%f", result_line, ntp_res.jitter);
700 } 704 }
701 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter, config.do_jitter)); 705 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(ntp_res.jitter, config.do_jitter, config.jitter_thresholds));
702 } 706 }
703 707
704 if (config.do_stratum) { 708 if (config.do_stratum) {
705 if (sresult == STATE_WARNING) { 709 if (sresult == STATE_WARNING) {
706 xasprintf(&result_line, "%s, stratum=%i (WARNING)", result_line, stratum); 710 xasprintf(&result_line, "%s, stratum=%i (WARNING)", result_line, ntp_res.stratum);
707 } else if (sresult == STATE_CRITICAL) { 711 } else if (sresult == STATE_CRITICAL) {
708 xasprintf(&result_line, "%s, stratum=%i (CRITICAL)", result_line, stratum); 712 xasprintf(&result_line, "%s, stratum=%i (CRITICAL)", result_line, ntp_res.stratum);
709 } else { 713 } else {
710 xasprintf(&result_line, "%s, stratum=%i", result_line, stratum); 714 xasprintf(&result_line, "%s, stratum=%i", result_line, ntp_res.stratum);
711 } 715 }
712 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum, config.do_stratum)); 716 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(ntp_res.stratum, config.do_stratum, config.stratum_thresholds));
713 } 717 }
714 718
715 if (config.do_truechimers) { 719 if (config.do_truechimers) {
716 if (tresult == STATE_WARNING) { 720 if (tresult == STATE_WARNING) {
717 xasprintf(&result_line, "%s, truechimers=%i (WARNING)", result_line, num_truechimers); 721 xasprintf(&result_line, "%s, truechimers=%i (WARNING)", result_line, ntp_res.num_truechimers);
718 } else if (tresult == STATE_CRITICAL) { 722 } else if (tresult == STATE_CRITICAL) {
719 xasprintf(&result_line, "%s, truechimers=%i (CRITICAL)", result_line, num_truechimers); 723 xasprintf(&result_line, "%s, truechimers=%i (CRITICAL)", result_line, ntp_res.num_truechimers);
720 } else { 724 } else {
721 xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers); 725 xasprintf(&result_line, "%s, truechimers=%i", result_line, ntp_res.num_truechimers);
722 } 726 }
723 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers, config.do_truechimers)); 727 xasprintf(&perfdata_line, "%s %s", perfdata_line,
728 perfd_truechimers(ntp_res.num_truechimers, config.do_truechimers, config.truechimer_thresholds));
724 } 729 }
730
725 printf("%s|%s\n", result_line, perfdata_line); 731 printf("%s|%s\n", result_line, perfdata_line);
726 732
727 if (config.server_address != NULL) { 733 if (config.server_address != NULL) {
diff --git a/plugins/check_ntp_peer.d/config.h b/plugins/check_ntp_peer.d/config.h
index 1907af7c..00e6b05d 100644
--- a/plugins/check_ntp_peer.d/config.h
+++ b/plugins/check_ntp_peer.d/config.h
@@ -1,6 +1,7 @@
1#pragma once 1#pragma once
2 2
3#include "../../config.h" 3#include "../../config.h"
4#include "thresholds.h"
4#include <stddef.h> 5#include <stddef.h>
5 6
6enum { 7enum {
@@ -17,19 +18,24 @@ typedef struct {
17 bool do_truechimers; 18 bool do_truechimers;
18 char *twarn; 19 char *twarn;
19 char *tcrit; 20 char *tcrit;
21 thresholds *truechimer_thresholds;
20 22
21 char *owarn; 23 char *owarn;
22 char *ocrit; 24 char *ocrit;
25 thresholds *offset_thresholds;
23 26
24 // stratum stuff 27 // stratum stuff
25 bool do_stratum; 28 bool do_stratum;
26 char *swarn; 29 char *swarn;
27 char *scrit; 30 char *scrit;
31 thresholds *stratum_thresholds;
28 32
29 // jitter stuff 33 // jitter stuff
30 bool do_jitter; 34 bool do_jitter;
31 char *jwarn; 35 char *jwarn;
32 char *jcrit; 36 char *jcrit;
37 thresholds *jitter_thresholds;
38
33} check_ntp_peer_config; 39} check_ntp_peer_config;
34 40
35check_ntp_peer_config check_ntp_peer_config_init() { 41check_ntp_peer_config check_ntp_peer_config_init() {
@@ -41,14 +47,21 @@ check_ntp_peer_config check_ntp_peer_config_init() {
41 .do_truechimers = false, 47 .do_truechimers = false,
42 .twarn = "0:", 48 .twarn = "0:",
43 .tcrit = "0:", 49 .tcrit = "0:",
50 .truechimer_thresholds = NULL,
51
44 .owarn = "60", 52 .owarn = "60",
45 .ocrit = "120", 53 .ocrit = "120",
54 .offset_thresholds = NULL,
55
46 .do_stratum = false, 56 .do_stratum = false,
47 .swarn = "-1:16", 57 .swarn = "-1:16",
48 .scrit = "-1:16", 58 .scrit = "-1:16",
59 .stratum_thresholds = NULL,
60
49 .do_jitter = false, 61 .do_jitter = false,
50 .jwarn = "-1:5000", 62 .jwarn = "-1:5000",
51 .jcrit = "-1:10000", 63 .jcrit = "-1:10000",
64 .jitter_thresholds = NULL,
52 }; 65 };
53 return tmp; 66 return tmp;
54} 67}