diff options
| author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2007-11-23 21:47:04 +0000 |
|---|---|---|
| committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2007-11-23 21:47:04 +0000 |
| commit | 97131650ea6bf9f16b775743e9931a91ea441887 (patch) | |
| tree | acf692480460cd671de554bbecf32487f334e3b6 | |
| parent | 643e6a0a4fc787541371aef9369d42b5cd250f91 (diff) | |
| download | monitoring-plugins-97131650ea6bf9f16b775743e9931a91ea441887.tar.gz | |
Rename check_ntp* and merge change in Trunk
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/branches/dermoth_ntp_rework@1832 f882894a-f735-0410-b71e-b25c423dba1c
| -rw-r--r-- | NEWS | 1 | ||||
| -rw-r--r-- | plugins/Makefile.am | 12 | ||||
| -rw-r--r-- | plugins/check_ntp.c | 61 | ||||
| -rw-r--r-- | plugins/check_ntp_peer.c (renamed from plugins/check_ntpd.c) | 0 | ||||
| -rw-r--r-- | plugins/check_ntp_time.c (renamed from plugins/check_time_ntp.c) | 0 | ||||
| -rw-r--r-- | plugins/t/check_ntp.t | 22 | ||||
| -rw-r--r-- | plugins/utils.c | 27 | ||||
| -rw-r--r-- | plugins/utils.h | 1 |
8 files changed, 56 insertions, 68 deletions
| @@ -9,6 +9,7 @@ This file documents the major additions and syntax changes between releases. | |||
| 9 | and the offset is unavailable, will return UNKNOWN as well. | 9 | and the offset is unavailable, will return UNKNOWN as well. |
| 10 | NOTE: If jitter thresholds are specified integers it will return CRITICAL if jitter | 10 | NOTE: If jitter thresholds are specified integers it will return CRITICAL if jitter |
| 11 | is "-1" as the default range starts at 0. See Examples in --help output. | 11 | is "-1" as the default range starts at 0. See Examples in --help output. |
| 12 | YADDA YADDA YADDA... stratum thresholds support to check_ntp_peer (feature request #1703823) | ||
| 12 | 13 | ||
| 13 | 1.4.10 28th September 2007 | 14 | 1.4.10 28th September 2007 |
| 14 | Fix check_http buffer overflow vulnerability when following HTTP redirects | 15 | Fix check_http buffer overflow vulnerability when following HTTP redirects |
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 782721a5..eafcc5cd 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
| @@ -14,8 +14,8 @@ MATHLIBS = @MATHLIBS@ | |||
| 14 | #AM_CFLAGS = -Wall | 14 | #AM_CFLAGS = -Wall |
| 15 | 15 | ||
| 16 | libexec_PROGRAMS = check_apt check_cluster check_disk check_dummy check_http check_load \ | 16 | libexec_PROGRAMS = check_apt check_cluster check_disk check_dummy check_http check_load \ |
| 17 | check_mrtg check_mrtgtraf check_ntp check_ntpd check_nwstat check_overcr check_ping \ | 17 | check_mrtg check_mrtgtraf check_ntp check_ntp_peer check_nwstat check_overcr check_ping \ |
| 18 | check_real check_smtp check_ssh check_tcp check_time check_time_ntp \ | 18 | check_real check_smtp check_ssh check_tcp check_time check_ntp_time \ |
| 19 | check_ups check_users negate \ | 19 | check_ups check_users negate \ |
| 20 | urlize @EXTRAS@ | 20 | urlize @EXTRAS@ |
| 21 | 21 | ||
| @@ -70,7 +70,7 @@ check_mysql_query_LDADD = $(NETLIBS) $(MYSQLLIBS) | |||
| 70 | check_nagios_LDADD = $(BASEOBJS) runcmd.o | 70 | check_nagios_LDADD = $(BASEOBJS) runcmd.o |
| 71 | check_nt_LDADD = $(NETLIBS) | 71 | check_nt_LDADD = $(NETLIBS) |
| 72 | check_ntp_LDADD = $(NETLIBS) $(MATHLIBS) | 72 | check_ntp_LDADD = $(NETLIBS) $(MATHLIBS) |
| 73 | check_ntpd_LDADD = $(NETLIBS) $(MATHLIBS) | 73 | check_ntp_peer_LDADD = $(NETLIBS) $(MATHLIBS) |
| 74 | check_nwstat_LDADD = $(NETLIBS) | 74 | check_nwstat_LDADD = $(NETLIBS) |
| 75 | check_overcr_LDADD = $(NETLIBS) | 75 | check_overcr_LDADD = $(NETLIBS) |
| 76 | check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) | 76 | check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) |
| @@ -84,7 +84,7 @@ check_ssh_LDADD = $(NETLIBS) | |||
| 84 | check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) popen.o | 84 | check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) popen.o |
| 85 | check_tcp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) | 85 | check_tcp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) |
| 86 | check_time_LDADD = $(NETLIBS) | 86 | check_time_LDADD = $(NETLIBS) |
| 87 | check_time_ntp_LDADD = $(NETLIBS) $(MATHLIBS) | 87 | check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) |
| 88 | check_ups_LDADD = $(NETLIBS) | 88 | check_ups_LDADD = $(NETLIBS) |
| 89 | check_users_LDADD = $(BASEOBJS) popen.o | 89 | check_users_LDADD = $(BASEOBJS) popen.o |
| 90 | check_by_ssh_LDADD = $(NETLIBS) runcmd.o | 90 | check_by_ssh_LDADD = $(NETLIBS) runcmd.o |
| @@ -112,7 +112,7 @@ check_mysql_query_DEPENDENCIES = check_mysql_query.c $(NETOBJS) $(DEPLIBS) | |||
| 112 | check_nagios_DEPENDENCIES = check_nagios.c $(BASEOBJS) runcmd.o $(DEPLIBS) | 112 | check_nagios_DEPENDENCIES = check_nagios.c $(BASEOBJS) runcmd.o $(DEPLIBS) |
| 113 | check_nt_DEPENDENCIES = check_nt.c $(NETOBJS) $(DEPLIBS) | 113 | check_nt_DEPENDENCIES = check_nt.c $(NETOBJS) $(DEPLIBS) |
| 114 | check_ntp_DEPENDENCIES = check_ntp.c $(NETOBJS) $(DEPLIBS) | 114 | check_ntp_DEPENDENCIES = check_ntp.c $(NETOBJS) $(DEPLIBS) |
| 115 | check_ntpd_DEPENDENCIES = check_ntpd.c $(NETOBJS) $(DEPLIBS) | 115 | check_ntp_peer_DEPENDENCIES = check_ntp_peer.c $(NETOBJS) $(DEPLIBS) |
| 116 | check_nwstat_DEPENDENCIES = check_nwstat.c $(NETOBJS) $(DEPLIBS) | 116 | check_nwstat_DEPENDENCIES = check_nwstat.c $(NETOBJS) $(DEPLIBS) |
| 117 | check_overcr_DEPENDENCIES = check_overcr.c $(NETOBJS) $(DEPLIBS) | 117 | check_overcr_DEPENDENCIES = check_overcr.c $(NETOBJS) $(DEPLIBS) |
| 118 | check_pgsql_DEPENDENCIES = check_pgsql.c $(NETOBJS) $(DEPLIBS) | 118 | check_pgsql_DEPENDENCIES = check_pgsql.c $(NETOBJS) $(DEPLIBS) |
| @@ -126,7 +126,7 @@ check_ssh_DEPENDENCIES = check_ssh.c $(NETOBJS) $(DEPLIBS) | |||
| 126 | check_swap_DEPENDENCIES = check_swap.c $(BASEOBJS) popen.o $(DEPLIBS) | 126 | check_swap_DEPENDENCIES = check_swap.c $(BASEOBJS) popen.o $(DEPLIBS) |
| 127 | check_tcp_DEPENDENCIES = check_tcp.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS) | 127 | check_tcp_DEPENDENCIES = check_tcp.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS) |
| 128 | check_time_DEPENDENCIES = check_time.c $(NETOBJS) $(DEPLIBS) | 128 | check_time_DEPENDENCIES = check_time.c $(NETOBJS) $(DEPLIBS) |
| 129 | check_time_ntp_DEPENDENCIES = check_time_ntp.c $(NETOBJS) $(DEPLIBS) | 129 | check_ntp_time_DEPENDENCIES = check_ntp_time.c $(NETOBJS) $(DEPLIBS) |
| 130 | check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS) | 130 | check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS) |
| 131 | check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS) | 131 | check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS) |
| 132 | check_by_ssh_DEPENDENCIES = check_by_ssh.c $(NETOBJS) runcmd.o $(DEPLIBS) | 132 | check_by_ssh_DEPENDENCIES = check_by_ssh.c $(NETOBJS) runcmd.o $(DEPLIBS) |
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index df6e02f8..38562ac9 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
| @@ -50,9 +50,6 @@ static int verbose=0; | |||
| 50 | static short do_offset=0; | 50 | static short do_offset=0; |
| 51 | static char *owarn="60"; | 51 | static char *owarn="60"; |
| 52 | static char *ocrit="120"; | 52 | static char *ocrit="120"; |
| 53 | static short do_stratum=0; | ||
| 54 | static char *swarn="16"; | ||
| 55 | static char *scrit="16"; | ||
| 56 | static short do_jitter=0; | 53 | static short do_jitter=0; |
| 57 | static char *jwarn="5000"; | 54 | static char *jwarn="5000"; |
| 58 | static char *jcrit="10000"; | 55 | static char *jcrit="10000"; |
| @@ -60,7 +57,6 @@ static char *jcrit="10000"; | |||
| 60 | int process_arguments (int, char **); | 57 | int process_arguments (int, char **); |
| 61 | thresholds *offset_thresholds = NULL; | 58 | thresholds *offset_thresholds = NULL; |
| 62 | thresholds *jitter_thresholds = NULL; | 59 | thresholds *jitter_thresholds = NULL; |
| 63 | thresholds *stratum_thresholds = NULL; | ||
| 64 | void print_help (void); | 60 | void print_help (void); |
| 65 | void print_usage (void); | 61 | void print_usage (void); |
| 66 | 62 | ||
| @@ -361,7 +357,7 @@ int best_offset_server(const ntp_server_results *slist, int nservers){ | |||
| 361 | * we don't waste time sitting around waiting for single packets. | 357 | * we don't waste time sitting around waiting for single packets. |
| 362 | * - we also "manually" handle resolving host names and connecting, because | 358 | * - we also "manually" handle resolving host names and connecting, because |
| 363 | * we have to do it in a way that our lazy macros don't handle currently :( */ | 359 | * we have to do it in a way that our lazy macros don't handle currently :( */ |
| 364 | double offset_request(const char *host, int *stratum, int *status){ | 360 | double offset_request(const char *host, int *status){ |
| 365 | int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; | 361 | int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; |
| 366 | int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1; | 362 | int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1; |
| 367 | time_t now_time=0, start_ts=0; | 363 | time_t now_time=0, start_ts=0; |
| @@ -458,7 +454,7 @@ double offset_request(const char *host, int *stratum, int *status){ | |||
| 458 | respnum=servers[i].num_responses++; | 454 | respnum=servers[i].num_responses++; |
| 459 | servers[i].offset[respnum]=calc_offset(&req[i], &recv_time); | 455 | servers[i].offset[respnum]=calc_offset(&req[i], &recv_time); |
| 460 | if(verbose) { | 456 | if(verbose) { |
| 461 | printf("offset %.10g, stratum %i\n", servers[i].offset[respnum], req[i].stratum); | 457 | printf("offset %.10g\n", servers[i].offset[respnum]); |
| 462 | } | 458 | } |
| 463 | servers[i].stratum=req[i].stratum; | 459 | servers[i].stratum=req[i].stratum; |
| 464 | servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp); | 460 | servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp); |
| @@ -487,7 +483,6 @@ double offset_request(const char *host, int *stratum, int *status){ | |||
| 487 | avg_offset+=servers[best_index].offset[j]; | 483 | avg_offset+=servers[best_index].offset[j]; |
| 488 | } | 484 | } |
| 489 | avg_offset/=servers[best_index].num_responses; | 485 | avg_offset/=servers[best_index].num_responses; |
| 490 | *stratum = servers[best_index].stratum; | ||
| 491 | } | 486 | } |
| 492 | 487 | ||
| 493 | /* cleanup */ | 488 | /* cleanup */ |
| @@ -665,8 +660,6 @@ int process_arguments(int argc, char **argv){ | |||
| 665 | {"use-ipv6", no_argument, 0, '6'}, | 660 | {"use-ipv6", no_argument, 0, '6'}, |
| 666 | {"warning", required_argument, 0, 'w'}, | 661 | {"warning", required_argument, 0, 'w'}, |
| 667 | {"critical", required_argument, 0, 'c'}, | 662 | {"critical", required_argument, 0, 'c'}, |
| 668 | {"swarn", required_argument, 0, 'W'}, | ||
| 669 | {"scrit", required_argument, 0, 'C'}, | ||
| 670 | {"jwarn", required_argument, 0, 'j'}, | 663 | {"jwarn", required_argument, 0, 'j'}, |
| 671 | {"jcrit", required_argument, 0, 'k'}, | 664 | {"jcrit", required_argument, 0, 'k'}, |
| 672 | {"timeout", required_argument, 0, 't'}, | 665 | {"timeout", required_argument, 0, 't'}, |
| @@ -679,7 +672,7 @@ int process_arguments(int argc, char **argv){ | |||
| 679 | usage ("\n"); | 672 | usage ("\n"); |
| 680 | 673 | ||
| 681 | while (1) { | 674 | while (1) { |
| 682 | c = getopt_long (argc, argv, "Vhv46w:c:W:C:j:k:t:H:", longopts, &option); | 675 | c = getopt_long (argc, argv, "Vhv46w:c:j:k:t:H:", longopts, &option); |
| 683 | if (c == -1 || c == EOF || c == 1) | 676 | if (c == -1 || c == EOF || c == 1) |
| 684 | break; | 677 | break; |
| 685 | 678 | ||
| @@ -703,14 +696,6 @@ int process_arguments(int argc, char **argv){ | |||
| 703 | do_offset=1; | 696 | do_offset=1; |
| 704 | ocrit = optarg; | 697 | ocrit = optarg; |
| 705 | break; | 698 | break; |
| 706 | case 'W': | ||
| 707 | do_stratum=1; | ||
| 708 | swarn = optarg; | ||
| 709 | break; | ||
| 710 | case 'C': | ||
| 711 | do_stratum=1; | ||
| 712 | scrit = optarg; | ||
| 713 | break; | ||
| 714 | case 'j': | 699 | case 'j': |
| 715 | do_jitter=1; | 700 | do_jitter=1; |
| 716 | jwarn = optarg; | 701 | jwarn = optarg; |
| @@ -767,16 +752,8 @@ char *perfd_jitter (double jitter) | |||
| 767 | TRUE, 0, FALSE, 0); | 752 | TRUE, 0, FALSE, 0); |
| 768 | } | 753 | } |
| 769 | 754 | ||
| 770 | char *perfd_stratum (int stratum) | ||
| 771 | { | ||
| 772 | return perfdata ("stratum", stratum, "", | ||
| 773 | do_stratum, (int)stratum_thresholds->warning->end, | ||
| 774 | do_stratum, (int)stratum_thresholds->critical->end, | ||
| 775 | TRUE, 0, TRUE, 16); | ||
| 776 | } | ||
| 777 | |||
| 778 | int main(int argc, char *argv[]){ | 755 | int main(int argc, char *argv[]){ |
| 779 | int result, offset_result, jitter_result, stratum; | 756 | int result, offset_result, jitter_result; |
| 780 | double offset=0, jitter=0; | 757 | double offset=0, jitter=0; |
| 781 | char *result_line, *perfdata_line; | 758 | char *result_line, *perfdata_line; |
| 782 | 759 | ||
| @@ -787,7 +764,6 @@ int main(int argc, char *argv[]){ | |||
| 787 | 764 | ||
| 788 | set_thresholds(&offset_thresholds, owarn, ocrit); | 765 | set_thresholds(&offset_thresholds, owarn, ocrit); |
| 789 | set_thresholds(&jitter_thresholds, jwarn, jcrit); | 766 | set_thresholds(&jitter_thresholds, jwarn, jcrit); |
| 790 | set_thresholds(&stratum_thresholds, swarn, scrit); | ||
| 791 | 767 | ||
| 792 | /* initialize alarm signal handling */ | 768 | /* initialize alarm signal handling */ |
| 793 | signal (SIGALRM, socket_timeout_alarm_handler); | 769 | signal (SIGALRM, socket_timeout_alarm_handler); |
| @@ -795,15 +771,14 @@ int main(int argc, char *argv[]){ | |||
| 795 | /* set socket timeout */ | 771 | /* set socket timeout */ |
| 796 | alarm (socket_timeout); | 772 | alarm (socket_timeout); |
| 797 | 773 | ||
| 798 | offset = offset_request(server_address, &stratum, &offset_result); | 774 | offset = offset_request(server_address, &offset_result); |
| 775 | /* check_ntp used to always return if offset_result == STATE_UNKNOWN. | ||
| 776 | * Now we'll only do that is the offset thresholds were set */ | ||
| 799 | if (do_offset && offset_result == STATE_UNKNOWN) { | 777 | if (do_offset && offset_result == STATE_UNKNOWN) { |
| 800 | result = STATE_CRITICAL; | 778 | result = STATE_CRITICAL; |
| 801 | } else { | 779 | } else { |
| 802 | result = get_status(fabs(offset), offset_thresholds); | 780 | result = get_status(fabs(offset), offset_thresholds); |
| 803 | } | 781 | } |
| 804 | result = max_state(result, offset_result); | ||
| 805 | if(do_stratum) | ||
| 806 | result = max_state(result, get_status(stratum, stratum_thresholds)); | ||
| 807 | 782 | ||
| 808 | /* If not told to check the jitter, we don't even send packets. | 783 | /* If not told to check the jitter, we don't even send packets. |
| 809 | * jitter is checked using NTP control packets, which not all | 784 | * jitter is checked using NTP control packets, which not all |
| @@ -812,13 +787,13 @@ int main(int argc, char *argv[]){ | |||
| 812 | */ | 787 | */ |
| 813 | if(do_jitter){ | 788 | if(do_jitter){ |
| 814 | jitter=jitter_request(server_address, &jitter_result); | 789 | jitter=jitter_request(server_address, &jitter_result); |
| 815 | result = max_state(result, get_status(jitter, jitter_thresholds)); | 790 | result = max_state_alt(result, get_status(jitter, jitter_thresholds)); |
| 816 | /* -1 indicates that we couldn't calculate the jitter | 791 | /* -1 indicates that we couldn't calculate the jitter |
| 817 | * Only overrides STATE_OK from the offset */ | 792 | * Only overrides STATE_OK from the offset */ |
| 818 | if(jitter == -1.0 && result == STATE_OK) | 793 | if(jitter == -1.0 && result == STATE_OK) |
| 819 | result = STATE_UNKNOWN; | 794 | result = STATE_UNKNOWN; |
| 820 | } | 795 | } |
| 821 | result = max_state(result, jitter_result); | 796 | result = max_state_alt(result, jitter_result); |
| 822 | 797 | ||
| 823 | switch (result) { | 798 | switch (result) { |
| 824 | case STATE_CRITICAL : | 799 | case STATE_CRITICAL : |
| @@ -838,11 +813,6 @@ int main(int argc, char *argv[]){ | |||
| 838 | asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); | 813 | asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); |
| 839 | asprintf(&perfdata_line, ""); | 814 | asprintf(&perfdata_line, ""); |
| 840 | } else { | 815 | } else { |
| 841 | #if 0 /* 2007-10-25 This can't happen. Leftovers or uninplemented? */ | ||
| 842 | if(offset_result==STATE_WARNING){ | ||
| 843 | asprintf(&result_line, "%s %s", result_line, _("Unable to fully sample sync server")); | ||
| 844 | } | ||
| 845 | #endif | ||
| 846 | asprintf(&result_line, "%s Offset %.10g secs", result_line, offset); | 816 | asprintf(&result_line, "%s Offset %.10g secs", result_line, offset); |
| 847 | asprintf(&perfdata_line, "%s", perfd_offset(offset)); | 817 | asprintf(&perfdata_line, "%s", perfd_offset(offset)); |
| 848 | } | 818 | } |
| @@ -850,10 +820,6 @@ int main(int argc, char *argv[]){ | |||
| 850 | asprintf(&result_line, "%s, jitter=%f", result_line, jitter); | 820 | asprintf(&result_line, "%s, jitter=%f", result_line, jitter); |
| 851 | asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); | 821 | asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); |
| 852 | } | 822 | } |
| 853 | if (do_stratum) { | ||
| 854 | asprintf(&result_line, "%s, stratum=%i", result_line, stratum); | ||
| 855 | asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum)); | ||
| 856 | } | ||
| 857 | printf("%s|%s\n", result_line, perfdata_line); | 823 | printf("%s|%s\n", result_line, perfdata_line); |
| 858 | 824 | ||
| 859 | if(server_address!=NULL) free(server_address); | 825 | if(server_address!=NULL) free(server_address); |
| @@ -879,10 +845,6 @@ void print_help(void){ | |||
| 879 | printf (" %s\n", _("Offset to result in warning status (seconds)")); | 845 | printf (" %s\n", _("Offset to result in warning status (seconds)")); |
| 880 | printf (" %s\n", "-c, --critical=THRESHOLD"); | 846 | printf (" %s\n", "-c, --critical=THRESHOLD"); |
| 881 | printf (" %s\n", _("Offset to result in critical status (seconds)")); | 847 | printf (" %s\n", _("Offset to result in critical status (seconds)")); |
| 882 | printf (" %s\n", "-W, --warning=THRESHOLD"); | ||
| 883 | printf (" %s\n", _("Warning threshold for stratum")); | ||
| 884 | printf (" %s\n", "-W, --critical=THRESHOLD"); | ||
| 885 | printf (" %s\n", _("Critical threshold for stratum")); | ||
| 886 | printf (" %s\n", "-j, --warning=THRESHOLD"); | 848 | printf (" %s\n", "-j, --warning=THRESHOLD"); |
| 887 | printf (" %s\n", _("Warning threshold for jitter")); | 849 | printf (" %s\n", _("Warning threshold for jitter")); |
| 888 | printf (" %s\n", "-k, --critical=THRESHOLD"); | 850 | printf (" %s\n", "-k, --critical=THRESHOLD"); |
| @@ -903,8 +865,6 @@ void print_help(void){ | |||
| 903 | printf(" %s\n", _("Check jitter too, avoiding critical notifications if jitter isn't available")); | 865 | 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):")); | 866 | 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")); | 867 | 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 | 868 | ||
| 909 | printf (_(UT_SUPPORT)); | 869 | printf (_(UT_SUPPORT)); |
| 910 | } | 870 | } |
| @@ -913,6 +873,5 @@ void | |||
| 913 | print_usage(void) | 873 | print_usage(void) |
| 914 | { | 874 | { |
| 915 | printf (_("Usage:")); | 875 | printf (_("Usage:")); |
| 916 | printf(" %s -H <host> [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname); | 876 | printf(" %s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n", progname); |
| 917 | printf(" [-j <warn>] [-k <crit>] [-v verbose]\n"); | ||
| 918 | } | 877 | } |
diff --git a/plugins/check_ntpd.c b/plugins/check_ntp_peer.c index 840fe0ac..840fe0ac 100644 --- a/plugins/check_ntpd.c +++ b/plugins/check_ntp_peer.c | |||
diff --git a/plugins/check_time_ntp.c b/plugins/check_ntp_time.c index c945076d..c945076d 100644 --- a/plugins/check_time_ntp.c +++ b/plugins/check_ntp_time.c | |||
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t index a36a730d..e7eb0c41 100644 --- a/plugins/t/check_ntp.t +++ b/plugins/t/check_ntp.t | |||
| @@ -9,8 +9,8 @@ use strict; | |||
| 9 | use Test::More; | 9 | use Test::More; |
| 10 | use NPTest; | 10 | use NPTest; |
| 11 | 11 | ||
| 12 | my @PLUGINS1 = ('check_ntp', 'check_ntpd', 'check_time_ntp'); | 12 | my @PLUGINS1 = ('check_ntp', 'check_ntp_peer', 'check_ntp_time'); |
| 13 | my @PLUGINS2 = ('check_ntp', 'check_ntpd'); | 13 | my @PLUGINS2 = ('check_ntp_peer'); |
| 14 | 14 | ||
| 15 | plan tests => (9 * scalar(@PLUGINS1)) + (6 * scalar(@PLUGINS2)); | 15 | plan tests => (9 * scalar(@PLUGINS1)) + (6 * scalar(@PLUGINS2)); |
| 16 | 16 | ||
| @@ -45,19 +45,19 @@ foreach my $plugin (@PLUGINS1) { | |||
| 45 | $res = NPTest->testCmd( | 45 | $res = NPTest->testCmd( |
| 46 | "./$plugin -H $ntp_service -w 1000 -c 2000" | 46 | "./$plugin -H $ntp_service -w 1000 -c 2000" |
| 47 | ); | 47 | ); |
| 48 | cmp_ok( $res->return_code, '==', 0, "Got good NTP result"); | 48 | cmp_ok( $res->return_code, '==', 0, "$plugin: Got good NTP result"); |
| 49 | like( $res->output, $ntp_okmatch1, "Output OK" ); | 49 | like( $res->output, $ntp_okmatch1, "Output OK" ); |
| 50 | 50 | ||
| 51 | $res = NPTest->testCmd( | 51 | $res = NPTest->testCmd( |
| 52 | "./$plugin -H $ntp_service -w 1000: -c 2000" | 52 | "./$plugin -H $ntp_service -w 1000: -c 2000" |
| 53 | ); | 53 | ); |
| 54 | cmp_ok( $res->return_code, '==', 1, "Got warning NTP result"); | 54 | cmp_ok( $res->return_code, '==', 1, "$plugin: Got warning NTP result"); |
| 55 | like( $res->output, $ntp_warnmatch1, "Output WARNING" ); | 55 | like( $res->output, $ntp_warnmatch1, "Output WARNING" ); |
| 56 | 56 | ||
| 57 | $res = NPTest->testCmd( | 57 | $res = NPTest->testCmd( |
| 58 | "./$plugin -H $ntp_service -w 1000 -c 2000:" | 58 | "./$plugin -H $ntp_service -w 1000 -c 2000:" |
| 59 | ); | 59 | ); |
| 60 | cmp_ok( $res->return_code, '==', 2, "Got critical NTP result"); | 60 | cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical NTP result"); |
| 61 | like( $res->output, $ntp_critmatch1, "Output CRITICAL" ); | 61 | like( $res->output, $ntp_critmatch1, "Output CRITICAL" ); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -66,18 +66,18 @@ foreach my $plugin (@PLUGINS1) { | |||
| 66 | $res = NPTest->testCmd( | 66 | $res = NPTest->testCmd( |
| 67 | "./$plugin -H $no_ntp_service" | 67 | "./$plugin -H $no_ntp_service" |
| 68 | ); | 68 | ); |
| 69 | cmp_ok( $res->return_code, '==', 2, "Got bad NTP result"); | 69 | cmp_ok( $res->return_code, '==', 2, "$plugin: Got bad NTP result"); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | $res = NPTest->testCmd( | 72 | $res = NPTest->testCmd( |
| 73 | "./$plugin -H $host_nonresponsive" | 73 | "./$plugin -H $host_nonresponsive" |
| 74 | ); | 74 | ); |
| 75 | cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding"); | 75 | cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical if server not responding"); |
| 76 | 76 | ||
| 77 | $res = NPTest->testCmd( | 77 | $res = NPTest->testCmd( |
| 78 | "./$plugin -H $hostname_invalid" | 78 | "./$plugin -H $hostname_invalid" |
| 79 | ); | 79 | ); |
| 80 | cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid"); | 80 | cmp_ok( $res->return_code, '==', 3, "$plugin: Got critical if server hostname invalid"); |
| 81 | 81 | ||
| 82 | } | 82 | } |
| 83 | 83 | ||
| @@ -87,19 +87,19 @@ foreach my $plugin (@PLUGINS2) { | |||
| 87 | $res = NPTest->testCmd( | 87 | $res = NPTest->testCmd( |
| 88 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k 200000" | 88 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k 200000" |
| 89 | ); | 89 | ); |
| 90 | cmp_ok( $res->return_code, '==', 0, "Got good NTP result"); | 90 | cmp_ok( $res->return_code, '==', 0, "$plugin: Got good NTP result"); |
| 91 | like( $res->output, $ntp_okmatch2, "Output OK" ); | 91 | like( $res->output, $ntp_okmatch2, "Output OK" ); |
| 92 | 92 | ||
| 93 | $res = NPTest->testCmd( | 93 | $res = NPTest->testCmd( |
| 94 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W ~:-1 -C 21 -j 100000 -k 200000" | 94 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W ~:-1 -C 21 -j 100000 -k 200000" |
| 95 | ); | 95 | ); |
| 96 | cmp_ok( $res->return_code, '==', 1, "Got warning NTP result"); | 96 | cmp_ok( $res->return_code, '==', 1, "$plugin: Got warning NTP result"); |
| 97 | like( $res->output, $ntp_warnmatch2, "Output WARNING" ); | 97 | like( $res->output, $ntp_warnmatch2, "Output WARNING" ); |
| 98 | 98 | ||
| 99 | $res = NPTest->testCmd( | 99 | $res = NPTest->testCmd( |
| 100 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k ~:-1" | 100 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k ~:-1" |
| 101 | ); | 101 | ); |
| 102 | cmp_ok( $res->return_code, '==', 2, "Got critical NTP result"); | 102 | cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical NTP result"); |
| 103 | like( $res->output, $ntp_critmatch2, "Output CRITICAL" ); | 103 | like( $res->output, $ntp_critmatch2, "Output CRITICAL" ); |
| 104 | } | 104 | } |
| 105 | } | 105 | } |
diff --git a/plugins/utils.c b/plugins/utils.c index 0e79fbdb..88b44114 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
| @@ -53,6 +53,33 @@ max_state (int a, int b) | |||
| 53 | return max (a, b); | 53 | return max (a, b); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | /* ************************************************************************** | ||
| 57 | * max_state_alt(STATE_x, STATE_y) | ||
| 58 | * compares STATE_x to STATE_y and returns result based on the following | ||
| 59 | * STATE_OK < STATE_DEPENDENT < STATE_UNKNOWN < STATE_WARNING < STATE_CRITICAL | ||
| 60 | * | ||
| 61 | * The main difference between max_state_alt and max_state it that it doesn't | ||
| 62 | * allow setting a default to UNKNOWN. It will instead prioritixe any valid | ||
| 63 | * non-OK state. | ||
| 64 | ****************************************************************************/ | ||
| 65 | |||
| 66 | int | ||
| 67 | max_state_alt (int a, int b) | ||
| 68 | { | ||
| 69 | if (a == STATE_CRITICAL || b == STATE_CRITICAL) | ||
| 70 | return STATE_CRITICAL; | ||
| 71 | else if (a == STATE_WARNING || b == STATE_WARNING) | ||
| 72 | return STATE_WARNING; | ||
| 73 | else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN) | ||
| 74 | return STATE_UNKNOWN; | ||
| 75 | else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) | ||
| 76 | return STATE_DEPENDENT; | ||
| 77 | else if (a == STATE_OK || b == STATE_OK) | ||
| 78 | return STATE_OK; | ||
| 79 | else | ||
| 80 | return max (a, b); | ||
| 81 | } | ||
| 82 | |||
| 56 | void usage (const char *msg) | 83 | void usage (const char *msg) |
| 57 | { | 84 | { |
| 58 | printf ("%s\n", msg); | 85 | printf ("%s\n", msg); |
diff --git a/plugins/utils.h b/plugins/utils.h index f15a7b16..bb99ee16 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
| @@ -76,6 +76,7 @@ char *strpcpy (char *, const char *, const char *); | |||
| 76 | char *strpcat (char *, const char *, const char *); | 76 | char *strpcat (char *, const char *, const char *); |
| 77 | 77 | ||
| 78 | int max_state (int a, int b); | 78 | int max_state (int a, int b); |
| 79 | int max_state_alt (int a, int b); | ||
| 79 | 80 | ||
| 80 | void usage (const char *) __attribute__((noreturn)); | 81 | void usage (const char *) __attribute__((noreturn)); |
| 81 | void usage2(const char *, const char *) __attribute__((noreturn)); | 82 | void usage2(const char *, const char *) __attribute__((noreturn)); |
