[Nagiosplug-checkins] CVS: nagiosplug/plugins check_ping.c,1.12,1.13

Karl DeBisschop kdebisschop at users.sourceforge.net
Sun Mar 2 19:50:29 CET 2003


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

Modified Files:
	check_ping.c 
Log Message:
accept comma-delimted list of hosts for checking if a multihomed host is alive


Index: check_ping.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ping.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** check_ping.c	2 Mar 2003 06:01:18 -0000	1.12
--- check_ping.c	3 Mar 2003 03:49:40 -0000	1.13
***************
*** 84,87 ****
--- 84,88 ----
  	char *command_line = NULL;
  	int result = STATE_UNKNOWN;
+ 	int this_result = STATE_UNKNOWN;
  	int i;
  
***************
*** 114,118 ****
  
  		/* run the command */
! 		run_ping (command_line, addresses[i]);
  
  		if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) {
--- 115,119 ----
  
  		/* run the command */
! 		this_result = run_ping (command_line, addresses[i]);
  
  		if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) {
***************
*** 123,144 ****
  
  		if (pl >= cpl || rta >= crta || rta < 0)
! 			result = STATE_CRITICAL;
  		else if (pl >= wpl || rta >= wrta)
! 			result = STATE_WARNING;
! 		else if (pl < wpl && rta < wrta && pl >= 0 && rta >= 0)
! 			/* cannot use the max function because STATE_UNKNOWN is now 3 gt STATE_OK			
! 				 result = max (result, STATE_OK);  */
! 			if( !( (result == STATE_WARNING) || (result == STATE_CRITICAL) )  ) {
! 				result = STATE_OK;	
! 			}
  	
  		if (display_html == TRUE)
  			printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]);
  		if (pl == 100)
! 			printf ("PING %s - %sPacket loss = %d%%", state_text (result), warn_text,
  							pl);
  		else
  			printf ("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms",
! 							state_text (result), warn_text, pl, rta);
  		if (display_html == TRUE)
  			printf ("</A>");
--- 124,144 ----
  
  		if (pl >= cpl || rta >= crta || rta < 0)
! 			this_result = STATE_CRITICAL;
  		else if (pl >= wpl || rta >= wrta)
! 			this_result = STATE_WARNING;
! 		else if (pl >= 0 && rta >= 0)
! 			this_result = max_state (STATE_OK, this_result);	
  	
+ 		if (n_addresses > 1 && this_result != STATE_UNKNOWN)
+ 			terminate (STATE_OK, "%s is alive\n", addresses[i]);
+ 
  		if (display_html == TRUE)
  			printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]);
  		if (pl == 100)
! 			printf ("PING %s - %sPacket loss = %d%%", state_text (this_result), warn_text,
  							pl);
  		else
  			printf ("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms",
! 							state_text (this_result), warn_text, pl, rta);
  		if (display_html == TRUE)
  			printf ("</A>");
***************
*** 147,150 ****
--- 147,153 ----
  		if (verbose)
  			printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl);
+ 
+ 		result = max_state (result, this_result);
+ 
  	}
  
***************
*** 158,161 ****
--- 161,165 ----
  {
  	int c = 1;
+ 	char *ptr;
  
  #ifdef HAVE_GETOPT_H
***************
*** 170,174 ****
  #endif
  
! #define OPTCHARS "Vvht:c:w:H:p:nL"
  
  	if (argc < 2)
--- 174,178 ----
  #endif
  
! #define OPTCHARS "VvhnLt:c:w:H:p:"
  
  	if (argc < 2)
***************
*** 207,220 ****
  			break;
  		case 'H':	/* hostname */
! 			if (is_host (optarg) == FALSE)
! 				usage2 ("Invalid host name/address", optarg);
! 			n_addresses++;
! 			if (n_addresses > max_addr) {
! 				max_addr *= 2;
! 				addresses = realloc (addresses, max_addr);
! 				if (addresses == NULL)
! 					terminate (STATE_UNKNOWN, "Could not realloc() addresses\n");
  			}
- 			addresses[n_addresses-1] = optarg;
  			break;
  		case 'p':	/* number of packets to send */
--- 211,231 ----
  			break;
  		case 'H':	/* hostname */
! 			ptr=optarg;
! 			while (1) {
! 				n_addresses++;
! 				if (n_addresses > max_addr) {
! 					max_addr *= 2;
! 					addresses = realloc (addresses, max_addr);
! 					if (addresses == NULL)
! 						terminate (STATE_UNKNOWN, "Could not realloc() addresses\n");
! 				}
! 				addresses[n_addresses-1] = ptr;
! 				if (ptr = index (ptr, ',')) {
! 					strcpy (ptr, "");
! 					ptr += sizeof(char);
! 				} else {
! 					break;
! 				}
  			}
  			break;
  		case 'p':	/* number of packets to send */
***************
*** 327,330 ****
--- 338,342 ----
  {
  	float max_seconds;
+ 	int i;
  
  	if (wrta == UNKNOWN_TRIP_TIME) {
***************
*** 359,362 ****
--- 371,379 ----
  	if (max_seconds > timeout_interval)
  		timeout_interval = (int)max_seconds;
+ 
+ 	for (i=0; i<n_addresses; i++) {
+ 		if (is_host(addresses[i]) == FALSE)
+ 			usage2 ("Invalid host name/address", addresses[i]);
+ 	}
  
  	return OK;





More information about the Commits mailing list