1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
--- check_ntp.c.orig 2007-04-10 08:17:18.000000000 +0100
+++ check_ntp.c 2007-05-29 12:41:58.000000000 +0100
@@ -47,6 +47,7 @@
static char *server_address=NULL;
static int verbose=0;
+static int max_hosts=0;
static double owarn=60;
static double ocrit=120;
static short do_jitter=0;
@@ -372,7 +373,15 @@
}
/* count the number of returned hosts, and allocate stuff accordingly */
- for(ai_tmp=ai; ai_tmp!=NULL; ai_tmp=ai_tmp->ai_next){ num_hosts++; }
+ for(ai_tmp=ai; ai_tmp!=NULL; ai_tmp=ai_tmp->ai_next){
+ num_hosts++;
+ /* Reached max # hosts to compare ? */
+ if(max_hosts && num_hosts >= max_hosts && ai_tmp->ai_next) {
+printf("chopping at %d\n", num_hosts);
+ freeaddrinfo(ai_tmp->ai_next);
+ ai_tmp->ai_next = NULL;
+ }
+ }
req=(ntp_message*)malloc(sizeof(ntp_message)*num_hosts);
if(req==NULL) die(STATE_UNKNOWN, "can not allocate ntp message array");
socklist=(int*)malloc(sizeof(int)*num_hosts);
@@ -651,6 +660,7 @@
{"critical", required_argument, 0, 'c'},
{"jwarn", required_argument, 0, 'j'},
{"jcrit", required_argument, 0, 'k'},
+ {"maxhosts", required_argument, 0, 'm'},
{"timeout", required_argument, 0, 't'},
{"hostname", required_argument, 0, 'H'},
{0, 0, 0, 0}
@@ -661,7 +671,7 @@
usage ("\n");
while (1) {
- c = getopt_long (argc, argv, "Vhv46w:c:j:k:t:H:", longopts, &option);
+ c = getopt_long (argc, argv, "Vhv46w:c:j:k:t:H:m:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
@@ -677,6 +687,9 @@
case 'v':
verbose++;
break;
+ case 'm':
+ max_hosts = atoi(optarg);
+ break;
case 'w':
owarn = atof(optarg);
break;
@@ -848,6 +861,8 @@
printf (" %s\n", _("Warning value for jitter"));
printf (" %s\n", "-k, --critical=DOUBLE");
printf (" %s\n", _("Critical value for jitter"));
+ printf (" %s\n", "-m, --maxhosts=INTEGER");
+ printf (" %s\n", _("Max hosts to check - for where host expands to multiple addresses"));
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
printf (_(UT_VERBOSE));
printf (_(UT_SUPPORT));
@@ -857,5 +872,5 @@
print_usage(void)
{
printf (_("Usage:"));
- printf("%s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n", progname);
+ printf("%s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose] [-m <max hosts to check>]\n", progname);
}
|