diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2007-12-04 12:08:34 +0000 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2007-12-04 12:08:34 +0000 |
commit | d358f1cc95a4c75b8ab443b9e5ce0c5b8b3c8d43 (patch) | |
tree | 0c4afa08b2c53c9fb782bb16f6a2f26e5073f44a /plugins/check_ntp_peer.c | |
parent | 6157cdf6e514b23ee20e2bde67eb62757bcdd2f2 (diff) | |
download | monitoring-plugins-d358f1cc95a4c75b8ab443b9e5ce0c5b8b3c8d43.tar.gz |
Add a quiet mode to avoid notification when NTP server isn't sync (check_ntp_peer and heck_ntp_time)
Fix default jitter and stratum ranges not including -1
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/branches/dermoth_ntp_rework@1840 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_ntp_peer.c')
-rw-r--r-- | plugins/check_ntp_peer.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index edef66a8..83fa8aba 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
@@ -52,15 +52,16 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
52 | 52 | ||
53 | static char *server_address=NULL; | 53 | static char *server_address=NULL; |
54 | static int verbose=0; | 54 | static int verbose=0; |
55 | static int quiet=0; | ||
55 | static short do_offset=0; | 56 | static short do_offset=0; |
56 | static char *owarn="60"; | 57 | static char *owarn="60"; |
57 | static char *ocrit="120"; | 58 | static char *ocrit="120"; |
58 | static short do_stratum=0; | 59 | static short do_stratum=0; |
59 | static char *swarn="16"; | 60 | static char *swarn="-1:16"; |
60 | static char *scrit="16"; | 61 | static char *scrit="-1:16"; |
61 | static short do_jitter=0; | 62 | static short do_jitter=0; |
62 | static char *jwarn="5000"; | 63 | static char *jwarn="-1:5000"; |
63 | static char *jcrit="10000"; | 64 | static char *jcrit="-1:10000"; |
64 | static int syncsource_found=0; | 65 | static int syncsource_found=0; |
65 | 66 | ||
66 | int process_arguments (int, char **); | 67 | int process_arguments (int, char **); |
@@ -358,7 +359,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
358 | if(value == NULL || value==nptr) { | 359 | if(value == NULL || value==nptr) { |
359 | if(verbose) printf("error: unable to read server offset response.\n"); | 360 | if(verbose) printf("error: unable to read server offset response.\n"); |
360 | } else { | 361 | } else { |
361 | if(verbose) printf("%g\n", *offset); | 362 | if(verbose) printf("%.10g\n", tmp_offset); |
362 | if(*offset_result == STATE_UNKNOWN || fabs(tmp_offset) < fabs(*offset)) { | 363 | if(*offset_result == STATE_UNKNOWN || fabs(tmp_offset) < fabs(*offset)) { |
363 | *offset = tmp_offset; | 364 | *offset = tmp_offset; |
364 | *offset_result = STATE_OK; | 365 | *offset_result = STATE_OK; |
@@ -379,11 +380,11 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
379 | if(value != NULL) | 380 | if(value != NULL) |
380 | *jitter = strtod(value, &nptr); | 381 | *jitter = strtod(value, &nptr); |
381 | /* If value is null or no conversion was performed */ | 382 | /* If value is null or no conversion was performed */ |
382 | if(value == NULL || value==nptr){ | 383 | if(value == NULL || value==nptr) { |
383 | if(verbose) printf("error: unable to read server jitter/dispersion response.\n"); | 384 | if(verbose) printf("error: unable to read server jitter/dispersion response.\n"); |
384 | *jitter = -1; | 385 | *jitter = -1; |
385 | } else { | 386 | } else if(verbose) { |
386 | if(verbose) printf("%g\n", *jitter); | 387 | printf("%.10g\n", *jitter); |
387 | } | 388 | } |
388 | } | 389 | } |
389 | 390 | ||
@@ -397,7 +398,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
397 | /* Convert the value if we have one */ | 398 | /* Convert the value if we have one */ |
398 | if(value != NULL) | 399 | if(value != NULL) |
399 | *stratum = strtol(value, &nptr, 10); | 400 | *stratum = strtol(value, &nptr, 10); |
400 | if(value == NULL || value==nptr){ | 401 | if(value == NULL || value==nptr) { |
401 | if(verbose) printf("error: unable to read server stratum response.\n"); | 402 | if(verbose) printf("error: unable to read server stratum response.\n"); |
402 | *stratum = -1; | 403 | *stratum = -1; |
403 | } else { | 404 | } else { |
@@ -422,6 +423,7 @@ int process_arguments(int argc, char **argv){ | |||
422 | {"verbose", no_argument, 0, 'v'}, | 423 | {"verbose", no_argument, 0, 'v'}, |
423 | {"use-ipv4", no_argument, 0, '4'}, | 424 | {"use-ipv4", no_argument, 0, '4'}, |
424 | {"use-ipv6", no_argument, 0, '6'}, | 425 | {"use-ipv6", no_argument, 0, '6'}, |
426 | {"quiet", no_argument, 0, 'q'}, | ||
425 | {"warning", required_argument, 0, 'w'}, | 427 | {"warning", required_argument, 0, 'w'}, |
426 | {"critical", required_argument, 0, 'c'}, | 428 | {"critical", required_argument, 0, 'c'}, |
427 | {"swarn", required_argument, 0, 'W'}, | 429 | {"swarn", required_argument, 0, 'W'}, |
@@ -438,7 +440,7 @@ int process_arguments(int argc, char **argv){ | |||
438 | usage ("\n"); | 440 | usage ("\n"); |
439 | 441 | ||
440 | while (1) { | 442 | while (1) { |
441 | c = getopt_long (argc, argv, "Vhv46w:c:W:C:j:k:t:H:", longopts, &option); | 443 | c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:t:H:", longopts, &option); |
442 | if (c == -1 || c == EOF || c == 1) | 444 | if (c == -1 || c == EOF || c == 1) |
443 | break; | 445 | break; |
444 | 446 | ||
@@ -454,6 +456,9 @@ int process_arguments(int argc, char **argv){ | |||
454 | case 'v': | 456 | case 'v': |
455 | verbose++; | 457 | verbose++; |
456 | break; | 458 | break; |
459 | case 'q': | ||
460 | quiet = 1; | ||
461 | break; | ||
457 | case 'w': | 462 | case 'w': |
458 | do_offset=1; | 463 | do_offset=1; |
459 | owarn = optarg; | 464 | owarn = optarg; |
@@ -520,7 +525,7 @@ char *perfd_offset (double offset) | |||
520 | 525 | ||
521 | char *perfd_jitter (double jitter) | 526 | char *perfd_jitter (double jitter) |
522 | { | 527 | { |
523 | return fperfdata ("jitter", jitter, "s", | 528 | return fperfdata ("jitter", jitter, "", |
524 | do_jitter, jitter_thresholds->warning->end, | 529 | do_jitter, jitter_thresholds->warning->end, |
525 | do_jitter, jitter_thresholds->critical->end, | 530 | do_jitter, jitter_thresholds->critical->end, |
526 | TRUE, 0, FALSE, 0); | 531 | TRUE, 0, FALSE, 0); |
@@ -554,10 +559,16 @@ int main(int argc, char *argv[]){ | |||
554 | 559 | ||
555 | /* This returns either OK or WARNING (See comment preceeding ntp_request) */ | 560 | /* This returns either OK or WARNING (See comment preceeding ntp_request) */ |
556 | result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum); | 561 | result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum); |
557 | if(offset_result == STATE_UNKNOWN) | ||
558 | result = STATE_CRITICAL; | ||
559 | 562 | ||
560 | result = max_state_alt(result, get_status(fabs(offset), offset_thresholds)); | 563 | if(offset_result == STATE_UNKNOWN) { |
564 | /* if there's no sync peer (this overrides ntp_request output): */ | ||
565 | result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL); | ||
566 | } else { | ||
567 | /* Be quiet if there's no candidates either */ | ||
568 | if (quiet == 1 && result == STATE_WARNING) | ||
569 | result = STATE_UNKNOWN; | ||
570 | result = max_state_alt(result, get_status(fabs(offset), offset_thresholds)); | ||
571 | } | ||
561 | 572 | ||
562 | if(do_stratum) | 573 | if(do_stratum) |
563 | result = max_state_alt(result, get_status(stratum, stratum_thresholds)); | 574 | result = max_state_alt(result, get_status(stratum, stratum_thresholds)); |
@@ -618,6 +629,8 @@ void print_help(void){ | |||
618 | print_usage(); | 629 | print_usage(); |
619 | printf (_(UT_HELP_VRSN)); | 630 | printf (_(UT_HELP_VRSN)); |
620 | printf (_(UT_HOST_PORT), 'p', "123"); | 631 | printf (_(UT_HOST_PORT), 'p', "123"); |
632 | printf (" %s\n", "-q, --quiet"); | ||
633 | printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized")); | ||
621 | printf (" %s\n", "-w, --warning=THRESHOLD"); | 634 | printf (" %s\n", "-w, --warning=THRESHOLD"); |
622 | printf (" %s\n", _("Offset to result in warning status (seconds)")); | 635 | printf (" %s\n", _("Offset to result in warning status (seconds)")); |
623 | printf (" %s\n", "-c, --critical=THRESHOLD"); | 636 | printf (" %s\n", "-c, --critical=THRESHOLD"); |