[Nagiosplug-checkins] CVS: nagiosplug/plugins check_swap.c,1.20,1.21

Ton Voon tonvoon at users.sourceforge.net
Tue Sep 30 06:55:05 CEST 2003


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

Modified Files:
	check_swap.c 
Log Message:
Fixed logic problem if HAVE_SWAP, but not on AIX or Solaris. Removed 
unnecessary ifdefs for help page. Better indentation for ifdefs


Index: check_swap.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_swap.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** check_swap.c	17 Sep 2003 09:31:56 -0000	1.20
--- check_swap.c	30 Sep 2003 13:54:26 -0000	1.21
***************
*** 100,120 ****
  #else
  # ifdef HAVE_SWAP
  	if (!allswaps) {
- #ifdef _AIX
  		asprintf(&swap_command, "%s", "/usr/sbin/lsps -s");
  		asprintf(&swap_format, "%s", "%d%*s %d");
  		conv_factor = 1;
! #else
! # ifdef sun
  		asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
  		asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
  		conv_factor = 2048;
- # endif
- #endif
- 	} else {
- 		asprintf(&swap_command, "%s", SWAP_COMMAND);
- 		asprintf(&swap_format, "%s", SWAP_FORMAT);
- 		conv_factor = SWAP_CONVERSION;
  	}
  
  	if (verbose >= 2)
--- 100,124 ----
  #else
  # ifdef HAVE_SWAP
+ 	asprintf(&swap_command, "%s", SWAP_COMMAND);
+ 	asprintf(&swap_format, "%s", SWAP_FORMAT);
+ 	conv_factor = SWAP_CONVERSION;
+ 
+ /* These override the command used if a summary (and thus ! allswaps) is required */
+ /* The summary flag returns more accurate information about swap usage on these OSes */
+ #  ifdef _AIX
  	if (!allswaps) {
  		asprintf(&swap_command, "%s", "/usr/sbin/lsps -s");
  		asprintf(&swap_format, "%s", "%d%*s %d");
  		conv_factor = 1;
! 	}
! #  else
! #   ifdef sun
! 	if (!allswaps) {
  		asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
  		asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
  		conv_factor = 2048;
  	}
+ #   endif
+ #  endif
  
  	if (verbose >= 2)
***************
*** 149,154 ****
  	}
  
  	if (!allswaps) {
- #ifdef _AIX
  		fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process);	/* Ignore first line */
  		sscanf (input_buffer, swap_format, &total_swap, &used_swap);
--- 153,159 ----
  	}
  
+ /* If different swap command is used for summary switch, need to read format differently */
+ #  ifdef _AIX
  	if (!allswaps) {
  		fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process);	/* Ignore first line */
  		sscanf (input_buffer, swap_format, &total_swap, &used_swap);
***************
*** 157,169 ****
  		if (verbose >= 3)
  			printf (_("total=%d, used=%d, free=%d\n"), total_swap, used_swap, free_swap);
! #else
! # ifdef sun
  		sscanf (input_buffer, swap_format, &used_swap, &free_swap);
  		used_swap = used_swap / 1024;
  		free_swap = free_swap / 1024;
  		total_swap = used_swap + free_swap;
- # endif
- #endif
  	} else {
  		while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
  			sscanf (input_buffer, swap_format, &dsktotal, &dskfree);
--- 162,176 ----
  		if (verbose >= 3)
  			printf (_("total=%d, used=%d, free=%d\n"), total_swap, used_swap, free_swap);
! 	} else {
! #  else
! #   ifdef sun
! 	if (!allswaps) {
  		sscanf (input_buffer, swap_format, &used_swap, &free_swap);
  		used_swap = used_swap / 1024;
  		free_swap = free_swap / 1024;
  		total_swap = used_swap + free_swap;
  	} else {
+ #   endif
+ #  endif
  		while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
  			sscanf (input_buffer, swap_format, &dsktotal, &dskfree);
***************
*** 171,179 ****
  			dsktotal = dsktotal / conv_factor;
  			/* AIX lists percent used, so this converts to dskfree in MBs */
! #ifdef _AIX
  			dskfree = dsktotal * (100 - dskfree) / 100;
! #else
  			dskfree = dskfree / conv_factor;
! #endif
  			if (verbose >= 3)
  				printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
--- 178,186 ----
  			dsktotal = dsktotal / conv_factor;
  			/* AIX lists percent used, so this converts to dskfree in MBs */
! #  ifdef _AIX
  			dskfree = dsktotal * (100 - dskfree) / 100;
! #  else
  			dskfree = dskfree / conv_factor;
! #  endif
  			if (verbose >= 3)
  				printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
***************
*** 190,194 ****
--- 197,208 ----
  			}
  		}
+ #  ifdef _AIX
+ 	}
+ #  else
+ #   ifdef sun
  	}
+ #   endif
+ #  endif
+ 
  	/* If we get anything on STDERR, at least set warning */
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
***************
*** 201,206 ****
  	if (spclose (child_process))
  		result = max_state (result, STATE_WARNING);
! # endif
! #endif
  
  	percent_used = 100 * ((double) used_swap) / ((double) total_swap);
--- 215,220 ----
  	if (spclose (child_process))
  		result = max_state (result, STATE_WARNING);
! # endif /* HAVE_SWAP */
! #endif /* HAVE_PROC_MEMINFO */
  
  	percent_used = 100 * ((double) used_swap) / ((double) total_swap);
***************
*** 388,401 ****
      Conduct comparisons for all swap partitions, one by one\n"));
  
- #ifdef sun
  	printf (_("\n\
  On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
  Will be discrepencies because swap -s counts allocated swap and includes\n\
  real memory\n"));
- #endif
- #ifdef _AIX
  	printf (_("\n\
  On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.\n"));
- #endif
  
  	printf (_(UT_SUPPORT));
--- 402,411 ----





More information about the Commits mailing list