summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-01-29 08:54:48 (GMT)
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-01-29 08:54:48 (GMT)
commit34cfb0c1034a6b3289e9aca567fd2393126aa80a (patch)
treec9e725021b2c6d7144203c8d71b590f873f20457
parent08d81dc7bd9a0c292b5dd7494da4b85cacb1c210 (diff)
downloadmonitoring-plugins-34cfb0c1034a6b3289e9aca567fd2393126aa80a.tar.gz
Fix bugs and flaws in best offset server selection of check_ntp_time and (deprecated) check_ntp
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1909 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--NEWS3
-rw-r--r--plugins/check_ntp.c68
-rw-r--r--plugins/check_ntp_time.c68
3 files changed, 72 insertions, 67 deletions
diff --git a/NEWS b/NEWS
index 8e5a494..628210d 100644
--- a/NEWS
+++ b/NEWS
@@ -4,10 +4,11 @@ This file documents the major additions and syntax changes between releases.
4 Added ./check_nt -v INSTANCES to count number of instances (Alessandro Ren) 4 Added ./check_nt -v INSTANCES to count number of instances (Alessandro Ren)
5 New check_icmp -s option to specify the source IP address 5 New check_icmp -s option to specify the source IP address
6 check_dns now sorts addresses for testing results for more than one returned IP (Matthias Urlichs) 6 check_dns now sorts addresses for testing results for more than one returned IP (Matthias Urlichs)
7 Fix segfault in check_ntp_time and (deprecated) check_ntp. (Bug #1862300) 7 Fix segfault in check_ntp_time and (deprecated) check_ntp (Bug #1862300)
8 check_disk should now work with large file systems (2TB+) on all archs that supports it 8 check_disk should now work with large file systems (2TB+) on all archs that supports it
9 Fixed check_disk disk usage calculation when using --group=NAME (related to bug #1348746) 9 Fixed check_disk disk usage calculation when using --group=NAME (related to bug #1348746)
10 Fix help text of check_ntp_* (Bug #1880095) 10 Fix help text of check_ntp_* (Bug #1880095)
11 Fix bugs and flaws in best offset server selection of check_ntp_time and (deprecated) check_ntp
11 12
121.4.11 13th December 2007 131.4.11 13th December 2007
13 Fixed check_http regression in 1.4.10 where following redirects to 14 Fixed check_http regression in 1.4.10 where following redirects to
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index b474d9a..2b3cc91 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -302,50 +302,52 @@ void setup_request(ntp_message *p){
302 * this is done by filtering servers based on stratum, dispersion, and 302 * this is done by filtering servers based on stratum, dispersion, and
303 * finally round-trip delay. */ 303 * finally round-trip delay. */
304int best_offset_server(const ntp_server_results *slist, int nservers){ 304int best_offset_server(const ntp_server_results *slist, int nservers){
305 int i=0, j=0, cserver=0, candidates[5], csize=0; 305 int i=0, cserver=0, best_server=-1;
306 306
307 /* for each server */ 307 /* for each server */
308 for(cserver=0; cserver<nservers; cserver++){ 308 for(cserver=0; cserver<nservers; cserver++){
309 /* sort out servers with error flags */ 309 /* We don't want any servers that fails these tests */
310 if ( LI(slist[cserver].flags) != LI_NOWARNING ){ 310 /* Sort out servers that didn't respond or responede with a 0 stratum;
311 if (verbose) printf("discarding peer id %d: flags=%d\n", cserver, LI(slist[cserver].flags)); 311 * stratum 0 is for reference clocks so no NTP server should ever report
312 break; 312 * a stratum 0 */
313 if ( slist[cserver].stratum == 0){
314 if (verbose) printf("discarding peer %d: stratum=%d\n", cserver, slist[cserver].stratum);
315 continue;
316 }
317 /* Sort out servers with error flags */
318 if ( LI(slist[cserver].flags) == LI_ALARM ){
319 if (verbose) printf("discarding peer %d: flags=%d\n", cserver, LI(slist[cserver].flags));
320 continue;
313 } 321 }
314 322
315 /* compare it to each of the servers already in the candidate list */ 323 /* If we don't have a server yet, use the first one */
316 for(i=0; i<csize; i++){ 324 if (best_server == -1) {
317 /* does it have an equal or better stratum? */ 325 best_server = cserver;
318 if(slist[cserver].stratum <= slist[i].stratum){ 326 DBG(printf("using peer %d as our first candidate\n", best_server));
319 /* does it have an equal or better dispersion? */ 327 continue;
320 if(slist[cserver].rtdisp <= slist[i].rtdisp){
321 /* does it have a better rtdelay? */
322 if(slist[cserver].rtdelay < slist[i].rtdelay){
323 break;
324 }
325 }
326 }
327 } 328 }
328 329
329 /* if we haven't reached the current list's end, move everyone 330 /* compare the server to the best one we've seen so far */
330 * over one to the right, and insert the new candidate */ 331 /* does it have an equal or better stratum? */
331 if(i<csize){ 332 DBG(printf("comparing peer %d with peer %d\n", cserver, best_server));
332 for(j=4; j>i; j--){ 333 if(slist[cserver].stratum <= slist[best_server].stratum){
333 candidates[j]=candidates[j-1]; 334 DBG(printf("stratum for peer %d <= peer %d\n", cserver, best_server));
335 /* does it have an equal or better dispersion? */
336 if(slist[cserver].rtdisp <= slist[best_server].rtdisp){
337 DBG(printf("dispersion for peer %d <= peer %d\n", cserver, best_server));
338 /* does it have a better rtdelay? */
339 if(slist[cserver].rtdelay < slist[best_server].rtdelay){
340 DBG(printf("rtdelay for peer %d < peer %d\n", cserver, best_server));
341 best_server = cserver;
342 DBG(printf("peer %d is now our best candidate\n", best_server));
343 }
334 } 344 }
335 } 345 }
336 /* regardless, if they should be on the list... */
337 if(i<5) {
338 candidates[i]=cserver;
339 if(csize<5) csize++;
340 /* otherwise discard the server */
341 } else {
342 DBG(printf("discarding peer id %d\n", cserver));
343 }
344 } 346 }
345 347
346 if(csize>0) { 348 if(best_server >= 0) {
347 DBG(printf("best server selected: peer %d\n", candidates[0])); 349 DBG(printf("best server selected: peer %d\n", best_server));
348 return candidates[0]; 350 return best_server;
349 } else { 351 } else {
350 DBG(printf("no peers meeting synchronization criteria :(\n")); 352 DBG(printf("no peers meeting synchronization criteria :(\n"));
351 return -1; 353 return -1;
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c
index 16e4c3c..11a0ece 100644
--- a/plugins/check_ntp_time.c
+++ b/plugins/check_ntp_time.c
@@ -247,50 +247,52 @@ void setup_request(ntp_message *p){
247 * this is done by filtering servers based on stratum, dispersion, and 247 * this is done by filtering servers based on stratum, dispersion, and
248 * finally round-trip delay. */ 248 * finally round-trip delay. */
249int best_offset_server(const ntp_server_results *slist, int nservers){ 249int best_offset_server(const ntp_server_results *slist, int nservers){
250 int i=0, j=0, cserver=0, candidates[5], csize=0; 250 int i=0, cserver=0, best_server=-1;
251 251
252 /* for each server */ 252 /* for each server */
253 for(cserver=0; cserver<nservers; cserver++){ 253 for(cserver=0; cserver<nservers; cserver++){
254 /* sort out servers with error flags */ 254 /* We don't want any servers that fails these tests */
255 if ( LI(slist[cserver].flags) != LI_NOWARNING ){ 255 /* Sort out servers that didn't respond or responede with a 0 stratum;
256 if (verbose) printf("discarding peer id %d: flags=%d\n", cserver, LI(slist[cserver].flags)); 256 * stratum 0 is for reference clocks so no NTP server should ever report
257 break; 257 * a stratum 0 */
258 if ( slist[cserver].stratum == 0){
259 if (verbose) printf("discarding peer %d: stratum=%d\n", cserver, slist[cserver].stratum);
260 continue;
261 }
262 /* Sort out servers with error flags */
263 if ( LI(slist[cserver].flags) == LI_ALARM ){
264 if (verbose) printf("discarding peer %d: flags=%d\n", cserver, LI(slist[cserver].flags));
265 continue;
258 } 266 }
259 267
260 /* compare it to each of the servers already in the candidate list */ 268 /* If we don't have a server yet, use the first one */
261 for(i=0; i<csize; i++){ 269 if (best_server == -1) {
262 /* does it have an equal or better stratum? */ 270 best_server = cserver;
263 if(slist[cserver].stratum <= slist[i].stratum){ 271 DBG(printf("using peer %d as our first candidate\n", best_server));
264 /* does it have an equal or better dispersion? */ 272 continue;
265 if(slist[cserver].rtdisp <= slist[i].rtdisp){
266 /* does it have a better rtdelay? */
267 if(slist[cserver].rtdelay < slist[i].rtdelay){
268 break;
269 }
270 }
271 }
272 } 273 }
273 274
274 /* if we haven't reached the current list's end, move everyone 275 /* compare the server to the best one we've seen so far */
275 * over one to the right, and insert the new candidate */ 276 /* does it have an equal or better stratum? */
276 if(i<csize){ 277 DBG(printf("comparing peer %d with peer %d\n", cserver, best_server));
277 for(j=4; j>i; j--){ 278 if(slist[cserver].stratum <= slist[best_server].stratum){
278 candidates[j]=candidates[j-1]; 279 DBG(printf("stratum for peer %d <= peer %d\n", cserver, best_server));
280 /* does it have an equal or better dispersion? */
281 if(slist[cserver].rtdisp <= slist[best_server].rtdisp){
282 DBG(printf("dispersion for peer %d <= peer %d\n", cserver, best_server));
283 /* does it have a better rtdelay? */
284 if(slist[cserver].rtdelay < slist[best_server].rtdelay){
285 DBG(printf("rtdelay for peer %d < peer %d\n", cserver, best_server));
286 best_server = cserver;
287 DBG(printf("peer %d is now our best candidate\n", best_server));
288 }
279 } 289 }
280 } 290 }
281 /* regardless, if they should be on the list... */
282 if(i<5) {
283 candidates[i]=cserver;
284 if(csize<5) csize++;
285 /* otherwise discard the server */
286 } else {
287 DBG(printf("discarding peer id %d\n", cserver));
288 }
289 } 291 }
290 292
291 if(csize>0) { 293 if(best_server >= 0) {
292 DBG(printf("best server selected: peer %d\n", candidates[0])); 294 DBG(printf("best server selected: peer %d\n", best_server));
293 return candidates[0]; 295 return best_server;
294 } else { 296 } else {
295 DBG(printf("no peers meeting synchronization criteria :(\n")); 297 DBG(printf("no peers meeting synchronization criteria :(\n"));
296 return -1; 298 return -1;