diff options
Diffstat (limited to 'plugins/check_time.c')
-rw-r--r-- | plugins/check_time.c | 520 |
1 files changed, 247 insertions, 273 deletions
diff --git a/plugins/check_time.c b/plugins/check_time.c index f50ea427..debf59f3 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c | |||
@@ -1,374 +1,348 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_time plugin | 3 | * Monitoring check_time plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_time plugin | 10 | * This file contains the check_time plugin |
11 | * | 11 | * |
12 | * This plugin will check the time difference with the specified host. | 12 | * This plugin will check the time difference with the specified host. |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * This program is free software: you can redistribute it and/or modify | 15 | * This program is free software: you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by | 16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation, either version 3 of the License, or | 17 | * the Free Software Foundation, either version 3 of the License, or |
18 | * (at your option) any later version. | 18 | * (at your option) any later version. |
19 | * | 19 | * |
20 | * This program is distributed in the hope that it will be useful, | 20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. | 23 | * GNU General Public License for more details. |
24 | * | 24 | * |
25 | * You should have received a copy of the GNU General Public License | 25 | * You should have received a copy of the GNU General Public License |
26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | * | 27 | * |
28 | * | 28 | * |
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | #include "states.h" | ||
31 | const char *progname = "check_time"; | 32 | const char *progname = "check_time"; |
32 | const char *copyright = "1999-2007"; | 33 | const char *copyright = "1999-2024"; |
33 | const char *email = "devel@monitoring-plugins.org"; | 34 | const char *email = "devel@monitoring-plugins.org"; |
34 | 35 | ||
35 | #include "common.h" | 36 | #include "common.h" |
36 | #include "netutils.h" | 37 | #include "netutils.h" |
37 | #include "utils.h" | 38 | #include "utils.h" |
39 | #include "check_time.d/config.h" | ||
40 | |||
41 | #define UNIX_EPOCH 2208988800UL | ||
42 | |||
43 | typedef struct { | ||
44 | int errorcode; | ||
45 | check_time_config config; | ||
46 | } check_time_config_wrapper; | ||
47 | static check_time_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | ||
48 | static void print_help(void); | ||
49 | void print_usage(void); | ||
38 | 50 | ||
39 | enum { | 51 | int main(int argc, char **argv) { |
40 | TIME_PORT = 37 | 52 | setlocale(LC_ALL, ""); |
41 | }; | 53 | bindtextdomain(PACKAGE, LOCALEDIR); |
42 | 54 | textdomain(PACKAGE); | |
43 | #define UNIX_EPOCH 2208988800UL | ||
44 | |||
45 | uint32_t raw_server_time; | ||
46 | unsigned long server_time, diff_time; | ||
47 | int warning_time = 0; | ||
48 | bool check_warning_time = false; | ||
49 | int critical_time = 0; | ||
50 | bool check_critical_time = false; | ||
51 | unsigned long warning_diff = 0; | ||
52 | bool check_warning_diff = false; | ||
53 | unsigned long critical_diff = 0; | ||
54 | bool check_critical_diff = false; | ||
55 | int server_port = TIME_PORT; | ||
56 | char *server_address = NULL; | ||
57 | bool use_udp = false; | ||
58 | |||
59 | int process_arguments (int, char **); | ||
60 | void print_help (void); | ||
61 | void print_usage (void); | ||
62 | |||
63 | int | ||
64 | main (int argc, char **argv) | ||
65 | { | ||
66 | int sd; | ||
67 | int result = STATE_UNKNOWN; | ||
68 | time_t conntime; | ||
69 | |||
70 | setlocale (LC_ALL, ""); | ||
71 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
72 | textdomain (PACKAGE); | ||
73 | 55 | ||
74 | /* Parse extra opts if any */ | 56 | /* Parse extra opts if any */ |
75 | argv=np_extra_opts (&argc, argv, progname); | 57 | argv = np_extra_opts(&argc, argv, progname); |
58 | |||
59 | check_time_config_wrapper tmp_config = process_arguments(argc, argv); | ||
60 | if (tmp_config.errorcode == ERROR) { | ||
61 | usage4(_("Could not parse arguments")); | ||
62 | } | ||
76 | 63 | ||
77 | if (process_arguments (argc, argv) == ERROR) | 64 | const check_time_config config = tmp_config.config; |
78 | usage4 (_("Could not parse arguments")); | ||
79 | 65 | ||
80 | /* initialize alarm signal handling */ | 66 | /* initialize alarm signal handling */ |
81 | signal (SIGALRM, socket_timeout_alarm_handler); | 67 | signal(SIGALRM, socket_timeout_alarm_handler); |
82 | 68 | ||
83 | /* set socket timeout */ | 69 | /* set socket timeout */ |
84 | alarm (socket_timeout); | 70 | alarm(socket_timeout); |
85 | time (&start_time); | 71 | time(&start_time); |
86 | 72 | ||
73 | int socket; | ||
74 | mp_state_enum result = STATE_UNKNOWN; | ||
87 | /* try to connect to the host at the given port number */ | 75 | /* try to connect to the host at the given port number */ |
88 | if (use_udp) { | 76 | if (config.use_udp) { |
89 | result = my_udp_connect (server_address, server_port, &sd); | 77 | result = my_udp_connect(config.server_address, config.server_port, &socket); |
90 | } else { | 78 | } else { |
91 | result = my_tcp_connect (server_address, server_port, &sd); | 79 | result = my_tcp_connect(config.server_address, config.server_port, &socket); |
92 | } | 80 | } |
93 | 81 | ||
94 | if (result != STATE_OK) { | 82 | if (result != STATE_OK) { |
95 | if (check_critical_time) | 83 | if (config.check_critical_time) { |
96 | result = STATE_CRITICAL; | 84 | result = STATE_CRITICAL; |
97 | else if (check_warning_time) | 85 | } else if (config.check_warning_time) { |
98 | result = STATE_WARNING; | 86 | result = STATE_WARNING; |
99 | else | 87 | } else { |
100 | result = STATE_UNKNOWN; | 88 | result = STATE_UNKNOWN; |
101 | die (result, | 89 | } |
102 | _("TIME UNKNOWN - could not connect to server %s, port %d\n"), | 90 | die(result, _("TIME UNKNOWN - could not connect to server %s, port %d\n"), config.server_address, config.server_port); |
103 | server_address, server_port); | ||
104 | } | 91 | } |
105 | 92 | ||
106 | if (use_udp) { | 93 | if (config.use_udp) { |
107 | if (send (sd, "", 0, 0) < 0) { | 94 | if (send(socket, "", 0, 0) < 0) { |
108 | if (check_critical_time) | 95 | if (config.check_critical_time) { |
109 | result = STATE_CRITICAL; | 96 | result = STATE_CRITICAL; |
110 | else if (check_warning_time) | 97 | } else if (config.check_warning_time) { |
111 | result = STATE_WARNING; | 98 | result = STATE_WARNING; |
112 | else | 99 | } else { |
113 | result = STATE_UNKNOWN; | 100 | result = STATE_UNKNOWN; |
114 | die (result, | 101 | } |
115 | _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), | 102 | die(result, _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), config.server_address, config.server_port); |
116 | server_address, server_port); | ||
117 | } | 103 | } |
118 | } | 104 | } |
119 | 105 | ||
120 | /* watch for the connection string */ | 106 | /* watch for the connection string */ |
121 | result = recv (sd, (void *)&raw_server_time, sizeof (raw_server_time), 0); | 107 | uint32_t raw_server_time; |
108 | result = recv(socket, (void *)&raw_server_time, sizeof(raw_server_time), 0); | ||
122 | 109 | ||
123 | /* close the connection */ | 110 | /* close the connection */ |
124 | close (sd); | 111 | close(socket); |
125 | 112 | ||
126 | /* reset the alarm */ | 113 | /* reset the alarm */ |
127 | time (&end_time); | 114 | time(&end_time); |
128 | alarm (0); | 115 | alarm(0); |
129 | 116 | ||
130 | /* return a WARNING status if we couldn't read any data */ | 117 | /* return a WARNING status if we couldn't read any data */ |
131 | if (result <= 0) { | 118 | if (result <= 0) { |
132 | if (check_critical_time) | 119 | if (config.check_critical_time) { |
133 | result = STATE_CRITICAL; | 120 | result = STATE_CRITICAL; |
134 | else if (check_warning_time) | 121 | } else if (config.check_warning_time) { |
135 | result = STATE_WARNING; | 122 | result = STATE_WARNING; |
136 | else | 123 | } else { |
137 | result = STATE_UNKNOWN; | 124 | result = STATE_UNKNOWN; |
138 | die (result, | 125 | } |
139 | _("TIME UNKNOWN - no data received from server %s, port %d\n"), | 126 | die(result, _("TIME UNKNOWN - no data received from server %s, port %d\n"), config.server_address, config.server_port); |
140 | server_address, server_port); | ||
141 | } | 127 | } |
142 | 128 | ||
143 | result = STATE_OK; | 129 | result = STATE_OK; |
144 | 130 | ||
145 | conntime = (end_time - start_time); | 131 | time_t conntime = (end_time - start_time); |
146 | if (check_critical_time&& conntime > critical_time) | 132 | if (config.check_critical_time && conntime > config.critical_time) { |
147 | result = STATE_CRITICAL; | 133 | result = STATE_CRITICAL; |
148 | else if (check_warning_time && conntime > warning_time) | 134 | } else if (config.check_warning_time && conntime > config.warning_time) { |
149 | result = STATE_WARNING; | 135 | result = STATE_WARNING; |
136 | } | ||
150 | 137 | ||
151 | if (result != STATE_OK) | 138 | if (result != STATE_OK) { |
152 | die (result, _("TIME %s - %d second response time|%s\n"), | 139 | die(result, _("TIME %s - %d second response time|%s\n"), state_text(result), (int)conntime, |
153 | state_text (result), (int)conntime, | 140 | perfdata("time", (long)conntime, "s", config.check_warning_time, (long)config.warning_time, config.check_critical_time, |
154 | perfdata ("time", (long)conntime, "s", | 141 | (long)config.critical_time, true, 0, false, 0)); |
155 | check_warning_time, (long)warning_time, | 142 | } |
156 | check_critical_time, (long)critical_time, | ||
157 | true, 0, false, 0)); | ||
158 | 143 | ||
159 | server_time = ntohl (raw_server_time) - UNIX_EPOCH; | 144 | unsigned long server_time; |
160 | if (server_time > (unsigned long)end_time) | 145 | unsigned long diff_time; |
146 | server_time = ntohl(raw_server_time) - UNIX_EPOCH; | ||
147 | if (server_time > (unsigned long)end_time) { | ||
161 | diff_time = server_time - (unsigned long)end_time; | 148 | diff_time = server_time - (unsigned long)end_time; |
162 | else | 149 | } else { |
163 | diff_time = (unsigned long)end_time - server_time; | 150 | diff_time = (unsigned long)end_time - server_time; |
151 | } | ||
164 | 152 | ||
165 | if (check_critical_diff&& diff_time > critical_diff) | 153 | if (config.check_critical_diff && diff_time > config.critical_diff) { |
166 | result = STATE_CRITICAL; | 154 | result = STATE_CRITICAL; |
167 | else if (check_warning_diff&& diff_time > warning_diff) | 155 | } else if (config.check_warning_diff && diff_time > config.warning_diff) { |
168 | result = STATE_WARNING; | 156 | result = STATE_WARNING; |
157 | } | ||
169 | 158 | ||
170 | printf (_("TIME %s - %lu second time difference|%s %s\n"), | 159 | printf(_("TIME %s - %lu second time difference|%s %s\n"), state_text(result), diff_time, |
171 | state_text (result), diff_time, | 160 | perfdata("time", (long)conntime, "s", config.check_warning_time, (long)config.warning_time, config.check_critical_time, |
172 | perfdata ("time", (long)conntime, "s", | 161 | (long)config.critical_time, true, 0, false, 0), |
173 | check_warning_time, (long)warning_time, | 162 | perfdata("offset", diff_time, "s", config.check_warning_diff, config.warning_diff, config.check_critical_diff, |
174 | check_critical_time, (long)critical_time, | 163 | config.critical_diff, true, 0, false, 0)); |
175 | true, 0, false, 0), | ||
176 | perfdata ("offset", diff_time, "s", | ||
177 | check_warning_diff, warning_diff, | ||
178 | check_critical_diff, critical_diff, | ||
179 | true, 0, false, 0)); | ||
180 | return result; | 164 | return result; |
181 | } | 165 | } |
182 | 166 | ||
183 | |||
184 | |||
185 | /* process command-line arguments */ | 167 | /* process command-line arguments */ |
186 | int | 168 | check_time_config_wrapper process_arguments(int argc, char **argv) { |
187 | process_arguments (int argc, char **argv) | 169 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, |
188 | { | 170 | {"warning-variance", required_argument, 0, 'w'}, |
189 | int c; | 171 | {"critical-variance", required_argument, 0, 'c'}, |
190 | 172 | {"warning-connect", required_argument, 0, 'W'}, | |
191 | int option = 0; | 173 | {"critical-connect", required_argument, 0, 'C'}, |
192 | static struct option longopts[] = { | 174 | {"port", required_argument, 0, 'p'}, |
193 | {"hostname", required_argument, 0, 'H'}, | 175 | {"udp", no_argument, 0, 'u'}, |
194 | {"warning-variance", required_argument, 0, 'w'}, | 176 | {"timeout", required_argument, 0, 't'}, |
195 | {"critical-variance", required_argument, 0, 'c'}, | 177 | {"version", no_argument, 0, 'V'}, |
196 | {"warning-connect", required_argument, 0, 'W'}, | 178 | {"help", no_argument, 0, 'h'}, |
197 | {"critical-connect", required_argument, 0, 'C'}, | 179 | {0, 0, 0, 0}}; |
198 | {"port", required_argument, 0, 'p'}, | 180 | |
199 | {"udp", no_argument, 0, 'u'}, | 181 | if (argc < 2) { |
200 | {"timeout", required_argument, 0, 't'}, | 182 | usage("\n"); |
201 | {"version", no_argument, 0, 'V'}, | 183 | } |
202 | {"help", no_argument, 0, 'h'}, | ||
203 | {0, 0, 0, 0} | ||
204 | }; | ||
205 | 184 | ||
206 | if (argc < 2) | 185 | for (int i = 1; i < argc; i++) { |
207 | usage ("\n"); | 186 | if (strcmp("-to", argv[i]) == 0) { |
208 | 187 | strcpy(argv[i], "-t"); | |
209 | for (c = 1; c < argc; c++) { | 188 | } else if (strcmp("-wd", argv[i]) == 0) { |
210 | if (strcmp ("-to", argv[c]) == 0) | 189 | strcpy(argv[i], "-w"); |
211 | strcpy (argv[c], "-t"); | 190 | } else if (strcmp("-cd", argv[i]) == 0) { |
212 | else if (strcmp ("-wd", argv[c]) == 0) | 191 | strcpy(argv[i], "-c"); |
213 | strcpy (argv[c], "-w"); | 192 | } else if (strcmp("-wt", argv[i]) == 0) { |
214 | else if (strcmp ("-cd", argv[c]) == 0) | 193 | strcpy(argv[i], "-W"); |
215 | strcpy (argv[c], "-c"); | 194 | } else if (strcmp("-ct", argv[i]) == 0) { |
216 | else if (strcmp ("-wt", argv[c]) == 0) | 195 | strcpy(argv[i], "-C"); |
217 | strcpy (argv[c], "-W"); | 196 | } |
218 | else if (strcmp ("-ct", argv[c]) == 0) | ||
219 | strcpy (argv[c], "-C"); | ||
220 | } | 197 | } |
221 | 198 | ||
199 | check_time_config_wrapper result = { | ||
200 | .errorcode = OK, | ||
201 | .config = check_time_config_init(), | ||
202 | }; | ||
203 | |||
204 | int option_char; | ||
222 | while (true) { | 205 | while (true) { |
223 | c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:u", longopts, | 206 | int option = 0; |
224 | &option); | 207 | option_char = getopt_long(argc, argv, "hVH:w:c:W:C:p:t:u", longopts, &option); |
225 | 208 | ||
226 | if (c == -1 || c == EOF) | 209 | if (option_char == -1 || option_char == EOF) { |
227 | break; | 210 | break; |
211 | } | ||
228 | 212 | ||
229 | switch (c) { | 213 | switch (option_char) { |
230 | case '?': /* print short usage statement if args not parsable */ | 214 | case '?': /* print short usage statement if args not parsable */ |
231 | usage5 (); | 215 | usage5(); |
232 | case 'h': /* help */ | 216 | case 'h': /* help */ |
233 | print_help (); | 217 | print_help(); |
234 | exit (STATE_UNKNOWN); | 218 | exit(STATE_UNKNOWN); |
235 | case 'V': /* version */ | 219 | case 'V': /* version */ |
236 | print_revision (progname, NP_VERSION); | 220 | print_revision(progname, NP_VERSION); |
237 | exit (STATE_UNKNOWN); | 221 | exit(STATE_UNKNOWN); |
238 | case 'H': /* hostname */ | 222 | case 'H': /* hostname */ |
239 | if (!is_host (optarg)) | 223 | if (!is_host(optarg)) { |
240 | usage2 (_("Invalid hostname/address"), optarg); | 224 | usage2(_("Invalid hostname/address"), optarg); |
241 | server_address = optarg; | ||
242 | break; | ||
243 | case 'w': /* warning-variance */ | ||
244 | if (is_intnonneg (optarg)) { | ||
245 | warning_diff = strtoul (optarg, NULL, 10); | ||
246 | check_warning_diff = true; | ||
247 | } | 225 | } |
248 | else if (strspn (optarg, "0123456789:,") > 0) { | 226 | result.config.server_address = optarg; |
249 | if (sscanf (optarg, "%lu%*[:,]%d", &warning_diff, &warning_time) == 2) { | 227 | break; |
250 | check_warning_diff = true; | 228 | case 'w': /* warning-variance */ |
251 | check_warning_time = true; | 229 | if (is_intnonneg(optarg)) { |
252 | } | 230 | result.config.warning_diff = strtoul(optarg, NULL, 10); |
253 | else { | 231 | result.config.check_warning_diff = true; |
254 | usage4 (_("Warning thresholds must be a positive integer")); | 232 | } else if (strspn(optarg, "0123456789:,") > 0) { |
233 | if (sscanf(optarg, "%lu%*[:,]%d", &result.config.warning_diff, &result.config.warning_time) == 2) { | ||
234 | result.config.check_warning_diff = true; | ||
235 | result.config.check_warning_time = true; | ||
236 | } else { | ||
237 | usage4(_("Warning thresholds must be a positive integer")); | ||
255 | } | 238 | } |
256 | } | 239 | } else { |
257 | else { | 240 | usage4(_("Warning threshold must be a positive integer")); |
258 | usage4 (_("Warning threshold must be a positive integer")); | ||
259 | } | 241 | } |
260 | break; | 242 | break; |
261 | case 'c': /* critical-variance */ | 243 | case 'c': /* critical-variance */ |
262 | if (is_intnonneg (optarg)) { | 244 | if (is_intnonneg(optarg)) { |
263 | critical_diff = strtoul (optarg, NULL, 10); | 245 | result.config.critical_diff = strtoul(optarg, NULL, 10); |
264 | check_critical_diff = true; | 246 | result.config.check_critical_diff = true; |
265 | } | 247 | } else if (strspn(optarg, "0123456789:,") > 0) { |
266 | else if (strspn (optarg, "0123456789:,") > 0) { | 248 | if (sscanf(optarg, "%lu%*[:,]%d", &result.config.critical_diff, &result.config.critical_time) == 2) { |
267 | if (sscanf (optarg, "%lu%*[:,]%d", &critical_diff, &critical_time) == | 249 | result.config.check_critical_diff = true; |
268 | 2) { | 250 | result.config.check_critical_time = true; |
269 | check_critical_diff = true; | 251 | } else { |
270 | check_critical_time = true; | 252 | usage4(_("Critical thresholds must be a positive integer")); |
271 | } | ||
272 | else { | ||
273 | usage4 (_("Critical thresholds must be a positive integer")); | ||
274 | } | 253 | } |
275 | } | 254 | } else { |
276 | else { | 255 | usage4(_("Critical threshold must be a positive integer")); |
277 | usage4 (_("Critical threshold must be a positive integer")); | ||
278 | } | 256 | } |
279 | break; | 257 | break; |
280 | case 'W': /* warning-connect */ | 258 | case 'W': /* warning-connect */ |
281 | if (!is_intnonneg (optarg)) | 259 | if (!is_intnonneg(optarg)) { |
282 | usage4 (_("Warning threshold must be a positive integer")); | 260 | usage4(_("Warning threshold must be a positive integer")); |
283 | else | 261 | } else { |
284 | warning_time = atoi (optarg); | 262 | result.config.warning_time = atoi(optarg); |
285 | check_warning_time = true; | 263 | } |
264 | result.config.check_warning_time = true; | ||
286 | break; | 265 | break; |
287 | case 'C': /* critical-connect */ | 266 | case 'C': /* critical-connect */ |
288 | if (!is_intnonneg (optarg)) | 267 | if (!is_intnonneg(optarg)) { |
289 | usage4 (_("Critical threshold must be a positive integer")); | 268 | usage4(_("Critical threshold must be a positive integer")); |
290 | else | 269 | } else { |
291 | critical_time = atoi (optarg); | 270 | result.config.critical_time = atoi(optarg); |
292 | check_critical_time = true; | 271 | } |
272 | result.config.check_critical_time = true; | ||
293 | break; | 273 | break; |
294 | case 'p': /* port */ | 274 | case 'p': /* port */ |
295 | if (!is_intnonneg (optarg)) | 275 | if (!is_intnonneg(optarg)) { |
296 | usage4 (_("Port must be a positive integer")); | 276 | usage4(_("Port must be a positive integer")); |
297 | else | 277 | } else { |
298 | server_port = atoi (optarg); | 278 | result.config.server_port = atoi(optarg); |
279 | } | ||
299 | break; | 280 | break; |
300 | case 't': /* timeout */ | 281 | case 't': /* timeout */ |
301 | if (!is_intnonneg (optarg)) | 282 | if (!is_intnonneg(optarg)) { |
302 | usage2 (_("Timeout interval must be a positive integer"), optarg); | 283 | usage2(_("Timeout interval must be a positive integer"), optarg); |
303 | else | 284 | } else { |
304 | socket_timeout = atoi (optarg); | 285 | socket_timeout = atoi(optarg); |
286 | } | ||
305 | break; | 287 | break; |
306 | case 'u': /* udp */ | 288 | case 'u': /* udp */ |
307 | use_udp = true; | 289 | result.config.use_udp = true; |
308 | } | 290 | } |
309 | } | 291 | } |
310 | 292 | ||
311 | c = optind; | 293 | option_char = optind; |
312 | if (server_address == NULL) { | 294 | if (result.config.server_address == NULL) { |
313 | if (argc > c) { | 295 | if (argc > option_char) { |
314 | if (!is_host (argv[c])) | 296 | if (!is_host(argv[option_char])) { |
315 | usage2 (_("Invalid hostname/address"), optarg); | 297 | usage2(_("Invalid hostname/address"), optarg); |
316 | server_address = argv[c]; | 298 | } |
317 | } | 299 | result.config.server_address = argv[option_char]; |
318 | else { | 300 | } else { |
319 | usage4 (_("Hostname was not supplied")); | 301 | usage4(_("Hostname was not supplied")); |
320 | } | 302 | } |
321 | } | 303 | } |
322 | 304 | ||
323 | return OK; | 305 | return result; |
324 | } | 306 | } |
325 | 307 | ||
326 | 308 | void print_help(void) { | |
327 | |||
328 | void | ||
329 | print_help (void) | ||
330 | { | ||
331 | char *myport; | 309 | char *myport; |
332 | xasprintf (&myport, "%d", TIME_PORT); | 310 | xasprintf(&myport, "%d", TIME_PORT); |
333 | 311 | ||
334 | print_revision (progname, NP_VERSION); | 312 | print_revision(progname, NP_VERSION); |
335 | 313 | ||
336 | printf ("Copyright (c) 1999 Ethan Galstad\n"); | 314 | printf("Copyright (c) 1999 Ethan Galstad\n"); |
337 | printf (COPYRIGHT, copyright, email); | 315 | printf(COPYRIGHT, copyright, email); |
338 | 316 | ||
339 | printf ("%s\n", _("This plugin will check the time on the specified host.")); | 317 | printf("%s\n", _("This plugin will check the time on the specified host.")); |
340 | 318 | ||
341 | printf ("\n\n"); | 319 | printf("\n\n"); |
342 | 320 | ||
343 | print_usage (); | 321 | print_usage(); |
344 | 322 | ||
345 | printf (UT_HELP_VRSN); | 323 | printf(UT_HELP_VRSN); |
346 | printf (UT_EXTRA_OPTS); | 324 | printf(UT_EXTRA_OPTS); |
347 | 325 | ||
348 | printf (UT_HOST_PORT, 'p', myport); | 326 | printf(UT_HOST_PORT, 'p', myport); |
349 | 327 | ||
350 | printf (" %s\n", "-u, --udp"); | 328 | printf(" %s\n", "-u, --udp"); |
351 | printf (" %s\n", _("Use UDP to connect, not TCP")); | 329 | printf(" %s\n", _("Use UDP to connect, not TCP")); |
352 | printf (" %s\n", "-w, --warning-variance=INTEGER"); | 330 | printf(" %s\n", "-w, --warning-variance=INTEGER"); |
353 | printf (" %s\n", _("Time difference (sec.) necessary to result in a warning status")); | 331 | printf(" %s\n", _("Time difference (sec.) necessary to result in a warning status")); |
354 | printf (" %s\n", "-c, --critical-variance=INTEGER"); | 332 | printf(" %s\n", "-c, --critical-variance=INTEGER"); |
355 | printf (" %s\n", _("Time difference (sec.) necessary to result in a critical status")); | 333 | printf(" %s\n", _("Time difference (sec.) necessary to result in a critical status")); |
356 | printf (" %s\n", "-W, --warning-connect=INTEGER"); | 334 | printf(" %s\n", "-W, --warning-connect=INTEGER"); |
357 | printf (" %s\n", _("Response time (sec.) necessary to result in warning status")); | 335 | printf(" %s\n", _("Response time (sec.) necessary to result in warning status")); |
358 | printf (" %s\n", "-C, --critical-connect=INTEGER"); | 336 | printf(" %s\n", "-C, --critical-connect=INTEGER"); |
359 | printf (" %s\n", _("Response time (sec.) necessary to result in critical status")); | 337 | printf(" %s\n", _("Response time (sec.) necessary to result in critical status")); |
360 | 338 | ||
361 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 339 | printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
362 | 340 | ||
363 | printf (UT_SUPPORT); | 341 | printf(UT_SUPPORT); |
364 | } | 342 | } |
365 | 343 | ||
366 | 344 | void print_usage(void) { | |
367 | 345 | printf("%s\n", _("Usage:")); | |
368 | void | 346 | printf("%s -H <host_address> [-p port] [-u] [-w variance] [-c variance]\n", progname); |
369 | print_usage (void) | 347 | printf(" [-W connect_time] [-C connect_time] [-t timeout]\n"); |
370 | { | ||
371 | printf ("%s\n", _("Usage:")); | ||
372 | printf ("%s -H <host_address> [-p port] [-u] [-w variance] [-c variance]\n",progname); | ||
373 | printf (" [-W connect_time] [-C connect_time] [-t timeout]\n"); | ||
374 | } | 348 | } |