summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-10-18 17:11:21 +0200
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-10-18 17:11:21 +0200
commita7e494192d222015bc098bfc3c7ed71e2e801590 (patch)
treec924ce6fcb754e3dfa249976e0ca1cb3247cab72 /plugins
parentca5af12f9475775179a599875bf7cf8d3296f02a (diff)
downloadmonitoring-plugins-a7e494192d222015bc098bfc3c7ed71e2e801590.tar.gz
check_ntp_peer: Use C99 booleans
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_ntp_peer.c53
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";
46static char *server_address=NULL; 46static char *server_address=NULL;
47static int port=123; 47static int port=123;
48static int verbose=0; 48static int verbose=0;
49static int quiet=0; 49static bool quiet = false;
50static short do_offset=0;
51static char *owarn="60"; 50static char *owarn="60";
52static char *ocrit="120"; 51static char *ocrit="120";
53static short do_stratum=0; 52static bool do_stratum = false;
54static char *swarn="-1:16"; 53static char *swarn="-1:16";
55static char *scrit="-1:16"; 54static char *scrit="-1:16";
56static short do_jitter=0; 55static bool do_jitter = false;
57static char *jwarn="-1:5000"; 56static char *jwarn="-1:5000";
58static char *jcrit="-1:10000"; 57static char *jcrit="-1:10000";
59static short do_truechimers=0; 58static bool do_truechimers = false;
60static char *twarn="0:"; 59static char *twarn="0:";
61static char *tcrit="0:"; 60static char *tcrit="0:";
62static int syncsource_found=0; 61static bool syncsource_found = false;
63static int li_alarm=0; 62static bool li_alarm = false;
64 63
65int process_arguments (int, char **); 64int process_arguments (int, char **);
66thresholds *offset_thresholds = NULL; 65thresholds *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){
530char *perfd_offset (double offset) 527char *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
538char *perfd_jitter (double jitter) 535char *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
546char *perfd_stratum (int stratum) 543char *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
554char *perfd_truechimers (int num_truechimers) 551char *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
562int main(int argc, char *argv[]){ 559int 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 }