[Nagiosplug-checkins] CVS: nagiosplug/plugins check_tcp.c,1.18,1.19 netutils.c,1.4,1.5 netutils.h,1.2,1.3

Jeremy T. Bouse undrgrid at users.sourceforge.net
Sun Mar 16 15:29:08 CET 2003


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

Modified Files:
	check_tcp.c netutils.c netutils.h 
Log Message:
Applied patch #660973 for tcp refusals


Index: check_tcp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_tcp.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** check_tcp.c	13 Mar 2003 21:14:26 -0000	1.18
--- check_tcp.c	16 Mar 2003 23:28:49 -0000	1.19
***************
*** 29,33 ****
  const char *option_summary = "\
  -H host -p port [-w warn_time] [-c crit_time] [-s send]\n\
! 	[-e expect] [-W wait] [-t to_sec] [-v]\n";
  
  const char *options = "\
--- 29,33 ----
  const char *option_summary = "\
  -H host -p port [-w warn_time] [-c crit_time] [-s send]\n\
! 	[-e expect] [-W wait] [-t to_sec] [-r refuse_state] [-v]\n";
  
  const char *options = "\
***************
*** 49,52 ****
--- 49,54 ----
   -t, --timeout=INTEGER\n\
      Seconds before connection times out (default: %d)\n\
+  -r, --refuse=ok|warn|crit\n\
+     Accept tcp refusals with states ok, warn, crit (default: crit)\n\
   -v\n\
      Show details for command-line debugging (do not use with nagios server)\n\
***************
*** 338,344 ****
  
  	printf
! 		("%s %s - %.3f second response time on port %d",
  		 SERVICE,
! 		 state_text (result), elapsed_time, server_port);
  
  	if (status && strlen(status) > 0)
--- 340,348 ----
  
  	printf
! 		("%s %s%s - %.3f second response time on port %d",
  		 SERVICE,
! 		 state_text (result),
! 		 (was_refused) ? " (refused)" : "",
! 		 elapsed_time, server_port);
  
  	if (status && strlen(status) > 0)
***************
*** 376,379 ****
--- 380,384 ----
  		{"quit", required_argument, 0, 'q'},
  		{"delay", required_argument, 0, 'd'},
+ 		{"refuse", required_argument, 0, 'r'},
  		{"verbose", no_argument, 0, 'v'},
  		{"version", no_argument, 0, 'V'},
***************
*** 403,407 ****
  
  	while (1) {
! 		c = getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:S", long_options,
  									 &option_index);
  
--- 408,412 ----
  
  	while (1) {
! 		c = getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:Sr:", long_options,
  									 &option_index);
  
***************
*** 472,475 ****
--- 477,490 ----
  			server_quit = optarg;
  			break;
+ 		case 'r':
+ 			if (!strncmp(optarg,"ok",2))
+ 				econn_refuse_state = STATE_OK;
+ 			else if (!strncmp(optarg,"warn",4))
+ 				econn_refuse_state = STATE_WARNING;
+ 			else if (!strncmp(optarg,"crit",4))
+ 				econn_refuse_state = STATE_CRITICAL;
+ 			else
+ 				usage ("Refuse mut be one of ok, warn, crit\n");
+ 			break;
  		case 'd':
  			if (is_intpos (optarg))
***************
*** 542,546 ****
  
    /* Make TCP connection */
!   if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK)
      {
      /* Do the SSL handshake */
--- 557,561 ----
  
    /* Make TCP connection */
!   if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK && was_refused == FALSE)
      {
      /* Do the SSL handshake */

Index: netutils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** netutils.c	15 Mar 2003 01:25:35 -0000	1.4
--- netutils.c	16 Mar 2003 23:28:49 -0000	1.5
***************
*** 33,36 ****
--- 33,38 ----
  
  int socket_timeout = DEFAULT_SOCKET_TIMEOUT; 
+ int econn_refuse_state = STATE_CRITICAL;
+ int was_refused = FALSE;
  
  /* handles socket timeouts */
***************
*** 276,281 ****
  			result = connect (*sd, res->ai_addr, res->ai_addrlen);
  
! 			if (result == 0)
  				break;
  
  			close (*sd);
--- 278,297 ----
  			result = connect (*sd, res->ai_addr, res->ai_addrlen);
  
! 			if (result == 0) {
! 				was_refused = FALSE;
  				break;
+ 			}
+ 
+ 			if (result < 0) {
+ 				switch (errno) {
+ 					case ECONNREFUSED:
+ 						switch (econn_refuse_state) {
+ 							case STATE_OK:
+ 							case STATE_WARNING:
+ 								was_refused = TRUE;
+ 						}
+ 						break;
+ 				}
+ 			}
  
  			close (*sd);
***************
*** 287,290 ****
--- 303,308 ----
  	if (result == 0)
  		return STATE_OK;
+ 	else if (was_refused)
+ 		return econn_refuse_state;
  	else {
  		printf ("%s\n", strerror(errno));

Index: netutils.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** netutils.h	15 Mar 2003 01:25:35 -0000	1.2
--- netutils.h	16 Mar 2003 23:28:49 -0000	1.3
***************
*** 61,62 ****
--- 61,64 ----
  
  extern int socket_timeout;
+ extern int econn_refuse_state;
+ extern int was_refused;





More information about the Commits mailing list