Reverted check_procs for solaris back to using pst3 due to truncation
[monitoring-plugins.git] / plugins / check_ntp_peer.c
blob753b7b25b0a964d3e7af78793e719cfc64a39e42
1 /*****************************************************************************
2 *
3 * Nagios check_ntp_peer plugin
4 *
5 * License: GPL
6 * Copyright (c) 2006 Sean Finney <seanius@seanius.net>
7 * Copyright (c) 2006-2008 Nagios Plugins Development Team
8 *
9 * Last Modified: $Date$
11 * Description:
13 * This file contains the check_ntp_peer plugin
15 * This plugin checks an NTP server independent of any commandline
16 * programs or external libraries.
18 * Use this plugin to check the health of an NTP server. It supports
19 * checking the offset with the sync peer, the jitter and stratum. This
20 * plugin will not check the clock offset between the local host and NTP
21 * server; please use check_ntp_time for that purpose.
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 * $Id$
39 *****************************************************************************/
41 const char *progname = "check_ntp_peer";
42 const char *revision = "$Revision$";
43 const char *copyright = "2006-2008";
44 const char *email = "nagiosplug-devel@lists.sourceforge.net";
46 #include "common.h"
47 #include "netutils.h"
48 #include "utils.h"
50 static char *server_address=NULL;
51 static int verbose=0;
52 static int quiet=0;
53 static short do_offset=0;
54 static char *owarn="60";
55 static char *ocrit="120";
56 static short do_stratum=0;
57 static char *swarn="-1:16";
58 static char *scrit="-1:16";
59 static short do_jitter=0;
60 static char *jwarn="-1:5000";
61 static char *jcrit="-1:10000";
62 static int syncsource_found=0;
63 static int li_alarm=0;
65 int process_arguments (int, char **);
66 thresholds *offset_thresholds = NULL;
67 thresholds *jitter_thresholds = NULL;
68 thresholds *stratum_thresholds = NULL;
69 void print_help (void);
70 void print_usage (void);
72 /* max size of control message data */
73 #define MAX_CM_SIZE 468
75 /* this structure holds everything in an ntp control message as per rfc1305 */
76 typedef struct {
77 uint8_t flags; /* byte with leapindicator,vers,mode. see macros */
78 uint8_t op; /* R,E,M bits and Opcode */
79 uint16_t seq; /* Packet sequence */
80 uint16_t status; /* Clock status */
81 uint16_t assoc; /* Association */
82 uint16_t offset; /* Similar to TCP sequence # */
83 uint16_t count; /* # bytes of data */
84 char data[MAX_CM_SIZE]; /* ASCII data of the request */
85 /* NB: not necessarily NULL terminated! */
86 } ntp_control_message;
88 /* this is an association/status-word pair found in control packet reponses */
89 typedef struct {
90 uint16_t assoc;
91 uint16_t status;
92 } ntp_assoc_status_pair;
94 /* bits 1,2 are the leap indicator */
95 #define LI_MASK 0xc0
96 #define LI(x) ((x&LI_MASK)>>6)
97 #define LI_SET(x,y) do{ x |= ((y<<6)&LI_MASK); }while(0)
98 /* and these are the values of the leap indicator */
99 #define LI_NOWARNING 0x00
100 #define LI_EXTRASEC 0x01
101 #define LI_MISSINGSEC 0x02
102 #define LI_ALARM 0x03
103 /* bits 3,4,5 are the ntp version */
104 #define VN_MASK 0x38
105 #define VN(x) ((x&VN_MASK)>>3)
106 #define VN_SET(x,y) do{ x |= ((y<<3)&VN_MASK); }while(0)
107 #define VN_RESERVED 0x02
108 /* bits 6,7,8 are the ntp mode */
109 #define MODE_MASK 0x07
110 #define MODE(x) (x&MODE_MASK)
111 #define MODE_SET(x,y) do{ x |= (y&MODE_MASK); }while(0)
112 /* here are some values */
113 #define MODE_CLIENT 0x03
114 #define MODE_CONTROLMSG 0x06
115 /* In control message, bits 8-10 are R,E,M bits */
116 #define REM_MASK 0xe0
117 #define REM_RESP 0x80
118 #define REM_ERROR 0x40
119 #define REM_MORE 0x20
120 /* In control message, bits 11 - 15 are opcode */
121 #define OP_MASK 0x1f
122 #define OP_SET(x,y) do{ x |= (y&OP_MASK); }while(0)
123 #define OP_READSTAT 0x01
124 #define OP_READVAR 0x02
125 /* In peer status bytes, bits 6,7,8 determine clock selection status */
126 #define PEER_SEL(x) ((ntohs(x)>>8)&0x07)
127 #define PEER_INCLUDED 0x04
128 #define PEER_SYNCSOURCE 0x06
130 /* NTP control message header is 12 bytes, plus any data in the data
131 * field, plus null padding to the nearest 32-bit boundary per rfc.
133 #define SIZEOF_NTPCM(m) (12+ntohs(m.count)+((m.count)?4-(ntohs(m.count)%4):0))
135 /* finally, a little helper or two for debugging: */
136 #define DBG(x) do{if(verbose>1){ x; }}while(0);
137 #define PRINTSOCKADDR(x) \
138 do{ \
139 printf("%u.%u.%u.%u", (x>>24)&0xff, (x>>16)&0xff, (x>>8)&0xff, x&0xff);\
140 }while(0);
142 void print_ntp_control_message(const ntp_control_message *p){
143 int i=0, numpeers=0;
144 const ntp_assoc_status_pair *peer=NULL;
146 printf("control packet contents:\n");
147 printf("\tflags: 0x%.2x , 0x%.2x\n", p->flags, p->op);
148 printf("\t li=%d (0x%.2x)\n", LI(p->flags), p->flags&LI_MASK);
149 printf("\t vn=%d (0x%.2x)\n", VN(p->flags), p->flags&VN_MASK);
150 printf("\t mode=%d (0x%.2x)\n", MODE(p->flags), p->flags&MODE_MASK);
151 printf("\t response=%d (0x%.2x)\n", (p->op&REM_RESP)>0, p->op&REM_RESP);
152 printf("\t more=%d (0x%.2x)\n", (p->op&REM_MORE)>0, p->op&REM_MORE);
153 printf("\t error=%d (0x%.2x)\n", (p->op&REM_ERROR)>0, p->op&REM_ERROR);
154 printf("\t op=%d (0x%.2x)\n", p->op&OP_MASK, p->op&OP_MASK);
155 printf("\tsequence: %d (0x%.2x)\n", ntohs(p->seq), ntohs(p->seq));
156 printf("\tstatus: %d (0x%.2x)\n", ntohs(p->status), ntohs(p->status));
157 printf("\tassoc: %d (0x%.2x)\n", ntohs(p->assoc), ntohs(p->assoc));
158 printf("\toffset: %d (0x%.2x)\n", ntohs(p->offset), ntohs(p->offset));
159 printf("\tcount: %d (0x%.2x)\n", ntohs(p->count), ntohs(p->count));
160 numpeers=ntohs(p->count)/(sizeof(ntp_assoc_status_pair));
161 if(p->op&REM_RESP && p->op&OP_READSTAT){
162 peer=(ntp_assoc_status_pair*)p->data;
163 for(i=0;i<numpeers;i++){
164 printf("\tpeer id %.2x status %.2x",
165 ntohs(peer[i].assoc), ntohs(peer[i].status));
166 if (PEER_SEL(peer[i].status) >= PEER_INCLUDED){
167 if(PEER_SEL(peer[i].status) >= PEER_SYNCSOURCE){
168 printf(" <-- current sync source");
169 } else {
170 printf(" <-- current sync candidate");
173 printf("\n");
178 char *extract_value(const char *varlist, const char *name){
179 char *tmpvarlist=NULL, *tmpkey=NULL, *value=NULL;
180 int last=0;
182 /* The following code require a non-empty varlist */
183 if(strlen(varlist) == 0)
184 return NULL;
186 tmpvarlist = strdup(varlist);
187 tmpkey = strtok(tmpvarlist, "=");
189 do {
190 if(strstr(tmpkey, name) != NULL) {
191 value = strtok(NULL, ",");
192 last = 1;
194 } while (last == 0 && (tmpkey = strtok(NULL, "=")));
196 return value;
199 void
200 setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){
201 memset(p, 0, sizeof(ntp_control_message));
202 LI_SET(p->flags, LI_NOWARNING);
203 VN_SET(p->flags, VN_RESERVED);
204 MODE_SET(p->flags, MODE_CONTROLMSG);
205 OP_SET(p->op, opcode);
206 p->seq = htons(seq);
207 /* Remaining fields are zero for requests */
210 /* This function does all the actual work; roughly here's what it does
211 * beside setting the offest, jitter and stratum passed as argument:
212 * - offset can be negative, so if it cannot get the offset, offset_result
213 * is set to UNKNOWN, otherwise OK.
214 * - jitter and stratum are set to -1 if they cannot be retrieved so any
215 * positive value means a success retrieving the value.
216 * - status is set to WARNING if there's no sync.peer (otherwise OK) and is
217 * the return value of the function.
218 * status is pretty much useless as syncsource_found is a global variable
219 * used later in main to check is the server was synchronized. It works
220 * so I left it alone */
221 int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum){
222 int conn=-1, i, npeers=0, num_candidates=0;
223 double tmp_offset = 0;
224 int min_peer_sel=PEER_INCLUDED;
225 int peers_size=0, peer_offset=0;
226 int status;
227 ntp_assoc_status_pair *peers=NULL;
228 ntp_control_message req;
229 const char *getvar = "stratum,offset,jitter";
230 char *data, *value, *nptr;
231 void *tmp;
233 status = STATE_OK;
234 *offset_result = STATE_UNKNOWN;
235 *jitter = *stratum = -1;
237 /* Long-winded explanation:
238 * Getting the sync peer offset, jitter and stratum requires a number of
239 * steps:
240 * 1) Send a READSTAT request.
241 * 2) Interpret the READSTAT reply
242 * a) The data section contains a list of peer identifiers (16 bits)
243 * and associated status words (16 bits)
244 * b) We want the value of 0x06 in the SEL (peer selection) value,
245 * which means "current synchronizatin source". If that's missing,
246 * we take anything better than 0x04 (see the rfc for details) but
247 * set a minimum of warning.
248 * 3) Send a READVAR request for information on each peer identified
249 * in 2b greater than the minimum selection value.
250 * 4) Extract the offset, jitter and stratum value from the data[]
251 * (it's ASCII)
253 my_udp_connect(server_address, 123, &conn);
255 /* keep sending requests until the server stops setting the
256 * REM_MORE bit, though usually this is only 1 packet. */
258 setup_control_request(&req, OP_READSTAT, 1);
259 DBG(printf("sending READSTAT request"));
260 write(conn, &req, SIZEOF_NTPCM(req));
261 DBG(print_ntp_control_message(&req));
262 /* Attempt to read the largest size packet possible */
263 req.count=htons(MAX_CM_SIZE);
264 DBG(printf("recieving READSTAT response"))
265 if(read(conn, &req, SIZEOF_NTPCM(req)) == -1)
266 die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n");
267 DBG(print_ntp_control_message(&req));
268 if (LI(req.flags) == LI_ALARM) li_alarm = 1;
269 /* Each peer identifier is 4 bytes in the data section, which
270 * we represent as a ntp_assoc_status_pair datatype.
272 peers_size+=ntohs(req.count);
273 if((tmp=realloc(peers, peers_size)) == NULL)
274 free(peers), die(STATE_UNKNOWN, "can not (re)allocate 'peers' buffer\n");
275 peers=tmp;
276 memcpy((void*)((ptrdiff_t)peers+peer_offset), (void*)req.data, ntohs(req.count));
277 npeers=peers_size/sizeof(ntp_assoc_status_pair);
278 peer_offset+=ntohs(req.count);
279 } while(req.op&REM_MORE);
281 /* first, let's find out if we have a sync source, or if there are
282 * at least some candidates. In the latter case we'll issue
283 * a warning but go ahead with the check on them. */
284 for (i = 0; i < npeers; i++){
285 if (PEER_SEL(peers[i].status) >= PEER_INCLUDED){
286 num_candidates++;
287 if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){
288 syncsource_found=1;
289 min_peer_sel=PEER_SYNCSOURCE;
293 if(verbose) printf("%d candiate peers available\n", num_candidates);
294 if(verbose && syncsource_found) printf("synchronization source found\n");
295 if(! syncsource_found){
296 status = STATE_WARNING;
297 if(verbose) printf("warning: no synchronization source found\n");
299 if(li_alarm){
300 status = STATE_WARNING;
301 if(verbose) printf("warning: LI_ALARM bit is set\n");
305 for (i = 0; i < npeers; i++){
306 /* Only query this server if it is the current sync source */
307 /* If there's no sync.peer, query all candidates and use the best one */
308 if (PEER_SEL(peers[i].status) >= min_peer_sel){
309 if(verbose) printf("Getting offset, jitter and stratum for peer %.2x\n", ntohs(peers[i].assoc));
310 asprintf(&data, "");
312 setup_control_request(&req, OP_READVAR, 2);
313 req.assoc = peers[i].assoc;
314 /* Putting the wanted variable names in the request
315 * cause the server to provide _only_ the requested values.
316 * thus reducing net traffic, guaranteeing us only a single
317 * datagram in reply, and making intepretation much simpler
319 /* Older servers doesn't know what jitter is, so if we get an
320 * error on the first pass we redo it with "dispersion" */
321 strncpy(req.data, getvar, MAX_CM_SIZE-1);
322 req.count = htons(strlen(getvar));
323 DBG(printf("sending READVAR request...\n"));
324 write(conn, &req, SIZEOF_NTPCM(req));
325 DBG(print_ntp_control_message(&req));
327 req.count = htons(MAX_CM_SIZE);
328 DBG(printf("receiving READVAR response...\n"));
329 read(conn, &req, SIZEOF_NTPCM(req));
330 DBG(print_ntp_control_message(&req));
332 if(!(req.op&REM_ERROR))
333 asprintf(&data, "%s%s", data, req.data);
334 } while(req.op&REM_MORE);
336 if(req.op&REM_ERROR) {
337 if(strstr(getvar, "jitter")) {
338 if(verbose) printf("The command failed. This is usually caused by servers refusing the 'jitter'\nvariable. Restarting with 'dispersion'...\n");
339 getvar = "stratum,offset,dispersion";
340 i--;
341 continue;
342 } else if(strlen(getvar)) {
343 if(verbose) printf("Server didn't like dispersion either; will retrieve everything\n");
344 getvar = "";
345 i--;
346 continue;
350 if(verbose > 1)
351 printf("Server responded: >>>%s<<<\n", data);
353 /* get the offset */
354 if(verbose)
355 printf("parsing offset from peer %.2x: ", ntohs(peers[i].assoc));
357 value = extract_value(data, "offset");
358 nptr=NULL;
359 /* Convert the value if we have one */
360 if(value != NULL)
361 tmp_offset = strtod(value, &nptr) / 1000;
362 /* If value is null or no conversion was performed */
363 if(value == NULL || value==nptr) {
364 if(verbose) printf("error: unable to read server offset response.\n");
365 } else {
366 if(verbose) printf("%.10g\n", tmp_offset);
367 if(*offset_result == STATE_UNKNOWN || fabs(tmp_offset) < fabs(*offset)) {
368 *offset = tmp_offset;
369 *offset_result = STATE_OK;
370 } else {
371 /* Skip this one; move to the next */
372 continue;
376 if(do_jitter) {
377 /* get the jitter */
378 if(verbose) {
379 printf("parsing %s from peer %.2x: ", strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter", ntohs(peers[i].assoc));
381 value = extract_value(data, strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter");
382 nptr=NULL;
383 /* Convert the value if we have one */
384 if(value != NULL)
385 *jitter = strtod(value, &nptr);
386 /* If value is null or no conversion was performed */
387 if(value == NULL || value==nptr) {
388 if(verbose) printf("error: unable to read server jitter/dispersion response.\n");
389 *jitter = -1;
390 } else if(verbose) {
391 printf("%.10g\n", *jitter);
395 if(do_stratum) {
396 /* get the stratum */
397 if(verbose) {
398 printf("parsing stratum from peer %.2x: ", ntohs(peers[i].assoc));
400 value = extract_value(data, "stratum");
401 nptr=NULL;
402 /* Convert the value if we have one */
403 if(value != NULL)
404 *stratum = strtol(value, &nptr, 10);
405 if(value == NULL || value==nptr) {
406 if(verbose) printf("error: unable to read server stratum response.\n");
407 *stratum = -1;
408 } else {
409 if(verbose) printf("%i\n", *stratum);
412 } /* if (PEER_SEL(peers[i].status) >= min_peer_sel) */
413 } /* for (i = 0; i < npeers; i++) */
415 close(conn);
416 if(peers!=NULL) free(peers);
418 return status;
421 int process_arguments(int argc, char **argv){
422 int c;
423 int option=0;
424 static struct option longopts[] = {
425 {"version", no_argument, 0, 'V'},
426 {"help", no_argument, 0, 'h'},
427 {"verbose", no_argument, 0, 'v'},
428 {"use-ipv4", no_argument, 0, '4'},
429 {"use-ipv6", no_argument, 0, '6'},
430 {"quiet", no_argument, 0, 'q'},
431 {"warning", required_argument, 0, 'w'},
432 {"critical", required_argument, 0, 'c'},
433 {"swarn", required_argument, 0, 'W'},
434 {"scrit", required_argument, 0, 'C'},
435 {"jwarn", required_argument, 0, 'j'},
436 {"jcrit", required_argument, 0, 'k'},
437 {"timeout", required_argument, 0, 't'},
438 {"hostname", required_argument, 0, 'H'},
439 {0, 0, 0, 0}
443 if (argc < 2)
444 usage ("\n");
446 while (1) {
447 c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:t:H:", longopts, &option);
448 if (c == -1 || c == EOF || c == 1)
449 break;
451 switch (c) {
452 case 'h':
453 print_help();
454 exit(STATE_OK);
455 break;
456 case 'V':
457 print_revision(progname, revision);
458 exit(STATE_OK);
459 break;
460 case 'v':
461 verbose++;
462 break;
463 case 'q':
464 quiet = 1;
465 break;
466 case 'w':
467 do_offset=1;
468 owarn = optarg;
469 break;
470 case 'c':
471 do_offset=1;
472 ocrit = optarg;
473 break;
474 case 'W':
475 do_stratum=1;
476 swarn = optarg;
477 break;
478 case 'C':
479 do_stratum=1;
480 scrit = optarg;
481 break;
482 case 'j':
483 do_jitter=1;
484 jwarn = optarg;
485 break;
486 case 'k':
487 do_jitter=1;
488 jcrit = optarg;
489 break;
490 case 'H':
491 if(is_host(optarg) == FALSE)
492 usage2(_("Invalid hostname/address"), optarg);
493 server_address = strdup(optarg);
494 break;
495 case 't':
496 socket_timeout=atoi(optarg);
497 break;
498 case '4':
499 address_family = AF_INET;
500 break;
501 case '6':
502 #ifdef USE_IPV6
503 address_family = AF_INET6;
504 #else
505 usage4 (_("IPv6 support not available"));
506 #endif
507 break;
508 case '?':
509 /* print short usage statement if args not parsable */
510 usage5 ();
511 break;
515 if(server_address == NULL){
516 usage4(_("Hostname was not supplied"));
519 return 0;
522 char *perfd_offset (double offset)
524 return fperfdata ("offset", offset, "s",
525 TRUE, offset_thresholds->warning->end,
526 TRUE, offset_thresholds->critical->end,
527 FALSE, 0, FALSE, 0);
530 char *perfd_jitter (double jitter)
532 return fperfdata ("jitter", jitter, "",
533 do_jitter, jitter_thresholds->warning->end,
534 do_jitter, jitter_thresholds->critical->end,
535 TRUE, 0, FALSE, 0);
538 char *perfd_stratum (int stratum)
540 return perfdata ("stratum", stratum, "",
541 do_stratum, (int)stratum_thresholds->warning->end,
542 do_stratum, (int)stratum_thresholds->critical->end,
543 TRUE, 0, TRUE, 16);
546 int main(int argc, char *argv[]){
547 int result, offset_result, stratum;
548 double offset=0, jitter=0;
549 char *result_line, *perfdata_line;
551 setlocale (LC_ALL, "");
552 bindtextdomain (PACKAGE, LOCALEDIR);
553 textdomain (PACKAGE);
555 if (process_arguments (argc, argv) == ERROR)
556 usage4 (_("Could not parse arguments"));
558 set_thresholds(&offset_thresholds, owarn, ocrit);
559 set_thresholds(&jitter_thresholds, jwarn, jcrit);
560 set_thresholds(&stratum_thresholds, swarn, scrit);
562 /* initialize alarm signal handling */
563 signal (SIGALRM, socket_timeout_alarm_handler);
565 /* set socket timeout */
566 alarm (socket_timeout);
568 /* This returns either OK or WARNING (See comment preceeding ntp_request) */
569 result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum);
571 if(offset_result == STATE_UNKNOWN) {
572 /* if there's no sync peer (this overrides ntp_request output): */
573 result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL);
574 } else {
575 /* Be quiet if there's no candidates either */
576 if (quiet == 1 && result == STATE_WARNING)
577 result = STATE_UNKNOWN;
578 result = max_state_alt(result, get_status(fabs(offset), offset_thresholds));
581 if(do_stratum)
582 result = max_state_alt(result, get_status(stratum, stratum_thresholds));
584 if(do_jitter)
585 result = max_state_alt(result, get_status(jitter, jitter_thresholds));
587 switch (result) {
588 case STATE_CRITICAL :
589 asprintf(&result_line, _("NTP CRITICAL:"));
590 break;
591 case STATE_WARNING :
592 asprintf(&result_line, _("NTP WARNING:"));
593 break;
594 case STATE_OK :
595 asprintf(&result_line, _("NTP OK:"));
596 break;
597 default :
598 asprintf(&result_line, _("NTP UNKNOWN:"));
599 break;
601 if(!syncsource_found)
602 asprintf(&result_line, "%s %s,", result_line, _("Server not synchronized"));
603 else if(li_alarm)
604 asprintf(&result_line, "%s %s,", result_line, _("Server has the LI_ALARM bit set"));
606 if(offset_result == STATE_UNKNOWN){
607 asprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
608 asprintf(&perfdata_line, "");
609 } else {
610 asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
611 asprintf(&perfdata_line, "%s", perfd_offset(offset));
613 if (do_jitter) {
614 asprintf(&result_line, "%s, jitter=%f", result_line, jitter);
615 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
617 if (do_stratum) {
618 asprintf(&result_line, "%s, stratum=%i", result_line, stratum);
619 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
621 printf("%s|%s\n", result_line, perfdata_line);
623 if(server_address!=NULL) free(server_address);
624 return result;
629 void print_help(void){
630 print_revision(progname, revision);
632 printf ("Copyright (c) 2006 Sean Finney\n");
633 printf (COPYRIGHT, copyright, email);
635 printf ("%s\n", _("This plugin checks the selected ntp server"));
637 printf ("\n\n");
639 print_usage();
640 printf (_(UT_HELP_VRSN));
641 printf (_(UT_HOST_PORT), 'p', "123");
642 printf (" %s\n", "-q, --quiet");
643 printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized"));
644 printf (" %s\n", "-w, --warning=THRESHOLD");
645 printf (" %s\n", _("Offset to result in warning status (seconds)"));
646 printf (" %s\n", "-c, --critical=THRESHOLD");
647 printf (" %s\n", _("Offset to result in critical status (seconds)"));
648 printf (" %s\n", "-W, --warning=THRESHOLD");
649 printf (" %s\n", _("Warning threshold for stratum"));
650 printf (" %s\n", "-C, --critical=THRESHOLD");
651 printf (" %s\n", _("Critical threshold for stratum"));
652 printf (" %s\n", "-j, --warning=THRESHOLD");
653 printf (" %s\n", _("Warning threshold for jitter"));
654 printf (" %s\n", "-k, --critical=THRESHOLD");
655 printf (" %s\n", _("Critical threshold for jitter"));
656 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
657 printf (_(UT_VERBOSE));
659 printf("\n");
660 printf("%s\n", _("Notes:"));
661 printf(" %s\n", _("This plugin checks an NTP server independent of any commandline"));
662 printf(" %s\n\n", _("programs or external libraries."));
663 printf(" %s\n", _("Use this plugin to check the health of an NTP server. It supports"));
664 printf(" %s\n", _("checking the offset with the sync peer, the jitter and stratum. This"));
665 printf(" %s\n", _("plugin will not check the clock offset between the local host and NTP"));
666 printf(" %s\n\n", _("server; please use check_ntp_time for that purpose."));
668 printf(" %s\n", _("See:"));
669 printf(" %s\n", ("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
670 printf(" %s\n", _("for THRESHOLD format and examples."));
672 printf("\n");
673 printf("%s\n", _("Examples:"));
674 printf(" %s\n", _("Simple NTP server check:"));
675 printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1"));
676 printf(" %s\n", _("Check jitter too, avoiding critical notifications if jitter isn't available"));
677 printf(" %s\n", _("(See Notes above for more details on thresholds formats):"));
678 printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200"));
679 printf(" %s\n", _("Check only stratum:"));
680 printf(" %s\n", ("./check_ntp_peer -H ntpserv -W 4 -C 6"));
682 printf (_(UT_SUPPORT));
685 void
686 print_usage(void)
688 printf (_("Usage:"));
689 printf(" %s -H <host> [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname);
690 printf(" [-j <warn>] [-k <crit>] [-v verbose]\n");