diff options
Diffstat (limited to 'plugins/check_ntp_peer.c')
-rw-r--r-- | plugins/check_ntp_peer.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index f0dd2d8..76152e1 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
@@ -241,15 +241,19 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
241 | DBG(printf("sending READSTAT request")); | 241 | DBG(printf("sending READSTAT request")); |
242 | write(conn, &req, SIZEOF_NTPCM(req)); | 242 | write(conn, &req, SIZEOF_NTPCM(req)); |
243 | DBG(print_ntp_control_message(&req)); | 243 | DBG(print_ntp_control_message(&req)); |
244 | /* Attempt to read the largest size packet possible */ | 244 | |
245 | req.count=htons(MAX_CM_SIZE); | 245 | do { |
246 | DBG(printf("recieving READSTAT response")) | 246 | /* Attempt to read the largest size packet possible */ |
247 | if(read(conn, &req, SIZEOF_NTPCM(req)) == -1) | 247 | req.count=htons(MAX_CM_SIZE); |
248 | die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n"); | 248 | DBG(printf("recieving READSTAT response")) |
249 | DBG(print_ntp_control_message(&req)); | 249 | if(read(conn, &req, SIZEOF_NTPCM(req)) == -1) |
250 | /* discard obviously invalid packets */ | 250 | die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n"); |
251 | if (ntohs(req.count) > MAX_CM_SIZE) | 251 | DBG(print_ntp_control_message(&req)); |
252 | die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); | 252 | /* discard obviously invalid packets */ |
253 | if (ntohs(req.count) > MAX_CM_SIZE) | ||
254 | die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); | ||
255 | } while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1)); | ||
256 | |||
253 | if (LI(req.flags) == LI_ALARM) li_alarm = 1; | 257 | if (LI(req.flags) == LI_ALARM) li_alarm = 1; |
254 | /* Each peer identifier is 4 bytes in the data section, which | 258 | /* Each peer identifier is 4 bytes in the data section, which |
255 | * we represent as a ntp_assoc_status_pair datatype. | 259 | * we represent as a ntp_assoc_status_pair datatype. |
@@ -312,10 +316,12 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
312 | write(conn, &req, SIZEOF_NTPCM(req)); | 316 | write(conn, &req, SIZEOF_NTPCM(req)); |
313 | DBG(print_ntp_control_message(&req)); | 317 | DBG(print_ntp_control_message(&req)); |
314 | 318 | ||
315 | req.count = htons(MAX_CM_SIZE); | 319 | do { |
316 | DBG(printf("receiving READVAR response...\n")); | 320 | req.count = htons(MAX_CM_SIZE); |
317 | read(conn, &req, SIZEOF_NTPCM(req)); | 321 | DBG(printf("receiving READVAR response...\n")); |
318 | DBG(print_ntp_control_message(&req)); | 322 | read(conn, &req, SIZEOF_NTPCM(req)); |
323 | DBG(print_ntp_control_message(&req)); | ||
324 | } while (!(req.op&OP_READVAR && ntohs(req.seq) == 2)); | ||
319 | 325 | ||
320 | if(!(req.op&REM_ERROR)) | 326 | if(!(req.op&REM_ERROR)) |
321 | xasprintf(&data, "%s%s", data, req.data); | 327 | xasprintf(&data, "%s%s", data, req.data); |
@@ -660,6 +666,7 @@ void print_help(void){ | |||
660 | print_usage(); | 666 | print_usage(); |
661 | printf (UT_HELP_VRSN); | 667 | printf (UT_HELP_VRSN); |
662 | printf (UT_EXTRA_OPTS); | 668 | printf (UT_EXTRA_OPTS); |
669 | printf (UT_IPv46); | ||
663 | printf (UT_HOST_PORT, 'p', "123"); | 670 | printf (UT_HOST_PORT, 'p', "123"); |
664 | printf (" %s\n", "-q, --quiet"); | 671 | printf (" %s\n", "-q, --quiet"); |
665 | printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized")); | 672 | printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized")); |
@@ -668,9 +675,9 @@ void print_help(void){ | |||
668 | printf (" %s\n", "-c, --critical=THRESHOLD"); | 675 | printf (" %s\n", "-c, --critical=THRESHOLD"); |
669 | printf (" %s\n", _("Offset to result in critical status (seconds)")); | 676 | printf (" %s\n", _("Offset to result in critical status (seconds)")); |
670 | printf (" %s\n", "-W, --swarn=THRESHOLD"); | 677 | printf (" %s\n", "-W, --swarn=THRESHOLD"); |
671 | printf (" %s\n", _("Warning threshold for stratum")); | 678 | printf (" %s\n", _("Warning threshold for stratum of server's synchronization peer")); |
672 | printf (" %s\n", "-C, --scrit=THRESHOLD"); | 679 | printf (" %s\n", "-C, --scrit=THRESHOLD"); |
673 | printf (" %s\n", _("Critical threshold for stratum")); | 680 | printf (" %s\n", _("Critical threshold for stratum of server's synchronization peer")); |
674 | printf (" %s\n", "-j, --jwarn=THRESHOLD"); | 681 | printf (" %s\n", "-j, --jwarn=THRESHOLD"); |
675 | printf (" %s\n", _("Warning threshold for jitter")); | 682 | printf (" %s\n", _("Warning threshold for jitter")); |
676 | printf (" %s\n", "-k, --jcrit=THRESHOLD"); | 683 | printf (" %s\n", "-k, --jcrit=THRESHOLD"); |
@@ -704,7 +711,7 @@ void print_help(void){ | |||
704 | printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200")); | 711 | printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200")); |
705 | printf("\n"); | 712 | printf("\n"); |
706 | printf(" %s\n", _("Only check the number of usable time sources (\"truechimers\"):")); | 713 | printf(" %s\n", _("Only check the number of usable time sources (\"truechimers\"):")); |
707 | printf(" %s\n", ("./check_ntp_peer -H ntpserv -m :5 -n :3")); | 714 | printf(" %s\n", ("./check_ntp_peer -H ntpserv -m @5 -n @3")); |
708 | printf("\n"); | 715 | printf("\n"); |
709 | printf(" %s\n", _("Check only stratum:")); | 716 | printf(" %s\n", _("Check only stratum:")); |
710 | printf(" %s\n", ("./check_ntp_peer -H ntpserv -W 4 -C 6")); | 717 | printf(" %s\n", ("./check_ntp_peer -H ntpserv -W 4 -C 6")); |
@@ -716,6 +723,6 @@ void | |||
716 | print_usage(void) | 723 | print_usage(void) |
717 | { | 724 | { |
718 | printf ("%s\n", _("Usage:")); | 725 | printf ("%s\n", _("Usage:")); |
719 | printf(" %s -H <host> [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname); | 726 | printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname); |
720 | printf(" [-j <warn>] [-k <crit>] [-v verbose]\n"); | 727 | printf(" [-j <warn>] [-k <crit>] [-v verbose]\n"); |
721 | } | 728 | } |