summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_ntpd.c32
-rw-r--r--plugins/check_time_ntp.c8
2 files changed, 23 insertions, 17 deletions
diff --git a/plugins/check_ntpd.c b/plugins/check_ntpd.c
index 84ebe34d..840fe0ac 100644
--- a/plugins/check_ntpd.c
+++ b/plugins/check_ntpd.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2* 2*
3* Nagios check_ntpd plugin 3* Nagios check_ntp_peer plugin
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>
@@ -10,7 +10,7 @@
10* 10*
11* Description: 11* Description:
12* 12*
13* This file contains the check_ntpd plugin 13* This file contains the check_ntp_peer plugin
14* 14*
15* This plugin to check ntp servers independant of any commandline 15* This plugin to check ntp servers independant of any commandline
16* programs or external libraries. 16* programs or external libraries.
@@ -36,7 +36,7 @@
36 36
37*****************************************************************************/ 37*****************************************************************************/
38 38
39const char *progname = "check_ntpd"; 39const char *progname = "check_ntp_peer";
40const char *revision = "$Revision$"; 40const char *revision = "$Revision$";
41const char *copyright = "2007"; 41const char *copyright = "2007";
42const char *email = "nagiosplug-devel@lists.sourceforge.net"; 42const char *email = "nagiosplug-devel@lists.sourceforge.net";
@@ -211,6 +211,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
211 char *value=NULL, *nptr=NULL; 211 char *value=NULL, *nptr=NULL;
212 void *tmp; 212 void *tmp;
213 213
214 status = STATE_OK;
214 *offset_result = STATE_UNKNOWN; 215 *offset_result = STATE_UNKNOWN;
215 *jitter = *stratum = -1; 216 *jitter = *stratum = -1;
216 217
@@ -315,28 +316,33 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
315 printf("parsing offset from peer %.2x: ", ntohs(peers[i].assoc)); 316 printf("parsing offset from peer %.2x: ", ntohs(peers[i].assoc));
316 317
317 value = extract_value(req.data, "offset"); 318 value = extract_value(req.data, "offset");
319 /* Convert the value if we have one */
318 if(value != NULL) 320 if(value != NULL)
319 *offset = strtod(value, &nptr) / 1000; 321 *offset = strtod(value, &nptr) / 1000;
320 if(value == NULL || value==nptr){ 322 /* If value is null or no conversion was performed */
323 if(value == NULL || value==nptr) {
321 printf("warning: unable to read server offset response.\n"); 324 printf("warning: unable to read server offset response.\n");
322 status = max_state(status, STATE_CRITICAL); 325 status = max_state_alt(status, STATE_CRITICAL);
323 } else { 326 } else {
324 *offset_result = STATE_OK; 327 *offset_result = STATE_OK;
325 if(verbose) printf("%g\n", *offset); 328 if(verbose) printf("%g\n", *offset);
326 } 329 }
327 330
328 if(do_jitter) { 331 if(do_jitter) {
332 /* first reset the pointers */
329 value = NULL, nptr=NULL; 333 value = NULL, nptr=NULL;
330 /* get the jitter */ 334 /* get the jitter */
331 if(verbose) { 335 if(verbose) {
332 printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc)); 336 printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc));
333 } 337 }
334 value = extract_value(req.data, strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter"); 338 value = extract_value(req.data, strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter");
339 /* Convert the value if we have one */
335 if(value != NULL) 340 if(value != NULL)
336 *jitter = strtod(value, &nptr); 341 *jitter = strtod(value, &nptr);
342 /* If value is null or no conversion was performed */
337 if(value == NULL || value==nptr){ 343 if(value == NULL || value==nptr){
338 printf("warning: unable to read server jitter response.\n"); 344 printf("warning: unable to read server jitter response.\n");
339 status = max_state(status, STATE_UNKNOWN); 345 status = max_state_alt(status, STATE_UNKNOWN);
340 } else { 346 } else {
341 if(verbose) printf("%g\n", *jitter); 347 if(verbose) printf("%g\n", *jitter);
342 } 348 }
@@ -351,7 +357,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
351 value = extract_value(req.data, "stratum"); 357 value = extract_value(req.data, "stratum");
352 if(value == NULL){ 358 if(value == NULL){
353 printf("warning: unable to read server stratum response.\n"); 359 printf("warning: unable to read server stratum response.\n");
354 status = max_state(status, STATE_UNKNOWN); 360 status = max_state_alt(status, STATE_UNKNOWN);
355 } else { 361 } else {
356 *stratum = atoi(value); 362 *stratum = atoi(value);
357 if(verbose) printf("%i\n", *stratum); 363 if(verbose) printf("%i\n", *stratum);
@@ -508,13 +514,13 @@ int main(int argc, char *argv[]){
508 alarm (socket_timeout); 514 alarm (socket_timeout);
509 515
510 result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum); 516 result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum);
511 result = get_status(fabs(offset), offset_thresholds); 517 result = max_state_alt(result, get_status(fabs(offset), offset_thresholds));
512 518
513 if(do_stratum) 519 if(do_stratum)
514 result = max_state(result, get_status(stratum, stratum_thresholds)); 520 result = max_state_alt(result, get_status(stratum, stratum_thresholds));
515 521
516 if(do_jitter) 522 if(do_jitter)
517 result = max_state(result, get_status(jitter, jitter_thresholds)); 523 result = max_state_alt(result, get_status(jitter, jitter_thresholds));
518 524
519 switch (result) { 525 switch (result) {
520 case STATE_CRITICAL : 526 case STATE_CRITICAL :
@@ -593,12 +599,12 @@ void print_help(void){
593 printf("\n"); 599 printf("\n");
594 printf("%s\n", _("Examples:")); 600 printf("%s\n", _("Examples:"));
595 printf(" %s\n", _("Normal offset check:")); 601 printf(" %s\n", _("Normal offset check:"));
596 printf(" %s\n", ("./check_ntpd -H ntpserv -w 0.5 -c 1")); 602 printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1"));
597 printf(" %s\n", _("Check jitter too, avoiding critical notifications if jitter isn't available")); 603 printf(" %s\n", _("Check jitter too, avoiding critical notifications if jitter isn't available"));
598 printf(" %s\n", _("(See Notes above for more details on thresholds formats):")); 604 printf(" %s\n", _("(See Notes above for more details on thresholds formats):"));
599 printf(" %s\n", ("./check_ntpd -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200")); 605 printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200"));
600 printf(" %s\n", _("Check only stratum:")); 606 printf(" %s\n", _("Check only stratum:"));
601 printf(" %s\n", ("./check_ntpd -H ntpserv -W 4 -C 6")); 607 printf(" %s\n", ("./check_ntp_peer -H ntpserv -W 4 -C 6"));
602 608
603 printf (_(UT_SUPPORT)); 609 printf (_(UT_SUPPORT));
604} 610}
diff --git a/plugins/check_time_ntp.c b/plugins/check_time_ntp.c
index ac332acb..c945076d 100644
--- a/plugins/check_time_ntp.c
+++ b/plugins/check_time_ntp.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2* 2*
3* Nagios check_time_ntp plugin 3* Nagios check_ntp_time plugin
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>
@@ -10,7 +10,7 @@
10* 10*
11* Description: 11* Description:
12* 12*
13* This file contains the check_time_ntp plugin 13* This file contains the check_ntp_time plugin
14* 14*
15* This plugin checks the clock offset with an NTP server. It is 15* This plugin checks the clock offset with an NTP server. It is
16* independant of any commandline programs or external libraries. 16* independant of any commandline programs or external libraries.
@@ -36,7 +36,7 @@
36 36
37*****************************************************************************/ 37*****************************************************************************/
38 38
39const char *progname = "check_time_ntp"; 39const char *progname = "check_ntp_time";
40const char *revision = "$Revision$"; 40const char *revision = "$Revision$";
41const char *copyright = "2007"; 41const char *copyright = "2007";
42const char *email = "nagiosplug-devel@lists.sourceforge.net"; 42const char *email = "nagiosplug-devel@lists.sourceforge.net";
@@ -600,7 +600,7 @@ void print_help(void){
600 600
601 printf("\n"); 601 printf("\n");
602 printf("%s\n", _("Examples:")); 602 printf("%s\n", _("Examples:"));
603 printf(" %s\n", ("./check_time_ntp -H ntpserv -w 0.5 -c 1")); 603 printf(" %s\n", ("./check_ntp_time -H ntpserv -w 0.5 -c 1"));
604 604
605 printf (_(UT_SUPPORT)); 605 printf (_(UT_SUPPORT));
606} 606}