summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_ntp_peer.c41
-rw-r--r--plugins/check_ntp_time.c11
2 files changed, 36 insertions, 16 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
53static char *server_address=NULL; 53static char *server_address=NULL;
54static int verbose=0; 54static int verbose=0;
55static int quiet=0;
55static short do_offset=0; 56static short do_offset=0;
56static char *owarn="60"; 57static char *owarn="60";
57static char *ocrit="120"; 58static char *ocrit="120";
58static short do_stratum=0; 59static short do_stratum=0;
59static char *swarn="16"; 60static char *swarn="-1:16";
60static char *scrit="16"; 61static char *scrit="-1:16";
61static short do_jitter=0; 62static short do_jitter=0;
62static char *jwarn="5000"; 63static char *jwarn="-1:5000";
63static char *jcrit="10000"; 64static char *jcrit="-1:10000";
64static int syncsource_found=0; 65static int syncsource_found=0;
65 66
66int process_arguments (int, char **); 67int 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
521char *perfd_jitter (double jitter) 526char *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");
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c
index 85015d65..042d3037 100644
--- a/plugins/check_ntp_time.c
+++ b/plugins/check_ntp_time.c
@@ -51,6 +51,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
51 51
52static char *server_address=NULL; 52static char *server_address=NULL;
53static int verbose=0; 53static int verbose=0;
54static int quiet=0;
54static char *owarn="60"; 55static char *owarn="60";
55static char *ocrit="120"; 56static char *ocrit="120";
56 57
@@ -450,6 +451,7 @@ int process_arguments(int argc, char **argv){
450 {"verbose", no_argument, 0, 'v'}, 451 {"verbose", no_argument, 0, 'v'},
451 {"use-ipv4", no_argument, 0, '4'}, 452 {"use-ipv4", no_argument, 0, '4'},
452 {"use-ipv6", no_argument, 0, '6'}, 453 {"use-ipv6", no_argument, 0, '6'},
454 {"quiet", no_argument, 0, 'q'},
453 {"warning", required_argument, 0, 'w'}, 455 {"warning", required_argument, 0, 'w'},
454 {"critical", required_argument, 0, 'c'}, 456 {"critical", required_argument, 0, 'c'},
455 {"timeout", required_argument, 0, 't'}, 457 {"timeout", required_argument, 0, 't'},
@@ -462,7 +464,7 @@ int process_arguments(int argc, char **argv){
462 usage ("\n"); 464 usage ("\n");
463 465
464 while (1) { 466 while (1) {
465 c = getopt_long (argc, argv, "Vhv46w:c:t:H:", longopts, &option); 467 c = getopt_long (argc, argv, "Vhv46qw:c:t:H:", longopts, &option);
466 if (c == -1 || c == EOF || c == 1) 468 if (c == -1 || c == EOF || c == 1)
467 break; 469 break;
468 470
@@ -478,6 +480,9 @@ int process_arguments(int argc, char **argv){
478 case 'v': 480 case 'v':
479 verbose++; 481 verbose++;
480 break; 482 break;
483 case 'q':
484 quiet = 1;
485 break;
481 case 'w': 486 case 'w':
482 owarn = optarg; 487 owarn = optarg;
483 break; 488 break;
@@ -544,7 +549,7 @@ int main(int argc, char *argv[]){
544 549
545 offset = offset_request(server_address, &offset_result); 550 offset = offset_request(server_address, &offset_result);
546 if (offset_result == STATE_UNKNOWN) { 551 if (offset_result == STATE_UNKNOWN) {
547 result = STATE_CRITICAL; 552 result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL);
548 } else { 553 } else {
549 result = get_status(fabs(offset), offset_thresholds); 554 result = get_status(fabs(offset), offset_thresholds);
550 } 555 }
@@ -589,6 +594,8 @@ void print_help(void){
589 print_usage(); 594 print_usage();
590 printf (_(UT_HELP_VRSN)); 595 printf (_(UT_HELP_VRSN));
591 printf (_(UT_HOST_PORT), 'p', "123"); 596 printf (_(UT_HOST_PORT), 'p', "123");
597 printf (" %s\n", "-q, --quiet");
598 printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL if offset cannot be found"));
592 printf (" %s\n", "-w, --warning=THRESHOLD"); 599 printf (" %s\n", "-w, --warning=THRESHOLD");
593 printf (" %s\n", _("Offset to result in warning status (seconds)")); 600 printf (" %s\n", _("Offset to result in warning status (seconds)"));
594 printf (" %s\n", "-c, --critical=THRESHOLD"); 601 printf (" %s\n", "-c, --critical=THRESHOLD");