[Nagiosplug-checkins] CVS: nagiosplug/plugins check_swap.c,1.4,1.5

Karl DeBisschop kdebisschop at projects.sourceforge.net
Mon Nov 18 06:41:03 CET 2002


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

Modified Files:
	check_swap.c 
Log Message:
test total swap instead of individual disks

Index: check_swap.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_swap.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** check_swap.c	30 Oct 2002 18:45:05 -0000	1.4
--- check_swap.c	18 Nov 2002 11:24:00 -0000	1.5
***************
*** 27,31 ****
  main (int argc, char **argv)
  {
! 	int total_swap, used_swap, free_swap, percent_used;
  	int result = STATE_OK;
  	char input_buffer[MAX_INPUT_BUFFER];
--- 27,32 ----
  main (int argc, char **argv)
  {
! 	int total_swap = 0, used_swap = 0, free_swap = 0, percent_used;
! 	int total, used, free;
  	int result = STATE_OK;
  	char input_buffer[MAX_INPUT_BUFFER];
***************
*** 37,41 ****
  #endif
  	char str[32];
! 	char *status = NULL;
  
  	if (process_arguments (argc, argv) != OK)
--- 38,42 ----
  #endif
  	char str[32];
! 	char *status = "";
  
  	if (process_arguments (argc, argv) != OK)
***************
*** 46,62 ****
  	asprintf (&status, "%s", "Swap used:");
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
! 		sscanf (input_buffer, " %s %d %d %d", str, &total_swap, &used_swap,
! 						&free_swap);
! 		if (strstr (str, "Swap")) {
! 			percent_used = 100 * (((float) used_swap) / ((float) total_swap));
! 			asprintf (&status, "%s %2d%% (%d bytes out of %d)",
! 			          status, percent_used, used_swap, total_swap);
! 			if (percent_used >= crit_percent || free_swap <= crit_size)
! 				result = STATE_CRITICAL;
! 			else if (percent_used >= warn_percent || free_swap <= warn_size)
! 				result = STATE_WARNING;
! 			break;
  		}
  	}
  	fclose (fp);
  #else
--- 47,65 ----
  	asprintf (&status, "%s", "Swap used:");
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
! 		if (sscanf (input_buffer, " %s %d %d %d", str, &total, &used, &free) == 4 &&
! 		    strstr (str, "Swap")) {
! /* 			asprintf (&status, "%s [%d/%d]", status, used, total); */
! 			total_swap += total;
! 			used_swap += used;
! 			free_swap += free;
  		}
  	}
+ 	percent_used = 100 * (((float) used_swap) / ((float) total_swap));
+ 	if (percent_used >= crit_percent || free_swap <= crit_size)
+ 		result = STATE_CRITICAL;
+ 	else if (percent_used >= warn_percent || free_swap <= warn_size)
+ 		result = STATE_WARNING;
+ 	asprintf (&status, "%s %2d%% (%d out of %d)", status, percent_used,
+ 	          used_swap, total_swap);
  	fclose (fp);
  #else
***************
*** 90,103 ****
  	asprintf (&status, "%s", "Swap used:");
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
! 		sscanf (input_buffer, SWAP_FORMAT, &total_swap, &free_swap);
! 		used_swap = total_swap - free_swap;
! 		percent_used = 100 * ((float) used_swap) / ((float) total_swap);
! 		asprintf (&status, "%s %2d%% (%d bytes out of %d)",
! 		          status, percent_used, used_swap, total_swap);
! 		if (percent_used >= crit_percent || free_swap <= crit_size)
! 			result = STATE_CRITICAL;
! 		else if (percent_used >= warn_percent || free_swap <= warn_size)
! 			result = STATE_WARNING;
  	}
  
  	/* If we get anything on STDERR, at least set warning */
--- 93,110 ----
  	asprintf (&status, "%s", "Swap used:");
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
! 		sscanf (input_buffer, SWAP_FORMAT, &total, &free);
! 		used = total - free;
! /* 		asprintf (&status, "%s [%d/%d]", status, used, total); */
! 		total_swap += total;
! 		used_swap += used;
! 		free_swap += free;
  	}
+ 	percent_used = 100 * ((float) used_swap) / ((float) total_swap);
+ 	asprintf (&status, "%s %2d%% (%d out of %d)",
+ 						status, percent_used, used_swap, total_swap);
+ 	if (percent_used >= crit_percent || free_swap <= crit_size)
+ 		result = STATE_CRITICAL;
+ 	else if (percent_used >= warn_percent || free_swap <= warn_size)
+ 		result = STATE_WARNING;
  
  	/* If we get anything on STDERR, at least set warning */





More information about the Commits mailing list