summaryrefslogtreecommitdiffstats
path: root/plugins/check_ntp.c
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2007-11-23 21:47:04 +0000
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2007-11-23 21:47:04 +0000
commit97131650ea6bf9f16b775743e9931a91ea441887 (patch)
treeacf692480460cd671de554bbecf32487f334e3b6 /plugins/check_ntp.c
parent643e6a0a4fc787541371aef9369d42b5cd250f91 (diff)
downloadmonitoring-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
Diffstat (limited to 'plugins/check_ntp.c')
-rw-r--r--plugins/check_ntp.c61
1 files changed, 10 insertions, 51 deletions
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;
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,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
770char *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
778int main(int argc, char *argv[]){ 755int 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
913print_usage(void) 873print_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}