[monitoring-plugins] check_ntp_time: adding offset option

Jan Wagner git at monitoring-plugins.org
Tue Jul 29 14:50:08 CEST 2014


 Module: monitoring-plugins
 Branch: master
 Commit: a941219b41ba15abb393ae3a1cbdef3d28025c09
 Author: Jan Wagner <waja at cyconet.org>
   Date: Tue Oct  1 08:17:54 2013 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=a941219

check_ntp_time: adding offset option

Not sure if this is of use or not - we have a strange requirement to run
certain servers 5 minutes fast. I've added a switch to the check_ntp_time
to allow for this offset.

Thanks to Patrick McAndrew.

---

 plugins/check_ntp_time.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c
index 72dffbd..d6cf419 100644
--- a/plugins/check_ntp_time.c
+++ b/plugins/check_ntp_time.c
@@ -48,6 +48,7 @@ static int verbose=0;
 static int quiet=0;
 static char *owarn="60";
 static char *ocrit="120";
+static int time_offset=0;
 
 int process_arguments (int, char **);
 thresholds *offset_thresholds = NULL;
@@ -400,7 +401,7 @@ double offset_request(const char *host, int *status){
 				gettimeofday(&recv_time, NULL);
 				DBG(print_ntp_message(&req[i]));
 				respnum=servers[i].num_responses++;
-				servers[i].offset[respnum]=calc_offset(&req[i], &recv_time);
+				servers[i].offset[respnum]=calc_offset(&req[i], &recv_time)+time_offset;
 				if(verbose) {
 					printf("offset %.10g\n", servers[i].offset[respnum]);
 				}
@@ -455,6 +456,7 @@ int process_arguments(int argc, char **argv){
 		{"use-ipv4", no_argument, 0, '4'},
 		{"use-ipv6", no_argument, 0, '6'},
 		{"quiet", no_argument, 0, 'q'},
+		{"time-offset", optional_argument, 0, 'o'},
 		{"warning", required_argument, 0, 'w'},
 		{"critical", required_argument, 0, 'c'},
 		{"timeout", required_argument, 0, 't'},
@@ -468,7 +470,7 @@ int process_arguments(int argc, char **argv){
 		usage ("\n");
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:", longopts, &option);
+		c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:o:", longopts, &option);
 		if (c == -1 || c == EOF || c == 1)
 			break;
 
@@ -504,6 +506,9 @@ int process_arguments(int argc, char **argv){
 		case 't':
 			socket_timeout=atoi(optarg);
 			break;
+		case 'o':
+			time_offset=atoi(optarg);
+                        break;
 		case '4':
 			address_family = AF_INET;
 			break;
@@ -616,6 +621,8 @@ void print_help(void){
 	printf ("    %s\n", _("Offset to result in warning status (seconds)"));
 	printf (" %s\n", "-c, --critical=THRESHOLD");
 	printf ("    %s\n", _("Offset to result in critical status (seconds)"));
+	printf (" %s\n", "-o, --time_offset=");
+	printf ("    %s\n", _("Expected offset of the ntp server relative to local server (seconds)"));
 	printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
 	printf (UT_VERBOSE);
 
@@ -642,6 +649,6 @@ void
 print_usage(void)
 {
 	printf ("%s\n", _("Usage:"));
-	printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose]\n", progname);
+	printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose] [-o <time offset>]\n", progname);
 }
 



More information about the Commits mailing list