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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
*** nagios-plugins-1.4.6-orig/plugins/check_ntp.c 2007-01-28 16:46:40.000000000 -0500
--- nagios-plugins-1.4.6/plugins/check_ntp.c 2007-02-17 17:17:20.000000000 -0500
*************** static double ocrit=120;
*** 53,58 ****
--- 53,62 ----
static short do_jitter=0;
static double jwarn=5000;
static double jcrit=10000;
+ static short do_stratum=0;
+ static int swarn=4;
+ static int scrit=15;
+ static int max_stratum=0;
int process_arguments (int, char **);
void print_help (void);
*************** double offset_request(const char *host,
*** 447,452 ****
--- 451,459 ----
if(verbose) {
printf("offset %.10g\n", servers[i].offset[respnum]);
}
+ if (req[i].stratum > max_stratum) {
+ max_stratum = req[i].stratum;
+ }
servers[i].stratum=req[i].stratum;
servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp);
servers[i].rtdelay=NTP32asDOUBLE(req[i].rtdelay);
*************** int process_arguments(int argc, char **a
*** 631,636 ****
--- 638,645 ----
{"zero-offset", no_argument, 0, 'O'},
{"jwarn", required_argument, 0, 'j'},
{"jcrit", required_argument, 0, 'k'},
+ {"swarn", required_argument, 0, 's'},
+ {"scrit", required_argument, 0, 'S'},
{"timeout", required_argument, 0, 't'},
{"hostname", required_argument, 0, 'H'},
{0, 0, 0, 0}
*************** int process_arguments(int argc, char **a
*** 641,647 ****
usage ("\n");
while (1) {
! c = getopt_long (argc, argv, "Vhv46w:c:Oj:k:t:H:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
--- 650,656 ----
usage ("\n");
while (1) {
! c = getopt_long (argc, argv, "Vhv46w:c:Oj:k:t:H:s:S:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
*************** int process_arguments(int argc, char **a
*** 671,676 ****
--- 680,693 ----
do_jitter=1;
jcrit = atof(optarg);
break;
+ case 's':
+ do_stratum=1;
+ swarn = atoi(optarg);
+ break;
+ case 'S':
+ do_stratum=1;
+ scrit = atoi(optarg);
+ break;
case 'H':
if(is_host(optarg) == FALSE)
usage2(_("Invalid hostname/address"), optarg);
*************** int process_arguments(int argc, char **a
*** 703,712 ****
usage4(_("Critical offset should be larger than warning offset"));
}
! if (ocrit < owarn){
usage4(_("Critical jitter should be larger than warning jitter"));
}
if(server_address == NULL){
usage4(_("Hostname was not supplied"));
}
--- 720,733 ----
usage4(_("Critical offset should be larger than warning offset"));
}
! if (jcrit < jwarn){
usage4(_("Critical jitter should be larger than warning jitter"));
}
+ if (scrit < swarn){
+ usage4(_("Critical stratum should be larger than warning stratum"));
+ }
+
if(server_address == NULL){
usage4(_("Hostname was not supplied"));
}
*************** int main(int argc, char *argv[]){
*** 758,763 ****
--- 779,792 ----
}
result=max_state(result, jitter_result);
+ if(do_stratum){
+ if (max_stratum >= scrit){
+ result - max_state(result, STATE_CRITICAL);
+ } else if(max_stratum >= swarn) {
+ result = max_state(result, STATE_WARNING);
+ }
+ }
+
switch (result) {
case STATE_CRITICAL :
printf("NTP CRITICAL: ");
*************** int main(int argc, char *argv[]){
*** 778,784 ****
if(offset_result==STATE_WARNING){
printf("Unable to fully sample sync server. ");
}
! printf("Offset %.10g secs|offset=%.10g", offset, offset);
}
if (do_jitter) printf(" jitter=%f", jitter);
printf("\n");
--- 807,817 ----
if(offset_result==STATE_WARNING){
printf("Unable to fully sample sync server. ");
}
! printf("Offset %.10g secs", offset);
! if (do_stratum) {
! printf(", max Stratum %d", max_stratum);
! }
! printf("|offset=%.10g", offset);
}
if (do_jitter) printf(" jitter=%f", jitter);
printf("\n");
*************** void print_help(void){
*** 804,809 ****
--- 837,846 ----
printf (_(UT_HOST_PORT), 'p', "123");
printf (_(UT_WARN_CRIT));
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+ printf (" -j, --jwarn=DOUBLE\n Jitter level to result in warning status\n");
+ printf (" -k, --jcrit=DOUBLE\n Jitter level to result in critical status\n");
+ printf (" -s, --swarn=INTEGER\n Stratum clock level to result in warning status\n");
+ printf (" -S, --scrit=INTEGER\n Stratum clock level to result in critical status\n");
printf (_(UT_VERBOSE));
printf (_(UT_SUPPORT));
}
|