diff options
Diffstat (limited to 'plugins/check_ntp.c')
| -rw-r--r-- | plugins/check_ntp.c | 25 | 
1 files changed, 18 insertions, 7 deletions
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 16be7c51..09a923eb 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c  | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | /***************************************************************************** | 1 | /***************************************************************************** | 
| 2 | * | 2 | * | 
| 3 | * Nagios check_ntp plugin | 3 | * Monitoring check_ntp 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> | 
| 7 | * Copyright (c) 2006-2008 Nagios Plugins Development Team | 7 | * Copyright (c) 2006-2008 Monitoring Plugins Development Team | 
| 8 | * | 8 | * | 
| 9 | * Description: | 9 | * Description: | 
| 10 | * | 10 | * | 
| @@ -32,7 +32,7 @@ | |||
| 32 | 32 | ||
| 33 | const char *progname = "check_ntp"; | 33 | const char *progname = "check_ntp"; | 
| 34 | const char *copyright = "2006-2008"; | 34 | const char *copyright = "2006-2008"; | 
| 35 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 35 | const char *email = "devel@monitoring-plugins.org"; | 
| 36 | 36 | ||
| 37 | #include "common.h" | 37 | #include "common.h" | 
| 38 | #include "netutils.h" | 38 | #include "netutils.h" | 
| @@ -54,7 +54,9 @@ void print_help (void); | |||
| 54 | void print_usage (void); | 54 | void print_usage (void); | 
| 55 | 55 | ||
| 56 | /* number of times to perform each request to get a good average. */ | 56 | /* number of times to perform each request to get a good average. */ | 
| 57 | #ifndef AVG_NUM | ||
| 57 | #define AVG_NUM 4 | 58 | #define AVG_NUM 4 | 
| 59 | #endif | ||
| 58 | 60 | ||
| 59 | /* max size of control message data */ | 61 | /* max size of control message data */ | 
| 60 | #define MAX_CM_SIZE 468 | 62 | #define MAX_CM_SIZE 468 | 
| @@ -480,7 +482,7 @@ double offset_request(const char *host, int *status){ | |||
| 480 | } else { | 482 | } else { | 
| 481 | /* finally, calculate the average offset */ | 483 | /* finally, calculate the average offset */ | 
| 482 | for(i=0; i<servers[best_index].num_responses;i++){ | 484 | for(i=0; i<servers[best_index].num_responses;i++){ | 
| 483 | avg_offset+=servers[best_index].offset[j]; | 485 | avg_offset+=servers[best_index].offset[i]; | 
| 484 | } | 486 | } | 
| 485 | avg_offset/=servers[best_index].num_responses; | 487 | avg_offset/=servers[best_index].num_responses; | 
| 486 | } | 488 | } | 
| @@ -515,13 +517,14 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ | |||
| 515 | double jitter_request(const char *host, int *status){ | 517 | double jitter_request(const char *host, int *status){ | 
| 516 | int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0; | 518 | int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0; | 
| 517 | int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; | 519 | int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; | 
| 518 | int peers_size=0, peer_offset=0; | 520 | int peers_size=0, peer_offset=0, bytes_read=0; | 
| 519 | ntp_assoc_status_pair *peers=NULL; | 521 | ntp_assoc_status_pair *peers=NULL; | 
| 520 | ntp_control_message req; | 522 | ntp_control_message req; | 
| 521 | const char *getvar = "jitter"; | 523 | const char *getvar = "jitter"; | 
| 522 | double rval = 0.0, jitter = -1.0; | 524 | double rval = 0.0, jitter = -1.0; | 
| 523 | char *startofvalue=NULL, *nptr=NULL; | 525 | char *startofvalue=NULL, *nptr=NULL; | 
| 524 | void *tmp; | 526 | void *tmp; | 
| 527 | int ntp_cm_ints = sizeof(uint16_t) * 5 + sizeof(uint8_t) * 2; | ||
| 525 | 528 | ||
| 526 | /* Long-winded explanation: | 529 | /* Long-winded explanation: | 
| 527 | * Getting the jitter requires a number of steps: | 530 | * Getting the jitter requires a number of steps: | 
| @@ -606,7 +609,15 @@ double jitter_request(const char *host, int *status){ | |||
| 606 | 609 | ||
| 607 | req.count = htons(MAX_CM_SIZE); | 610 | req.count = htons(MAX_CM_SIZE); | 
| 608 | DBG(printf("recieving READVAR response...\n")); | 611 | DBG(printf("recieving READVAR response...\n")); | 
| 609 | read(conn, &req, SIZEOF_NTPCM(req)); | 612 | |
| 613 | /* cov-66524 - req.data not null terminated before usage. Also covers verifying struct was returned correctly*/ | ||
| 614 | if ((bytes_read = read(conn, &req, SIZEOF_NTPCM(req))) == -1) | ||
| 615 | die(STATE_UNKNOWN, _("Cannot read from socket: %s"), strerror(errno)); | ||
| 616 | if (bytes_read != ntp_cm_ints + req.count) | ||
| 617 | die(STATE_UNKNOWN, _("Invalid NTP response: %d bytes read does not equal %d plus %d data segment"), bytes_read, ntp_cm_ints, req.count); | ||
| 618 | /* else null terminate */ | ||
| 619 | strncpy(req.data[req.count], "\0", 1); | ||
| 620 | |||
| 610 | DBG(print_ntp_control_message(&req)); | 621 | DBG(print_ntp_control_message(&req)); | 
| 611 | 622 | ||
| 612 | if(req.op&REM_ERROR && strstr(getvar, "jitter")) { | 623 | if(req.op&REM_ERROR && strstr(getvar, "jitter")) { | 
| @@ -858,7 +869,7 @@ void print_help(void){ | |||
| 858 | printf (" %s\n", _("Warning threshold for jitter")); | 869 | printf (" %s\n", _("Warning threshold for jitter")); | 
| 859 | printf (" %s\n", "-k, --jcrit=THRESHOLD"); | 870 | printf (" %s\n", "-k, --jcrit=THRESHOLD"); | 
| 860 | printf (" %s\n", _("Critical threshold for jitter")); | 871 | printf (" %s\n", _("Critical threshold for jitter")); | 
| 861 | printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 872 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 
| 862 | printf (UT_VERBOSE); | 873 | printf (UT_VERBOSE); | 
| 863 | 874 | ||
| 864 | printf("\n"); | 875 | printf("\n"); | 
