diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_ntp_peer.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index 49cb1008..d4e5fd9a 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
@@ -46,21 +46,20 @@ const char *email = "devel@monitoring-plugins.org"; | |||
46 | static char *server_address=NULL; | 46 | static char *server_address=NULL; |
47 | static int port=123; | 47 | static int port=123; |
48 | static int verbose=0; | 48 | static int verbose=0; |
49 | static int quiet=0; | 49 | static bool quiet = false; |
50 | static short do_offset=0; | ||
51 | static char *owarn="60"; | 50 | static char *owarn="60"; |
52 | static char *ocrit="120"; | 51 | static char *ocrit="120"; |
53 | static short do_stratum=0; | 52 | static bool do_stratum = false; |
54 | static char *swarn="-1:16"; | 53 | static char *swarn="-1:16"; |
55 | static char *scrit="-1:16"; | 54 | static char *scrit="-1:16"; |
56 | static short do_jitter=0; | 55 | static bool do_jitter = false; |
57 | static char *jwarn="-1:5000"; | 56 | static char *jwarn="-1:5000"; |
58 | static char *jcrit="-1:10000"; | 57 | static char *jcrit="-1:10000"; |
59 | static short do_truechimers=0; | 58 | static bool do_truechimers = false; |
60 | static char *twarn="0:"; | 59 | static char *twarn="0:"; |
61 | static char *tcrit="0:"; | 60 | static char *tcrit="0:"; |
62 | static int syncsource_found=0; | 61 | static bool syncsource_found = false; |
63 | static int li_alarm=0; | 62 | static bool li_alarm = false; |
64 | 63 | ||
65 | int process_arguments (int, char **); | 64 | int process_arguments (int, char **); |
66 | thresholds *offset_thresholds = NULL; | 65 | thresholds *offset_thresholds = NULL; |
@@ -254,7 +253,7 @@ int ntp_request(double *offset, int *offset_result, double *jitter, int *stratum | |||
254 | die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); | 253 | die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); |
255 | } while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1)); | 254 | } while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1)); |
256 | 255 | ||
257 | if (LI(req.flags) == LI_ALARM) li_alarm = 1; | 256 | if (LI(req.flags) == LI_ALARM) li_alarm = true; |
258 | /* Each peer identifier is 4 bytes in the data section, which | 257 | /* Each peer identifier is 4 bytes in the data section, which |
259 | * we represent as a ntp_assoc_status_pair datatype. | 258 | * we represent as a ntp_assoc_status_pair datatype. |
260 | */ | 259 | */ |
@@ -276,7 +275,7 @@ int ntp_request(double *offset, int *offset_result, double *jitter, int *stratum | |||
276 | if(PEER_SEL(peers[i].status) >= PEER_INCLUDED){ | 275 | if(PEER_SEL(peers[i].status) >= PEER_INCLUDED){ |
277 | num_candidates++; | 276 | num_candidates++; |
278 | if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){ | 277 | if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){ |
279 | syncsource_found=1; | 278 | syncsource_found = true; |
280 | min_peer_sel=PEER_SYNCSOURCE; | 279 | min_peer_sel=PEER_SYNCSOURCE; |
281 | } | 280 | } |
282 | } | 281 | } |
@@ -440,7 +439,7 @@ int process_arguments(int argc, char **argv){ | |||
440 | if (argc < 2) | 439 | if (argc < 2) |
441 | usage ("\n"); | 440 | usage ("\n"); |
442 | 441 | ||
443 | while (1) { | 442 | while (true) { |
444 | c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:m:n:t:H:p:", longopts, &option); | 443 | c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:m:n:t:H:p:", longopts, &option); |
445 | if (c == -1 || c == EOF || c == 1) | 444 | if (c == -1 || c == EOF || c == 1) |
446 | break; | 445 | break; |
@@ -458,42 +457,40 @@ int process_arguments(int argc, char **argv){ | |||
458 | verbose++; | 457 | verbose++; |
459 | break; | 458 | break; |
460 | case 'q': | 459 | case 'q': |
461 | quiet = 1; | 460 | quiet = true; |
462 | break; | 461 | break; |
463 | case 'w': | 462 | case 'w': |
464 | do_offset=1; | ||
465 | owarn = optarg; | 463 | owarn = optarg; |
466 | break; | 464 | break; |
467 | case 'c': | 465 | case 'c': |
468 | do_offset=1; | ||
469 | ocrit = optarg; | 466 | ocrit = optarg; |
470 | break; | 467 | break; |
471 | case 'W': | 468 | case 'W': |
472 | do_stratum=1; | 469 | do_stratum = true; |
473 | swarn = optarg; | 470 | swarn = optarg; |
474 | break; | 471 | break; |
475 | case 'C': | 472 | case 'C': |
476 | do_stratum=1; | 473 | do_stratum = true; |
477 | scrit = optarg; | 474 | scrit = optarg; |
478 | break; | 475 | break; |
479 | case 'j': | 476 | case 'j': |
480 | do_jitter=1; | 477 | do_jitter = true; |
481 | jwarn = optarg; | 478 | jwarn = optarg; |
482 | break; | 479 | break; |
483 | case 'k': | 480 | case 'k': |
484 | do_jitter=1; | 481 | do_jitter = true; |
485 | jcrit = optarg; | 482 | jcrit = optarg; |
486 | break; | 483 | break; |
487 | case 'm': | 484 | case 'm': |
488 | do_truechimers=1; | 485 | do_truechimers = true; |
489 | twarn = optarg; | 486 | twarn = optarg; |
490 | break; | 487 | break; |
491 | case 'n': | 488 | case 'n': |
492 | do_truechimers=1; | 489 | do_truechimers = true; |
493 | tcrit = optarg; | 490 | tcrit = optarg; |
494 | break; | 491 | break; |
495 | case 'H': | 492 | case 'H': |
496 | if(is_host(optarg) == FALSE) | 493 | if(!is_host(optarg)) |
497 | usage2(_("Invalid hostname/address"), optarg); | 494 | usage2(_("Invalid hostname/address"), optarg); |
498 | server_address = strdup(optarg); | 495 | server_address = strdup(optarg); |
499 | break; | 496 | break; |
@@ -530,9 +527,9 @@ int process_arguments(int argc, char **argv){ | |||
530 | char *perfd_offset (double offset) | 527 | char *perfd_offset (double offset) |
531 | { | 528 | { |
532 | return fperfdata ("offset", offset, "s", | 529 | return fperfdata ("offset", offset, "s", |
533 | TRUE, offset_thresholds->warning->end, | 530 | true, offset_thresholds->warning->end, |
534 | TRUE, offset_thresholds->critical->end, | 531 | true, offset_thresholds->critical->end, |
535 | FALSE, 0, FALSE, 0); | 532 | false, 0, false, 0); |
536 | } | 533 | } |
537 | 534 | ||
538 | char *perfd_jitter (double jitter) | 535 | char *perfd_jitter (double jitter) |
@@ -540,7 +537,7 @@ char *perfd_jitter (double jitter) | |||
540 | return fperfdata ("jitter", jitter, "", | 537 | return fperfdata ("jitter", jitter, "", |
541 | do_jitter, jitter_thresholds->warning->end, | 538 | do_jitter, jitter_thresholds->warning->end, |
542 | do_jitter, jitter_thresholds->critical->end, | 539 | do_jitter, jitter_thresholds->critical->end, |
543 | TRUE, 0, FALSE, 0); | 540 | true, 0, false, 0); |
544 | } | 541 | } |
545 | 542 | ||
546 | char *perfd_stratum (int stratum) | 543 | char *perfd_stratum (int stratum) |
@@ -548,7 +545,7 @@ char *perfd_stratum (int stratum) | |||
548 | return perfdata ("stratum", stratum, "", | 545 | return perfdata ("stratum", stratum, "", |
549 | do_stratum, (int)stratum_thresholds->warning->end, | 546 | do_stratum, (int)stratum_thresholds->warning->end, |
550 | do_stratum, (int)stratum_thresholds->critical->end, | 547 | do_stratum, (int)stratum_thresholds->critical->end, |
551 | TRUE, 0, TRUE, 16); | 548 | true, 0, true, 16); |
552 | } | 549 | } |
553 | 550 | ||
554 | char *perfd_truechimers (int num_truechimers) | 551 | char *perfd_truechimers (int num_truechimers) |
@@ -556,7 +553,7 @@ char *perfd_truechimers (int num_truechimers) | |||
556 | return perfdata ("truechimers", num_truechimers, "", | 553 | return perfdata ("truechimers", num_truechimers, "", |
557 | do_truechimers, (int)truechimer_thresholds->warning->end, | 554 | do_truechimers, (int)truechimer_thresholds->warning->end, |
558 | do_truechimers, (int)truechimer_thresholds->critical->end, | 555 | do_truechimers, (int)truechimer_thresholds->critical->end, |
559 | TRUE, 0, FALSE, 0); | 556 | true, 0, false, 0); |
560 | } | 557 | } |
561 | 558 | ||
562 | int main(int argc, char *argv[]){ | 559 | int main(int argc, char *argv[]){ |
@@ -590,10 +587,10 @@ int main(int argc, char *argv[]){ | |||
590 | 587 | ||
591 | if(offset_result == STATE_UNKNOWN) { | 588 | if(offset_result == STATE_UNKNOWN) { |
592 | /* if there's no sync peer (this overrides ntp_request output): */ | 589 | /* if there's no sync peer (this overrides ntp_request output): */ |
593 | result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL); | 590 | result = (quiet ? STATE_UNKNOWN : STATE_CRITICAL); |
594 | } else { | 591 | } else { |
595 | /* Be quiet if there's no candidates either */ | 592 | /* Be quiet if there's no candidates either */ |
596 | if (quiet == 1 && result == STATE_WARNING) | 593 | if (quiet && result == STATE_WARNING) |
597 | result = STATE_UNKNOWN; | 594 | result = STATE_UNKNOWN; |
598 | result = max_state_alt(result, get_status(fabs(offset), offset_thresholds)); | 595 | result = max_state_alt(result, get_status(fabs(offset), offset_thresholds)); |
599 | } | 596 | } |