[Nagiosplug-checkins] CVS: nagiosplug/plugins check_time.c,1.9,1.10

Ton Voon tonvoon at users.sourceforge.net
Wed Aug 20 03:35:07 CEST 2003


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv31432

Modified Files:
	check_time.c 
Log Message:
Optionally use udp instead of tcp (Bradley Baetz - 751646)


Index: check_time.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_time.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** check_time.c	10 Aug 2003 06:53:22 -0000	1.9
--- check_time.c	20 Aug 2003 09:54:12 -0000	1.10
***************
*** 44,47 ****
--- 44,48 ----
  int server_port = TIME_PORT;
  char *server_address = NULL;
+ int use_udp = FALSE;
  
  int process_arguments (int, char **);
***************
*** 66,70 ****
  
  	/* try to connect to the host at the given port number */
! 	if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) {
  		if (check_critical_time == TRUE)
  			result = STATE_CRITICAL;
--- 67,77 ----
  
  	/* try to connect to the host at the given port number */
! 	if (use_udp) {
! 		result = my_udp_connect (server_address, server_port, &sd);
! 	} else {
! 		result = my_tcp_connect (server_address, server_port, &sd);
! 	}
! 
! 	if (result != STATE_OK) {
  		if (check_critical_time == TRUE)
  			result = STATE_CRITICAL;
***************
*** 78,81 ****
--- 85,102 ----
  	}
  
+ 	if (use_udp) {
+ 		if (send (sd, "", 0, 0) < 0) {
+ 			if (check_critical_time == TRUE)
+ 				result = STATE_CRITICAL;
+ 			else if (check_warning_time == TRUE)
+ 				result = STATE_WARNING;
+ 			else
+ 				result = STATE_UNKNOWN;
+ 			die (result, 
+ 			  _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"),
+ 			  server_address, server_port);
+ 		}
+ 	}
+ 
  	/* watch for the connection string */
  	result = recv (sd, (void *)&raw_server_time, sizeof (raw_server_time), 0);
***************
*** 147,150 ****
--- 168,172 ----
  		{"critical-connect", required_argument, 0, 'C'},
  		{"port", required_argument, 0, 'p'},
+ 		{"udp", no_argument, 0, 'u'},
  		{"timeout", required_argument, 0, 't'},
  		{"version", no_argument, 0, 'V'},
***************
*** 170,174 ****
  
  	while (1) {
! 		c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", longopts,
  									 &option);
  
--- 192,196 ----
  
  	while (1) {
! 		c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:u", longopts,
  									 &option);
  
***************
*** 253,256 ****
--- 275,280 ----
  				socket_timeout = atoi (optarg);
  			break;
+ 		case 'u':									/* udp */
+ 			use_udp = TRUE;
  		}
  	}
***************
*** 297,300 ****
--- 321,326 ----
  
  	printf (_("\
+  -u, --udp\n\
+     Use UDP to connect, not TCP\n\
   -w, --warning-variance=INTEGER\n\
      Time difference (sec.) necessary to result in a warning status\n\
***************
*** 318,322 ****
  {
  	printf (_("\
! Usage: %s -H <host_address> [-p port] [-w variance] [-c variance]\n\
      [-W connect_time] [-C connect_time] [-t timeout]\n"), progname);
  	printf (_(UT_HLP_VRS), progname, progname);
--- 344,348 ----
  {
  	printf (_("\
! Usage: %s -H <host_address> [-p port] [-u] [-w variance] [-c variance]\n\
      [-W connect_time] [-C connect_time] [-t timeout]\n"), progname);
  	printf (_(UT_HLP_VRS), progname, progname);





More information about the Commits mailing list