summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--plugins/check_ntp.c63
2 files changed, 10 insertions, 54 deletions
diff --git a/NEWS b/NEWS
index 7a7ef8c..0c26c82 100644
--- a/NEWS
+++ b/NEWS
@@ -3,7 +3,6 @@ This file documents the major additions and syntax changes between releases.
31.4.11 or 1.5 ?? 31.4.11 or 1.5 ??
4 Fix check_http regression in 1.4.10 where following redirects to 4 Fix check_http regression in 1.4.10 where following redirects to
5 relative URLs on virtual hosts failed if both "-H" and "-I" were used 5 relative URLs on virtual hosts failed if both "-H" and "-I" were used
6 Add stratum thresholds support to check_ntp (feature request #1703823)
7 check_ntp now return UNKNOWN instead of WARNING if jitter is unavailable (jitter=-1.000000) 6 check_ntp now return UNKNOWN instead of WARNING if jitter is unavailable (jitter=-1.000000)
8 as long as the thresholds range inculde -1. If no offset threshold is specified 7 as long as the thresholds range inculde -1. If no offset threshold is specified
9 and the offset is unavailable, will return UNKNOWN as well. 8 and the offset is unavailable, will return UNKNOWN as well.
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 2854161..38562ac 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -50,9 +50,6 @@ static int verbose=0;
50static short do_offset=0; 50static short do_offset=0;
51static char *owarn="60"; 51static char *owarn="60";
52static char *ocrit="120"; 52static char *ocrit="120";
53static short do_stratum=0;
54static char *swarn="16";
55static char *scrit="16";
56static short do_jitter=0; 53static short do_jitter=0;
57static char *jwarn="5000"; 54static char *jwarn="5000";
58static char *jcrit="10000"; 55static char *jcrit="10000";
@@ -60,7 +57,6 @@ static char *jcrit="10000";
60int process_arguments (int, char **); 57int process_arguments (int, char **);
61thresholds *offset_thresholds = NULL; 58thresholds *offset_thresholds = NULL;
62thresholds *jitter_thresholds = NULL; 59thresholds *jitter_thresholds = NULL;
63thresholds *stratum_thresholds = NULL;
64void print_help (void); 60void print_help (void);
65void print_usage (void); 61void 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 :( */
364double offset_request(const char *host, int *stratum, int *status){ 360double 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,9 +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 sent in normal packets is ingreased by 1 (i.e. stratum that
491 * would be displayed if we were a server) so we decrease it */
492 *stratum = servers[best_index].stratum - 1;
493 } 486 }
494 487
495 /* cleanup */ 488 /* cleanup */
@@ -667,8 +660,6 @@ int process_arguments(int argc, char **argv){
667 {"use-ipv6", no_argument, 0, '6'}, 660 {"use-ipv6", no_argument, 0, '6'},
668 {"warning", required_argument, 0, 'w'}, 661 {"warning", required_argument, 0, 'w'},
669 {"critical", required_argument, 0, 'c'}, 662 {"critical", required_argument, 0, 'c'},
670 {"swarn", required_argument, 0, 'W'},
671 {"scrit", required_argument, 0, 'C'},
672 {"jwarn", required_argument, 0, 'j'}, 663 {"jwarn", required_argument, 0, 'j'},
673 {"jcrit", required_argument, 0, 'k'}, 664 {"jcrit", required_argument, 0, 'k'},
674 {"timeout", required_argument, 0, 't'}, 665 {"timeout", required_argument, 0, 't'},
@@ -681,7 +672,7 @@ int process_arguments(int argc, char **argv){
681 usage ("\n"); 672 usage ("\n");
682 673
683 while (1) { 674 while (1) {
684 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);
685 if (c == -1 || c == EOF || c == 1) 676 if (c == -1 || c == EOF || c == 1)
686 break; 677 break;
687 678
@@ -705,14 +696,6 @@ int process_arguments(int argc, char **argv){
705 do_offset=1; 696 do_offset=1;
706 ocrit = optarg; 697 ocrit = optarg;
707 break; 698 break;
708 case 'W':
709 do_stratum=1;
710 swarn = optarg;
711 break;
712 case 'C':
713 do_stratum=1;
714 scrit = optarg;
715 break;
716 case 'j': 699 case 'j':
717 do_jitter=1; 700 do_jitter=1;
718 jwarn = optarg; 701 jwarn = optarg;
@@ -769,16 +752,8 @@ char *perfd_jitter (double jitter)
769 TRUE, 0, FALSE, 0); 752 TRUE, 0, FALSE, 0);
770} 753}
771 754
772char *perfd_stratum (int stratum)
773{
774 return perfdata ("stratum", stratum, "",
775 do_stratum, (int)stratum_thresholds->warning->end,
776 do_stratum, (int)stratum_thresholds->critical->end,
777 TRUE, 0, TRUE, 16);
778}
779
780int main(int argc, char *argv[]){ 755int main(int argc, char *argv[]){
781 int result, offset_result, jitter_result, stratum; 756 int result, offset_result, jitter_result;
782 double offset=0, jitter=0; 757 double offset=0, jitter=0;
783 char *result_line, *perfdata_line; 758 char *result_line, *perfdata_line;
784 759
@@ -789,7 +764,6 @@ int main(int argc, char *argv[]){
789 764
790 set_thresholds(&offset_thresholds, owarn, ocrit); 765 set_thresholds(&offset_thresholds, owarn, ocrit);
791 set_thresholds(&jitter_thresholds, jwarn, jcrit); 766 set_thresholds(&jitter_thresholds, jwarn, jcrit);
792 set_thresholds(&stratum_thresholds, swarn, scrit);
793 767
794 /* initialize alarm signal handling */ 768 /* initialize alarm signal handling */
795 signal (SIGALRM, socket_timeout_alarm_handler); 769 signal (SIGALRM, socket_timeout_alarm_handler);
@@ -797,15 +771,14 @@ int main(int argc, char *argv[]){
797 /* set socket timeout */ 771 /* set socket timeout */
798 alarm (socket_timeout); 772 alarm (socket_timeout);
799 773
800 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 */
801 if (do_offset && offset_result == STATE_UNKNOWN) { 777 if (do_offset && offset_result == STATE_UNKNOWN) {
802 result = STATE_CRITICAL; 778 result = STATE_CRITICAL;
803 } else { 779 } else {
804 result = get_status(fabs(offset), offset_thresholds); 780 result = get_status(fabs(offset), offset_thresholds);
805 } 781 }
806 result = max_state(result, offset_result);
807 if(do_stratum)
808 result = max_state(result, get_status(stratum, stratum_thresholds));
809 782
810 /* 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.
811 * jitter is checked using NTP control packets, which not all 784 * jitter is checked using NTP control packets, which not all
@@ -814,13 +787,13 @@ int main(int argc, char *argv[]){
814 */ 787 */
815 if(do_jitter){ 788 if(do_jitter){
816 jitter=jitter_request(server_address, &jitter_result); 789 jitter=jitter_request(server_address, &jitter_result);
817 result = max_state(result, get_status(jitter, jitter_thresholds)); 790 result = max_state_alt(result, get_status(jitter, jitter_thresholds));
818 /* -1 indicates that we couldn't calculate the jitter 791 /* -1 indicates that we couldn't calculate the jitter
819 * Only overrides STATE_OK from the offset */ 792 * Only overrides STATE_OK from the offset */
820 if(jitter == -1.0 && result == STATE_OK) 793 if(jitter == -1.0 && result == STATE_OK)
821 result = STATE_UNKNOWN; 794 result = STATE_UNKNOWN;
822 } 795 }
823 result = max_state(result, jitter_result); 796 result = max_state_alt(result, jitter_result);
824 797
825 switch (result) { 798 switch (result) {
826 case STATE_CRITICAL : 799 case STATE_CRITICAL :
@@ -840,11 +813,6 @@ int main(int argc, char *argv[]){
840 asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); 813 asprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
841 asprintf(&perfdata_line, ""); 814 asprintf(&perfdata_line, "");
842 } else { 815 } else {
843#if 0 /* 2007-10-25 This can't happen. Leftovers or uninplemented? */
844 if(offset_result==STATE_WARNING){
845 asprintf(&result_line, "%s %s", result_line, _("Unable to fully sample sync server"));
846 }
847#endif
848 asprintf(&result_line, "%s Offset %.10g secs", result_line, offset); 816 asprintf(&result_line, "%s Offset %.10g secs", result_line, offset);
849 asprintf(&perfdata_line, "%s", perfd_offset(offset)); 817 asprintf(&perfdata_line, "%s", perfd_offset(offset));
850 } 818 }
@@ -852,10 +820,6 @@ int main(int argc, char *argv[]){
852 asprintf(&result_line, "%s, jitter=%f", result_line, jitter); 820 asprintf(&result_line, "%s, jitter=%f", result_line, jitter);
853 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); 821 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
854 } 822 }
855 if (do_stratum) {
856 asprintf(&result_line, "%s, stratum=%i", result_line, stratum);
857 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
858 }
859 printf("%s|%s\n", result_line, perfdata_line); 823 printf("%s|%s\n", result_line, perfdata_line);
860 824
861 if(server_address!=NULL) free(server_address); 825 if(server_address!=NULL) free(server_address);
@@ -881,10 +845,6 @@ void print_help(void){
881 printf (" %s\n", _("Offset to result in warning status (seconds)")); 845 printf (" %s\n", _("Offset to result in warning status (seconds)"));
882 printf (" %s\n", "-c, --critical=THRESHOLD"); 846 printf (" %s\n", "-c, --critical=THRESHOLD");
883 printf (" %s\n", _("Offset to result in critical status (seconds)")); 847 printf (" %s\n", _("Offset to result in critical status (seconds)"));
884 printf (" %s\n", "-W, --warning=THRESHOLD");
885 printf (" %s\n", _("Warning threshold for stratum"));
886 printf (" %s\n", "-W, --critical=THRESHOLD");
887 printf (" %s\n", _("Critical threshold for stratum"));
888 printf (" %s\n", "-j, --warning=THRESHOLD"); 848 printf (" %s\n", "-j, --warning=THRESHOLD");
889 printf (" %s\n", _("Warning threshold for jitter")); 849 printf (" %s\n", _("Warning threshold for jitter"));
890 printf (" %s\n", "-k, --critical=THRESHOLD"); 850 printf (" %s\n", "-k, --critical=THRESHOLD");
@@ -905,8 +865,6 @@ void print_help(void){
905 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"));
906 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):"));
907 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"));
908 printf(" %s\n", _("Check only stratum:"));
909 printf(" %s\n", ("./check_ntp -H ntpserv -W 4 -C 6"));
910 868
911 printf (_(UT_SUPPORT)); 869 printf (_(UT_SUPPORT));
912} 870}
@@ -915,6 +873,5 @@ void
915print_usage(void) 873print_usage(void)
916{ 874{
917 printf (_("Usage:")); 875 printf (_("Usage:"));
918 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);
919 printf(" [-j <warn>] [-k <crit>] [-v verbose]\n");
920} 877}