[Nagiosplug-checkins] nagiosplug/plugins check_ntp.c,1.23,1.24

Thomas Guyot dermoth at users.sourceforge.net
Wed Apr 4 22:09:02 CEST 2007


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv2781/plugins

Modified Files:
	check_ntp.c 
Log Message:
Fix for getting dispersion instead of jitter on older servers (like xntpd on Solaris).


Index: check_ntp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ntp.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- check_ntp.c	3 Apr 2007 17:19:04 -0000	1.23
+++ check_ntp.c	4 Apr 2007 20:08:59 -0000	1.24
@@ -507,6 +507,7 @@
 	int peers_size=0, peer_offset=0;
 	ntp_assoc_status_pair *peers=NULL;
 	ntp_control_message req;
+	const char *getvar = "jitter";
 	double rval = 0.0, jitter = -1.0;
 	char *startofvalue=NULL, *nptr=NULL;
 	void *tmp;
@@ -584,8 +585,10 @@
 				 * thus reducing net traffic, guaranteeing us only a single
 				 * datagram in reply, and making intepretation much simpler
 				 */
-				strncpy(req.data, "jitter", 6);
-				req.count = htons(6);
+				/* Older servers doesn't know what jitter is, so if we get an
+				 * error on the first pass we redo it with "dispersion" */
+				strncpy(req.data, getvar, MAX_CM_SIZE-1);
+				req.count = htons(strlen(getvar));
 				DBG(printf("sending READVAR request...\n"));
 				write(conn, &req, SIZEOF_NTPCM(req));
 				DBG(print_ntp_control_message(&req));
@@ -595,6 +598,14 @@
 				read(conn, &req, SIZEOF_NTPCM(req));
 				DBG(print_ntp_control_message(&req));
 
+				if(req.op&REM_ERROR && strstr(getvar, "jitter")) {
+					if(verbose) printf("The 'jitter' command failed (old ntp server?)\nRestarting with 'dispersion'...\n");
+					getvar = "dispersion";
+					num_selected--;
+					i--;
+					continue;
+				}
+
 				/* get to the float value */
 				if(verbose) {
 					printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc));





More information about the Commits mailing list