summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2003-08-20 09:54:12 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2003-08-20 09:54:12 +0000
commit6dd9903fa2df3e387a157ee5f5846581e5f0468c (patch)
treebc9dbfd97693f0691eb39f05091ba3a84e9a931e /plugins
parent40451e93880327bbf34a4662637975a79b643d60 (diff)
downloadmonitoring-plugins-6dd9903fa2df3e387a157ee5f5846581e5f0468c.tar.gz
Optionally use udp instead of tcp (Bradley Baetz - 751646)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@687 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_time.c32
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;
43int check_critical_diff = FALSE; 43int check_critical_diff = FALSE;
44int server_port = TIME_PORT; 44int server_port = TIME_PORT;
45char *server_address = NULL; 45char *server_address = NULL;
46int use_udp = FALSE;
46 47
47int process_arguments (int, char **); 48int process_arguments (int, char **);
48void print_help (void); 49void 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
317print_usage (void) 343print_usage (void)
318{ 344{
319 printf (_("\ 345 printf (_("\
320Usage: %s -H <host_address> [-p port] [-w variance] [-c variance]\n\ 346Usage: %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}