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