[Nagiosplug-checkins] CVS: nagiosplug/plugins check_ping.c,1.22,1.23

Karl DeBisschop kdebisschop at users.sourceforge.net
Mon Aug 18 04:10:06 CEST 2003


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

Modified Files:
	check_ping.c 
Log Message:
move error scans to a new separate routine and scan both stderr and stdio


Index: check_ping.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ping.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** check_ping.c	10 Aug 2003 06:53:22 -0000	1.22
--- check_ping.c	18 Aug 2003 11:05:17 -0000	1.23
***************
*** 38,42 ****
  int get_threshold (char *, float *, int *);
  int validate_arguments (void);
! int run_ping (char *, char *);
  void print_usage (void);
  void print_help (void);
--- 38,43 ----
  int get_threshold (char *, float *, int *);
  int validate_arguments (void);
! int run_ping (const char *cmd, const char *addr);
! int error_scan (char buf[MAX_INPUT_BUFFER], const char *addr);
  void print_usage (void);
  void print_help (void);
***************
*** 395,399 ****
  
  int
! run_ping (char *cmd, char *server_address)
  {
  	char buf[MAX_INPUT_BUFFER];
--- 396,400 ----
  
  int
! run_ping (const char *cmd, const char *addr)
  {
  	char buf[MAX_INPUT_BUFFER];
***************
*** 409,418 ****
  	while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
  
! 		if (strstr (buf, _("(DUP!)"))) {
! 			result = max_state (result, STATE_WARNING);
! 			warn_text = strdup (WARN_DUPLICATES);
! 			if (!warn_text)
! 				die (STATE_UNKNOWN, _("unable to realloc warn_text"));
! 		}
  
  		/* get the percent loss statistics */
--- 410,414 ----
  	while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
  
! 		result = max_state (result, error_scan (buf, addr));
  
  		/* get the percent loss statistics */
***************
*** 439,470 ****
  		rta = crta;
  
! 	/* check stderr */
! 	while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) {
! 		if (strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP"))
! 				continue;
! 
! 		if (strstr (buf, "Network is unreachable"))
! 			die (STATE_CRITICAL,
! 			           _("PING CRITICAL - Network unreachable (%s)"),
! 			           server_address);
! 		else if (strstr (buf, "Destination Host Unreachable"))
! 			die (STATE_CRITICAL,
! 			           _("PING CRITICAL - Host Unreachable (%s)"),
! 			           server_address);
! 		else if (strstr (buf, "unknown host" ))
! 			die (STATE_CRITICAL,
! 			           _("PING CRITICAL - Host not found (%s)"),
! 			           server_address);
  
- 		if (warn_text == NULL)
- 			warn_text = strdup (buf);
- 		else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1)
- 			die (STATE_UNKNOWN, _("unable to realloc warn_text"));
- 
- 		if (strstr (buf, "DUPLICATES FOUND"))
- 			result = max_state (result, STATE_WARNING);
- 		else
- 			result = STATE_CRITICAL ;
- 	}
  	(void) fclose (child_stderr);
  
--- 435,443 ----
  		rta = crta;
  
! 	/* check stderr, setting at least WARNING if there is output here */
! 	while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
! 		if (! strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP"))
! 			result = max_state (STATE_WARNING, error_scan (buf, addr));
  
  	(void) fclose (child_stderr);
  
***************
*** 478,481 ****
--- 451,480 ----
  
  	return result;
+ }
+ 
+ 
+ 
+ 
+ 
+ int
+ error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
+ {
+ 	if (strstr (buf, "Network is unreachable"))
+ 		die (STATE_CRITICAL, _("PING CRITICAL - Network unreachable (%s)"), addr);
+ 	else if (strstr (buf, "Destination Host Unreachable"))
+ 		die (STATE_CRITICAL, _("PING CRITICAL - Host Unreachable (%s)"), addr);
+ 	else if (strstr (buf, "unknown host" ))
+ 		die (STATE_CRITICAL, _("PING CRITICAL - Host not found (%s)"), addr);
+ 
+ 	if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) {
+ 		if (warn_text == NULL)
+ 			warn_text = strdup (_(WARN_DUPLICATES));
+ 		else if (! strstr (warn_text, _(WARN_DUPLICATES)) &&
+ 		         asprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1)
+ 			die (STATE_UNKNOWN, _("unable to realloc warn_text"));
+ 		return (STATE_WARNING);
+ 	}
+ 
+ 	return (STATE_OK);
  }
  





More information about the Commits mailing list