summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_ntp.c71
1 files changed, 56 insertions, 15 deletions
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 6c7c1e7..12334f7 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -4,7 +4,7 @@
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2006 sean finney <seanius@seanius.net> 6* Copyright (c) 2006 sean finney <seanius@seanius.net>
7* Copyright (c) 2006 nagios-plugins team 7* Copyright (c) 2007 nagios-plugins team
8* 8*
9* Last Modified: $Date$ 9* Last Modified: $Date$
10* 10*
@@ -38,7 +38,7 @@
38 38
39const char *progname = "check_ntp"; 39const char *progname = "check_ntp";
40const char *revision = "$Revision$"; 40const char *revision = "$Revision$";
41const char *copyright = "2006"; 41const char *copyright = "2007";
42const char *email = "nagiosplug-devel@lists.sourceforge.net"; 42const char *email = "nagiosplug-devel@lists.sourceforge.net";
43 43
44#include "common.h" 44#include "common.h"
@@ -47,9 +47,11 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
47 47
48static char *server_address=NULL; 48static char *server_address=NULL;
49static int verbose=0; 49static int verbose=0;
50static int stratum=-1;
51static char *owarn="60"; 50static char *owarn="60";
52static char *ocrit="120"; 51static char *ocrit="120";
52static short do_stratum=0;
53static char *swarn="16";
54static char *scrit="16";
53static short do_jitter=0; 55static short do_jitter=0;
54static char *jwarn="5000"; 56static char *jwarn="5000";
55static char *jcrit="10000"; 57static char *jcrit="10000";
@@ -57,6 +59,7 @@ static char *jcrit="10000";
57int process_arguments (int, char **); 59int process_arguments (int, char **);
58thresholds *offset_thresholds = NULL; 60thresholds *offset_thresholds = NULL;
59thresholds *jitter_thresholds = NULL; 61thresholds *jitter_thresholds = NULL;
62thresholds *stratum_thresholds = NULL;
60void print_help (void); 63void print_help (void);
61void print_usage (void); 64void print_usage (void);
62 65
@@ -357,7 +360,7 @@ int best_offset_server(const ntp_server_results *slist, int nservers){
357 * we don't waste time sitting around waiting for single packets. 360 * we don't waste time sitting around waiting for single packets.
358 * - we also "manually" handle resolving host names and connecting, because 361 * - we also "manually" handle resolving host names and connecting, because
359 * we have to do it in a way that our lazy macros don't handle currently :( */ 362 * we have to do it in a way that our lazy macros don't handle currently :( */
360double offset_request(const char *host, int *status){ 363double offset_request(const char *host, int *stratum, int *status){
361 int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; 364 int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0;
362 int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1; 365 int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1;
363 time_t now_time=0, start_ts=0; 366 time_t now_time=0, start_ts=0;
@@ -454,7 +457,7 @@ double offset_request(const char *host, int *status){
454 respnum=servers[i].num_responses++; 457 respnum=servers[i].num_responses++;
455 servers[i].offset[respnum]=calc_offset(&req[i], &recv_time); 458 servers[i].offset[respnum]=calc_offset(&req[i], &recv_time);
456 if(verbose) { 459 if(verbose) {
457 printf("offset %.10g\n", servers[i].offset[respnum]); 460 printf("offset %.10g, stratum %i\n", servers[i].offset[respnum], req[i].stratum);
458 } 461 }
459 servers[i].stratum=req[i].stratum; 462 servers[i].stratum=req[i].stratum;
460 servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp); 463 servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp);
@@ -483,6 +486,7 @@ double offset_request(const char *host, int *status){
483 avg_offset+=servers[best_index].offset[j]; 486 avg_offset+=servers[best_index].offset[j];
484 } 487 }
485 avg_offset/=servers[best_index].num_responses; 488 avg_offset/=servers[best_index].num_responses;
489 *stratum = servers[best_index].stratum;
486 } 490 }
487 491
488 /* cleanup */ 492 /* cleanup */
@@ -660,6 +664,8 @@ int process_arguments(int argc, char **argv){
660 {"use-ipv6", no_argument, 0, '6'}, 664 {"use-ipv6", no_argument, 0, '6'},
661 {"warning", required_argument, 0, 'w'}, 665 {"warning", required_argument, 0, 'w'},
662 {"critical", required_argument, 0, 'c'}, 666 {"critical", required_argument, 0, 'c'},
667 {"swarn", required_argument, 0, 'W'},
668 {"scrit", required_argument, 0, 'C'},
663 {"jwarn", required_argument, 0, 'j'}, 669 {"jwarn", required_argument, 0, 'j'},
664 {"jcrit", required_argument, 0, 'k'}, 670 {"jcrit", required_argument, 0, 'k'},
665 {"timeout", required_argument, 0, 't'}, 671 {"timeout", required_argument, 0, 't'},
@@ -672,7 +678,7 @@ int process_arguments(int argc, char **argv){
672 usage ("\n"); 678 usage ("\n");
673 679
674 while (1) { 680 while (1) {
675 c = getopt_long (argc, argv, "Vhv46w:c:j:k:t:H:", longopts, &option); 681 c = getopt_long (argc, argv, "Vhv46w:c:W:C:j:k:t:H:", longopts, &option);
676 if (c == -1 || c == EOF || c == 1) 682 if (c == -1 || c == EOF || c == 1)
677 break; 683 break;
678 684
@@ -694,6 +700,14 @@ int process_arguments(int argc, char **argv){
694 case 'c': 700 case 'c':
695 ocrit = optarg; 701 ocrit = optarg;
696 break; 702 break;
703 case 'W':
704 do_stratum=1;
705 swarn = optarg;
706 break;
707 case 'C':
708 do_stratum=1;
709 scrit = optarg;
710 break;
697 case 'j': 711 case 'j':
698 do_jitter=1; 712 do_jitter=1;
699 jwarn = optarg; 713 jwarn = optarg;
@@ -750,8 +764,16 @@ char *perfd_jitter (double jitter)
750 TRUE, 0, FALSE, 0); 764 TRUE, 0, FALSE, 0);
751} 765}
752 766
767char *perfd_stratum (int stratum)
768{
769 return perfdata ("stratum", stratum, "",
770 do_stratum, (int)stratum_thresholds->warning->end,
771 do_stratum, (int)stratum_thresholds->critical->end,
772 TRUE, 0, TRUE, 16);
773}
774
753int main(int argc, char *argv[]){ 775int main(int argc, char *argv[]){
754 int result, offset_result, jitter_result; 776 int result, offset_result, jitter_result, stratum;
755 double offset=0, jitter=0; 777 double offset=0, jitter=0;
756 char *result_line, *perfdata_line; 778 char *result_line, *perfdata_line;
757 779
@@ -762,6 +784,7 @@ int main(int argc, char *argv[]){
762 784
763 set_thresholds(&offset_thresholds, owarn, ocrit); 785 set_thresholds(&offset_thresholds, owarn, ocrit);
764 set_thresholds(&jitter_thresholds, jwarn, jcrit); 786 set_thresholds(&jitter_thresholds, jwarn, jcrit);
787 set_thresholds(&stratum_thresholds, swarn, scrit);
765 788
766 /* initialize alarm signal handling */ 789 /* initialize alarm signal handling */
767 signal (SIGALRM, socket_timeout_alarm_handler); 790 signal (SIGALRM, socket_timeout_alarm_handler);
@@ -769,9 +792,11 @@ int main(int argc, char *argv[]){
769 /* set socket timeout */ 792 /* set socket timeout */
770 alarm (socket_timeout); 793 alarm (socket_timeout);
771 794
772 offset = offset_request(server_address, &offset_result); 795 offset = offset_request(server_address, &stratum, &offset_result);
773 result = get_status(fabs(offset), offset_thresholds); 796 result = get_status(fabs(offset), offset_thresholds);
774 result = max_state(result, offset_result); 797 result = max_state(result, offset_result);
798 if(do_stratum)
799 result = max_state(result, get_status(stratum, stratum_thresholds));
775 800
776 /* If not told to check the jitter, we don't even send packets. 801 /* If not told to check the jitter, we don't even send packets.
777 * jitter is checked using NTP control packets, which not all 802 * jitter is checked using NTP control packets, which not all
@@ -816,6 +841,10 @@ int main(int argc, char *argv[]){
816 asprintf(&result_line, "%s, jitter=%f", result_line, jitter); 841 asprintf(&result_line, "%s, jitter=%f", result_line, jitter);
817 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); 842 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
818 } 843 }
844 if (do_stratum) {
845 asprintf(&result_line, "%s, stratum=%i", result_line, stratum);
846 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
847 }
819 printf("%s|%s\n", result_line, perfdata_line); 848 printf("%s|%s\n", result_line, perfdata_line);
820 849
821 if(server_address!=NULL) free(server_address); 850 if(server_address!=NULL) free(server_address);
@@ -837,16 +866,27 @@ void print_help(void){
837 print_usage(); 866 print_usage();
838 printf (_(UT_HELP_VRSN)); 867 printf (_(UT_HELP_VRSN));
839 printf (_(UT_HOST_PORT), 'p', "123"); 868 printf (_(UT_HOST_PORT), 'p', "123");
840 printf (" %s\n", "-w, --warning=DOUBLE"); 869 printf (" %s\n", "-w, --warning=THRESHOLD");
841 printf (" %s\n", _("Offset to result in warning status (seconds)")); 870 printf (" %s\n", _("Offset to result in warning status (seconds)"));
842 printf (" %s\n", "-c, --critical=DOUBLE"); 871 printf (" %s\n", "-c, --critical=THRESHOLD");
843 printf (" %s\n", _("Offset to result in critical status (seconds)")); 872 printf (" %s\n", _("Offset to result in critical status (seconds)"));
844 printf (" %s\n", "-j, --warning=DOUBLE"); 873 printf (" %s\n", "-W, --warning=THRESHOLD");
845 printf (" %s\n", _("Warning value for jitter")); 874 printf (" %s\n", _("Warning threshold for stratum"));
846 printf (" %s\n", "-k, --critical=DOUBLE"); 875 printf (" %s\n", "-W, --critical=THRESHOLD");
847 printf (" %s\n", _("Critical value for jitter")); 876 printf (" %s\n", _("Critical threshold for stratum"));
877 printf (" %s\n", "-j, --warning=THRESHOLD");
878 printf (" %s\n", _("Warning threshold for jitter"));
879 printf (" %s\n", "-k, --critical=THRESHOLD");
880 printf (" %s\n", _("Critical threshold for jitter"));
848 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 881 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
849 printf (_(UT_VERBOSE)); 882 printf (_(UT_VERBOSE));
883
884 printf("\n");
885 printf("%s\n", _("Notes:"));
886 printf(" %s\n", _("See:"));
887 printf(" %s\n", ("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
888 printf(" %s\n", _("for THRESHOLD format and examples."));
889
850 printf (_(UT_SUPPORT)); 890 printf (_(UT_SUPPORT));
851} 891}
852 892
@@ -854,5 +894,6 @@ void
854print_usage(void) 894print_usage(void)
855{ 895{
856 printf (_("Usage:")); 896 printf (_("Usage:"));
857 printf("%s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n", progname); 897 printf(" %s -H <host> [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname);
898 printf(" [-j <warn>] [-k <crit>] [-v verbose]\n");
858} 899}