[Nagiosplug-checkins] CVS: nagiosplug/plugins check_disk.c,1.2,1.3 check_procs.c,1.1.1.1,1.2 check_ping.c,1.3,1.4

Subhendu Ghosh sghosh at users.sourceforge.net
Tue Jun 18 20:10:03 CEST 2002


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv11608

Modified Files:
	check_disk.c check_procs.c check_ping.c 
Log Message:
fixes for using POSIX return codes

Index: check_disk.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_disk.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** check_disk.c	6 Jun 2002 04:15:49 -0000	1.2
--- check_disk.c	19 Jun 2002 03:09:10 -0000	1.3
***************
*** 63,66 ****
--- 63,67 ----
  	int free_disk = -1;
  	int result = STATE_UNKNOWN;
+ 	int temp_result = STATE_UNKNOWN;
  	char *command_line = NULL;
  	char input_buffer[MAX_INPUT_BUFFER] = "";
***************
*** 100,104 ****
  				 &total_disk, &used_disk, &free_disk, &usp, &mntp) == 6) {
  
! 			result = max (result, check_disk (usp, free_disk));
  			len =
  				snprintf (outbuf, MAX_INPUT_BUFFER - 1,
--- 101,134 ----
  				 &total_disk, &used_disk, &free_disk, &usp, &mntp) == 6) {
  
! 			/* cannot use max now that STATE_UNKNOWN is greater than STATE_CRITICAL
! 			result = max (result, check_disk (usp, free_disk)); */
! 			temp_result = check_disk (usp, free_disk) ;
! 
! 					
! 			if ( temp_result == STATE_CRITICAL ) {
! 				result = STATE_CRITICAL;
! 			}
! 			else if (temp_result == STATE_WARNING) {
! 				if ( !( result == STATE_CRITICAL) ) {
! 					result = STATE_WARNING;
! 				}
! 			}
! 			else if (temp_result == STATE_OK) {
! 				if ( ! ( result == STATE_CRITICAL || result == STATE_WARNING) ){
! 					result = STATE_OK;
! 				}
! 			}
! 			else if (temp_result == STATE_UNKNOWN) {
! 				if ( ! ( result == STATE_CRITICAL || result == STATE_WARNING || result == STATE_OK) ){
! 					result = STATE_UNKNOWN;
! 				}
! 			}
! 			else {
! 				/* don't have a match with the return value from check_disk() */
! 				result = STATE_UNKNOWN;
! 			}
! 				
! 
! 				
  			len =
  				snprintf (outbuf, MAX_INPUT_BUFFER - 1,
***************
*** 116,120 ****
  	/* If we get anything on stderr, at least set warning */
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! 		result = max (result, STATE_WARNING);
  
  	/* close stderr */
--- 146,153 ----
  	/* If we get anything on stderr, at least set warning */
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! 		/*result = max (result, STATE_WARNING); */
! 		if( !( result == STATE_CRITICAL) ) {
! 			result = STATE_WARNING;
! 		}
  
  	/* close stderr */
***************
*** 123,128 ****
  	/* close the pipe */
  	if (spclose (child_process))
! 		result = max (result, STATE_WARNING);
! 
  	if (usp < 0)
  		printf ("Disk \"%s\" not mounted or nonexistant\n", path);
--- 156,163 ----
  	/* close the pipe */
  	if (spclose (child_process))
! 		/*result = max (result, STATE_WARNING); */
! 		if( !( result == STATE_CRITICAL) ) {
! 			result = STATE_WARNING;
! 		}
  	if (usp < 0)
  		printf ("Disk \"%s\" not mounted or nonexistant\n", path);

Index: check_procs.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_procs.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_procs.c	28 Feb 2002 06:42:58 -0000	1.1.1.1
--- check_procs.c	19 Jun 2002 03:09:10 -0000	1.2
***************
*** 146,155 ****
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
  		if (verbose)
! 			printf ("%s", input_buffer);
! 		result = max (result, STATE_WARNING);
  	}
! 	if (result > STATE_OK)
  		printf ("System call sent warnings to stderr\n");
! 
  	(void) fclose (child_stderr);
  
--- 146,161 ----
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
  		if (verbose)
! 			printf ("STDERR: %s", input_buffer);
! 		/*Cannot use max() any more as STATE_UNKNOWN is gt STATE_CRITICAL 
! 		result = max (result, STATE_WARNING); */
! 		if ( !(result == STATE_CRITICAL) ) {
! 			result = STATE_WARNING;
! 		}
! 			printf ("System call sent warnings to stderr\n");
  	}
! 	
! /*	if (result == STATE_UNKNOWN || result == STATE_WARNING)
  		printf ("System call sent warnings to stderr\n");
! */
  	(void) fclose (child_stderr);
  
***************
*** 157,161 ****
  	if (spclose (child_process)) {
  		printf ("System call returned nonzero status\n");
! 		return max (result, STATE_WARNING);
  	}
  
--- 163,172 ----
  	if (spclose (child_process)) {
  		printf ("System call returned nonzero status\n");
! 		if ( !(result == STATE_CRITICAL) ) {
! 			return STATE_WARNING;
! 		}
! 		else {
! 			return result ;
! 		}
  	}
  
***************
*** 165,169 ****
  	if (found == 0) {							/* no process lines parsed so return STATE_UNKNOWN */
  		printf ("Unable to read output\n");
! 		return max (result, STATE_UNKNOWN);
  	}
  
--- 176,181 ----
  	if (found == 0) {							/* no process lines parsed so return STATE_UNKNOWN */
  		printf ("Unable to read output\n");
! 
! 		return result;
  	}
  
***************
*** 200,212 ****
  	else if (wmax >= 0 && procs > wmax) {
  		printf (format, "WARNING", procs);
! 		return max (result, STATE_WARNING);
  	}
  	else if (wmin >= 0 && procs < wmin) {
  		printf (format, "WARNING", procs);
! 		return max (result, STATE_WARNING);
  	}
  
  	printf (format, "OK", procs);
! 	return max (result, STATE_OK);
  }
  
--- 212,239 ----
  	else if (wmax >= 0 && procs > wmax) {
  		printf (format, "WARNING", procs);
! 		if ( !(result == STATE_CRITICAL) ) {
! 			return STATE_WARNING;
! 		}
! 		else {
! 			return result ;
! 		}
! 		/*return max (result, STATE_WARNING); */
  	}
  	else if (wmin >= 0 && procs < wmin) {
  		printf (format, "WARNING", procs);
! 		if ( !(result == STATE_CRITICAL) ) {
! 			return STATE_WARNING;
! 		}
! 		else {
! 			return result ;
! 		}
! 		/*return max (result, STATE_WARNING); */
  	}
  
  	printf (format, "OK", procs);
! 	if ( result == STATE_UNKNOWN ) {
! 		result = STATE_OK;
! 	}
! 	return result;
  }
  

Index: check_ping.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ping.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** check_ping.c	8 May 2002 15:35:37 -0000	1.3
--- check_ping.c	19 Jun 2002 03:09:10 -0000	1.4
***************
*** 122,127 ****
  		result = STATE_WARNING;
  	else if (pl < wpl && rta < wrta && pl >= 0 && rta >= 0)
! 		result = max (result, STATE_OK);
! 
  	if (display_html == TRUE)
  		printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, server_address);
--- 122,131 ----
  		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, server_address);
***************
*** 382,386 ****
  
  		if (strstr (input_buffer, "(DUP!)")) {
! 			result = max (result, STATE_WARNING);
  			warn_text = realloc (warn_text, strlen (WARN_DUPLICATES) + 1);
  			if (warn_text == NULL)
--- 386,395 ----
  
  		if (strstr (input_buffer, "(DUP!)")) {
! 			/* cannot use the max function since STATE_UNKNOWN is max
! 			result = max (result, STATE_WARNING); */
! 			if( !(result == STATE_CRITICAL) ){
! 				result = STATE_WARNING;
! 			}
! 			
  			warn_text = realloc (warn_text, strlen (WARN_DUPLICATES) + 1);
  			if (warn_text == NULL)
***************
*** 446,449 ****
--- 455,461 ----
  			terminate (STATE_CRITICAL, "PING CRITICAL - Host Unreachable (%s)",
  								 server_address);
+ 		else if (strstr (input_buffer, "unknown host" ) )
+ 			terminate (STATE_CRITICAL, "PING CRITICAL - Host not found (%s)",
+ 								server_address);
  
  		warn_text =
***************
*** 457,463 ****
  
  		if (strstr (input_buffer, "DUPLICATES FOUND"))
! 			result = max (result, STATE_WARNING);
  		else
! 			result = max (result, STATE_CRITICAL);
  	}
  	(void) fclose (child_stderr);
--- 469,481 ----
  
  		if (strstr (input_buffer, "DUPLICATES FOUND"))
! 			/* cannot use the max function since STATE_UNKNOWN is max
! 			result = max (result, STATE_WARNING); */
! 			if( !(result == STATE_CRITICAL) ){
! 				result = STATE_WARNING;
! 			}
  		else
! 			/* cannot use the max function since STATE_UNKNOWN is max
! 			result = max (result, STATE_CRITICAL); */
! 			result = STATE_CRITICAL ;
  	}
  	(void) fclose (child_stderr);
***************
*** 470,474 ****
  	return result;
  }
! 
  
  void
--- 488,492 ----
  	return result;
  }
! 
  
  void





More information about the Commits mailing list