diff -Nur nagios-plugins-1.4.13.orig/plugins/check_ntp_peer.c nagios-plugins-1.4.13/plugins/check_ntp_peer.c --- nagios-plugins-1.4.13.orig/plugins/check_ntp_peer.c 2008-09-02 14:28:04.000000000 +0200 +++ nagios-plugins-1.4.13/plugins/check_ntp_peer.c 2008-12-09 14:12:32.000000000 +0100 @@ -60,6 +60,9 @@ static short do_jitter=0; static char *jwarn="-1:5000"; static char *jcrit="-1:10000"; +static short do_peer=0; +static char *pwarn="@1"; +static char *pcrit="@1"; static int syncsource_found=0; static int li_alarm=0; @@ -67,6 +70,7 @@ thresholds *offset_thresholds = NULL; thresholds *jitter_thresholds = NULL; thresholds *stratum_thresholds = NULL; +thresholds *peer_thresholds = NULL; void print_help (void); void print_usage (void); @@ -252,7 +256,7 @@ * status is pretty much useless as syncsource_found is a global variable * used later in main to check is the server was synchronized. It works * so I left it alone */ -int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum){ +int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum, int *peer){ int conn=-1, i, npeers=0, num_candidates=0; double tmp_offset = 0; int min_peer_sel=PEER_INCLUDED; @@ -266,7 +270,7 @@ status = STATE_OK; *offset_result = STATE_UNKNOWN; - *jitter = *stratum = -1; + *jitter = *stratum = *peer = -1; /* Long-winded explanation: * Getting the sync peer offset, jitter and stratum requires a number of @@ -328,6 +332,7 @@ } } if(verbose) printf("%d candiate peers available\n", num_candidates); + *peer = num_candidates; if(verbose && syncsource_found) printf("synchronization source found\n"); if(! syncsource_found){ status = STATE_WARNING; @@ -471,6 +476,8 @@ {"scrit", required_argument, 0, 'C'}, {"jwarn", required_argument, 0, 'j'}, {"jcrit", required_argument, 0, 'k'}, + {"pwarn", required_argument, 0, 'o'}, + {"pcrit", required_argument, 0, 'P'}, {"timeout", required_argument, 0, 't'}, {"hostname", required_argument, 0, 'H'}, {"port", required_argument, 0, 'p'}, @@ -482,7 +489,7 @@ usage ("\n"); while (1) { - c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:t:H:p:", longopts, &option); + c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:t:H:p:P:o:", longopts, &option); if (c == -1 || c == EOF || c == 1) break; @@ -525,6 +532,14 @@ do_jitter=1; jcrit = optarg; break; + case 'o': + do_peer=1; + pwarn = optarg; + break; + case 'P': + do_peer=1; + pcrit = optarg; + break; case 'H': if(is_host(optarg) == FALSE) usage2(_("Invalid hostname/address"), optarg); @@ -584,8 +599,16 @@ TRUE, 0, TRUE, 16); } +char *perfd_peer (int num_peer) +{ + return perfdata ("num_peer", num_peer, "", + do_peer, (int)peer_thresholds->warning->end, + do_peer, (int)peer_thresholds->critical->end, + TRUE, 0, TRUE, 16); +} + int main(int argc, char *argv[]){ - int result, offset_result, stratum; + int result, offset_result, stratum, peer; double offset=0, jitter=0; char *result_line, *perfdata_line; @@ -602,6 +625,7 @@ set_thresholds(&offset_thresholds, owarn, ocrit); set_thresholds(&jitter_thresholds, jwarn, jcrit); set_thresholds(&stratum_thresholds, swarn, scrit); + set_thresholds(&peer_thresholds, pwarn, pcrit); /* initialize alarm signal handling */ signal (SIGALRM, socket_timeout_alarm_handler); @@ -610,7 +634,7 @@ alarm (socket_timeout); /* This returns either OK or WARNING (See comment preceeding ntp_request) */ - result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum); + result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &peer); if(offset_result == STATE_UNKNOWN) { /* if there's no sync peer (this overrides ntp_request output): */ @@ -628,6 +652,9 @@ if(do_jitter) result = max_state_alt(result, get_status(jitter, jitter_thresholds)); + if(do_peer) + result = max_state_alt(result, get_status(peer, peer_thresholds)); + switch (result) { case STATE_CRITICAL : asprintf(&result_line, _("NTP CRITICAL:")); @@ -662,6 +689,10 @@ asprintf(&result_line, "%s, stratum=%i", result_line, stratum); asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum)); } + if (do_peer) { + asprintf(&result_line, "%s, num_peer=%i", result_line, peer); + asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_peer(peer)); + } printf("%s|%s\n", result_line, perfdata_line); if(server_address!=NULL) free(server_address); @@ -698,6 +729,10 @@ printf (" %s\n", _("Warning threshold for jitter")); printf (" %s\n", "-k, --jcrit=THRESHOLD"); printf (" %s\n", _("Critical threshold for jitter")); + printf (" %s\n", "-o, --pwarn=THRESHOLD"); + printf (" %s\n", _("Warning threshold for peer")); + printf (" %s\n", "-P, --pcrit=THRESHOLD"); + printf (" %s\n", _("Critical threshold for peer")); printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); printf (_(UT_VERBOSE));