diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_time.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/plugins/check_time.c b/plugins/check_time.c index 49e7c87d..e6c3c716 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c | |||
@@ -43,6 +43,7 @@ unsigned long critical_diff = 0; | |||
43 | int check_critical_diff = FALSE; | 43 | int check_critical_diff = FALSE; |
44 | int server_port = TIME_PORT; | 44 | int server_port = TIME_PORT; |
45 | char *server_address = NULL; | 45 | char *server_address = NULL; |
46 | int use_udp = FALSE; | ||
46 | 47 | ||
47 | int process_arguments (int, char **); | 48 | int process_arguments (int, char **); |
48 | void print_help (void); | 49 | void print_help (void); |
@@ -65,7 +66,13 @@ main (int argc, char **argv) | |||
65 | time (&start_time); | 66 | time (&start_time); |
66 | 67 | ||
67 | /* try to connect to the host at the given port number */ | 68 | /* try to connect to the host at the given port number */ |
68 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) { | 69 | if (use_udp) { |
70 | result = my_udp_connect (server_address, server_port, &sd); | ||
71 | } else { | ||
72 | result = my_tcp_connect (server_address, server_port, &sd); | ||
73 | } | ||
74 | |||
75 | if (result != STATE_OK) { | ||
69 | if (check_critical_time == TRUE) | 76 | if (check_critical_time == TRUE) |
70 | result = STATE_CRITICAL; | 77 | result = STATE_CRITICAL; |
71 | else if (check_warning_time == TRUE) | 78 | else if (check_warning_time == TRUE) |
@@ -77,6 +84,20 @@ main (int argc, char **argv) | |||
77 | server_address, server_port); | 84 | server_address, server_port); |
78 | } | 85 | } |
79 | 86 | ||
87 | if (use_udp) { | ||
88 | if (send (sd, "", 0, 0) < 0) { | ||
89 | if (check_critical_time == TRUE) | ||
90 | result = STATE_CRITICAL; | ||
91 | else if (check_warning_time == TRUE) | ||
92 | result = STATE_WARNING; | ||
93 | else | ||
94 | result = STATE_UNKNOWN; | ||
95 | die (result, | ||
96 | _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), | ||
97 | server_address, server_port); | ||
98 | } | ||
99 | } | ||
100 | |||
80 | /* watch for the connection string */ | 101 | /* watch for the connection string */ |
81 | result = recv (sd, (void *)&raw_server_time, sizeof (raw_server_time), 0); | 102 | result = recv (sd, (void *)&raw_server_time, sizeof (raw_server_time), 0); |
82 | 103 | ||
@@ -146,6 +167,7 @@ process_arguments (int argc, char **argv) | |||
146 | {"warning-connect", required_argument, 0, 'W'}, | 167 | {"warning-connect", required_argument, 0, 'W'}, |
147 | {"critical-connect", required_argument, 0, 'C'}, | 168 | {"critical-connect", required_argument, 0, 'C'}, |
148 | {"port", required_argument, 0, 'p'}, | 169 | {"port", required_argument, 0, 'p'}, |
170 | {"udp", no_argument, 0, 'u'}, | ||
149 | {"timeout", required_argument, 0, 't'}, | 171 | {"timeout", required_argument, 0, 't'}, |
150 | {"version", no_argument, 0, 'V'}, | 172 | {"version", no_argument, 0, 'V'}, |
151 | {"help", no_argument, 0, 'h'}, | 173 | {"help", no_argument, 0, 'h'}, |
@@ -169,7 +191,7 @@ process_arguments (int argc, char **argv) | |||
169 | } | 191 | } |
170 | 192 | ||
171 | while (1) { | 193 | while (1) { |
172 | c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", longopts, | 194 | c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:u", longopts, |
173 | &option); | 195 | &option); |
174 | 196 | ||
175 | if (c == -1 || c == EOF) | 197 | if (c == -1 || c == EOF) |
@@ -252,6 +274,8 @@ process_arguments (int argc, char **argv) | |||
252 | else | 274 | else |
253 | socket_timeout = atoi (optarg); | 275 | socket_timeout = atoi (optarg); |
254 | break; | 276 | break; |
277 | case 'u': /* udp */ | ||
278 | use_udp = TRUE; | ||
255 | } | 279 | } |
256 | } | 280 | } |
257 | 281 | ||
@@ -296,6 +320,8 @@ This plugin will check the time on the specified host.\n\n")); | |||
296 | printf (_(UT_HOST_PORT), 'p', myport); | 320 | printf (_(UT_HOST_PORT), 'p', myport); |
297 | 321 | ||
298 | printf (_("\ | 322 | printf (_("\ |
323 | -u, --udp\n\ | ||
324 | Use UDP to connect, not TCP\n\ | ||
299 | -w, --warning-variance=INTEGER\n\ | 325 | -w, --warning-variance=INTEGER\n\ |
300 | Time difference (sec.) necessary to result in a warning status\n\ | 326 | Time difference (sec.) necessary to result in a warning status\n\ |
301 | -c, --critical-variance=INTEGER\n\ | 327 | -c, --critical-variance=INTEGER\n\ |
@@ -317,7 +343,7 @@ void | |||
317 | print_usage (void) | 343 | print_usage (void) |
318 | { | 344 | { |
319 | printf (_("\ | 345 | printf (_("\ |
320 | Usage: %s -H <host_address> [-p port] [-w variance] [-c variance]\n\ | 346 | Usage: %s -H <host_address> [-p port] [-u] [-w variance] [-c variance]\n\ |
321 | [-W connect_time] [-C connect_time] [-t timeout]\n"), progname); | 347 | [-W connect_time] [-C connect_time] [-t timeout]\n"), progname); |
322 | printf (_(UT_HLP_VRS), progname, progname); | 348 | printf (_(UT_HLP_VRS), progname, progname); |
323 | } | 349 | } |