diff options
Diffstat (limited to 'plugins/check_ntp.c')
-rw-r--r-- | plugins/check_ntp.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 12334f7..df6e02f 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
@@ -47,6 +47,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
47 | 47 | ||
48 | static char *server_address=NULL; | 48 | static char *server_address=NULL; |
49 | static int verbose=0; | 49 | static int verbose=0; |
50 | static short do_offset=0; | ||
50 | static char *owarn="60"; | 51 | static char *owarn="60"; |
51 | static char *ocrit="120"; | 52 | static char *ocrit="120"; |
52 | static short do_stratum=0; | 53 | static short do_stratum=0; |
@@ -479,7 +480,7 @@ double offset_request(const char *host, int *stratum, int *status){ | |||
479 | /* now, pick the best server from the list */ | 480 | /* now, pick the best server from the list */ |
480 | best_index=best_offset_server(servers, num_hosts); | 481 | best_index=best_offset_server(servers, num_hosts); |
481 | if(best_index < 0){ | 482 | if(best_index < 0){ |
482 | *status=STATE_CRITICAL; | 483 | *status=STATE_UNKNOWN; |
483 | } else { | 484 | } else { |
484 | /* finally, calculate the average offset */ | 485 | /* finally, calculate the average offset */ |
485 | for(i=0; i<servers[best_index].num_responses;i++){ | 486 | for(i=0; i<servers[best_index].num_responses;i++){ |
@@ -582,7 +583,7 @@ double jitter_request(const char *host, int *status){ | |||
582 | if(verbose) printf("%d candiate peers available\n", num_candidates); | 583 | if(verbose) printf("%d candiate peers available\n", num_candidates); |
583 | if(verbose && syncsource_found) printf("synchronization source found\n"); | 584 | if(verbose && syncsource_found) printf("synchronization source found\n"); |
584 | if(! syncsource_found){ | 585 | if(! syncsource_found){ |
585 | *status = STATE_WARNING; | 586 | *status = STATE_UNKNOWN; |
586 | if(verbose) printf("warning: no synchronization source found\n"); | 587 | if(verbose) printf("warning: no synchronization source found\n"); |
587 | } | 588 | } |
588 | 589 | ||
@@ -632,7 +633,7 @@ double jitter_request(const char *host, int *status){ | |||
632 | } | 633 | } |
633 | if(startofvalue == NULL || startofvalue==nptr){ | 634 | if(startofvalue == NULL || startofvalue==nptr){ |
634 | printf("warning: unable to read server jitter response.\n"); | 635 | printf("warning: unable to read server jitter response.\n"); |
635 | *status = STATE_WARNING; | 636 | *status = STATE_UNKNOWN; |
636 | } else { | 637 | } else { |
637 | if(verbose) printf("%g\n", jitter); | 638 | if(verbose) printf("%g\n", jitter); |
638 | num_valid++; | 639 | num_valid++; |
@@ -695,9 +696,11 @@ int process_arguments(int argc, char **argv){ | |||
695 | verbose++; | 696 | verbose++; |
696 | break; | 697 | break; |
697 | case 'w': | 698 | case 'w': |
699 | do_offset=1; | ||
698 | owarn = optarg; | 700 | owarn = optarg; |
699 | break; | 701 | break; |
700 | case 'c': | 702 | case 'c': |
703 | do_offset=1; | ||
701 | ocrit = optarg; | 704 | ocrit = optarg; |
702 | break; | 705 | break; |
703 | case 'W': | 706 | case 'W': |
@@ -777,7 +780,7 @@ int main(int argc, char *argv[]){ | |||
777 | double offset=0, jitter=0; | 780 | double offset=0, jitter=0; |
778 | char *result_line, *perfdata_line; | 781 | char *result_line, *perfdata_line; |
779 | 782 | ||
780 | result = offset_result = jitter_result= STATE_UNKNOWN; | 783 | result = offset_result = jitter_result = STATE_OK; |
781 | 784 | ||
782 | if (process_arguments (argc, argv) == ERROR) | 785 | if (process_arguments (argc, argv) == ERROR) |
783 | usage4 (_("Could not parse arguments")); | 786 | usage4 (_("Could not parse arguments")); |
@@ -793,7 +796,11 @@ int main(int argc, char *argv[]){ | |||
793 | alarm (socket_timeout); | 796 | alarm (socket_timeout); |
794 | 797 | ||
795 | offset = offset_request(server_address, &stratum, &offset_result); | 798 | offset = offset_request(server_address, &stratum, &offset_result); |
796 | result = get_status(fabs(offset), offset_thresholds); | 799 | if (do_offset && offset_result == STATE_UNKNOWN) { |
800 | result = STATE_CRITICAL; | ||
801 | } else { | ||
802 | result = get_status(fabs(offset), offset_thresholds); | ||
803 | } | ||
797 | result = max_state(result, offset_result); | 804 | result = max_state(result, offset_result); |
798 | if(do_stratum) | 805 | if(do_stratum) |
799 | result = max_state(result, get_status(stratum, stratum_thresholds)); | 806 | result = max_state(result, get_status(stratum, stratum_thresholds)); |
@@ -827,13 +834,15 @@ int main(int argc, char *argv[]){ | |||
827 | asprintf(&result_line, "NTP UNKNOWN:"); | 834 | asprintf(&result_line, "NTP UNKNOWN:"); |
828 | break; | 835 | break; |
829 | } | 836 | } |
830 | if(offset_result==STATE_CRITICAL){ | 837 | if(offset_result == STATE_UNKNOWN){ |
831 | asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); | 838 | asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); |
832 | asprintf(&perfdata_line, ""); | 839 | asprintf(&perfdata_line, ""); |
833 | } else { | 840 | } else { |
841 | #if 0 /* 2007-10-25 This can't happen. Leftovers or uninplemented? */ | ||
834 | if(offset_result==STATE_WARNING){ | 842 | if(offset_result==STATE_WARNING){ |
835 | asprintf(&result_line, "%s %s", result_line, _("Unable to fully sample sync server")); | 843 | asprintf(&result_line, "%s %s", result_line, _("Unable to fully sample sync server")); |
836 | } | 844 | } |
845 | #endif | ||
837 | asprintf(&result_line, "%s Offset %.10g secs", result_line, offset); | 846 | asprintf(&result_line, "%s Offset %.10g secs", result_line, offset); |
838 | asprintf(&perfdata_line, "%s", perfd_offset(offset)); | 847 | asprintf(&perfdata_line, "%s", perfd_offset(offset)); |
839 | } | 848 | } |
@@ -887,6 +896,16 @@ void print_help(void){ | |||
887 | printf(" %s\n", ("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT")); | 896 | printf(" %s\n", ("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT")); |
888 | printf(" %s\n", _("for THRESHOLD format and examples.")); | 897 | printf(" %s\n", _("for THRESHOLD format and examples.")); |
889 | 898 | ||
899 | printf("\n"); | ||
900 | printf("%s\n", _("Examples:")); | ||
901 | printf(" %s\n", _("Normal offset check:")); | ||
902 | printf(" %s\n", ("./check_ntp -H ntpserv -w 0.5 -c 1")); | ||
903 | printf(" %s\n", _("Check jitter too, avoiding critical notifications if jitter isn't available")); | ||
904 | printf(" %s\n", _("(See Notes above for more details on thresholds formats):")); | ||
905 | printf(" %s\n", ("./check_ntp -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200")); | ||
906 | printf(" %s\n", _("Check only stratum:")); | ||
907 | printf(" %s\n", ("./check_ntp -H ntpserv -W 4 -C 6")); | ||
908 | |||
890 | printf (_(UT_SUPPORT)); | 909 | printf (_(UT_SUPPORT)); |
891 | } | 910 | } |
892 | 911 | ||