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

Karl DeBisschop kdebisschop at users.sourceforge.net
Wed Nov 20 03:57:02 CET 2002


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

Modified Files:
	check_swap.c 
Log Message:
add switch to evaluate each swap individually

Index: check_swap.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_swap.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** check_swap.c	18 Nov 2002 11:24:00 -0000	1.5
--- check_swap.c	20 Nov 2002 11:56:11 -0000	1.6
***************
*** 1,13 ****
  /******************************************************************************
! *
! * CHECK_SWAP.C
! *
! * Program: Process plugin for Nagios
! * License: GPL
! * Copyright (c) 2000 Karl DeBisschop (kdebisschop at users.sourceforge.net)
! *
! * $Id$
! *
! ******************************************************************************/
  
  #include "common.h"
--- 1,28 ----
  /******************************************************************************
!  *
!  * Program: Swap space plugin for Nagios
!  * License: GPL
!  *
!  * License Information:
!  *
!  * This program is free software; you can redistribute it and/or modify
!  * it under the terms of the GNU General Public License as published by
!  * the Free Software Foundation; either version 2 of the License, or
!  * (at your option) any later version.
!  *
!  * This program is distributed in the hope that it will be useful,
!  * but WITHOUT ANY WARRANTY; without even the implied warranty of
!  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!  * GNU General Public License for more details.
!  *
!  * You should have received a copy of the GNU General Public License
!  * along with this program; if not, write to the Free Software
!  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!  *
!  * Copyright (c) 2000 Karl DeBisschop (kdebisschop at users.sourceforge.net)
!  *
!  * $Id$
!  *
!  *****************************************************************************/
  
  #include "common.h"
***************
*** 16,19 ****
--- 31,39 ----
  
  #define PROGNAME "check_swap"
+ #define REVISION "$Revision$"
+ #define COPYRIGHT "2000-2002"
+ #define AUTHOR "Karl DeBisschop"
+ #define EMAIL "kdebisschop at users.sourceforge.net"
+ #define SUMMARY "Check swap space on local server.\n"
  
  int process_arguments (int argc, char **argv);
***************
*** 22,26 ****
  void print_help (void);
  
! int warn_percent = 200, crit_percent = 200, warn_size = -1, crit_size = -1;
  
  int
--- 42,51 ----
  void print_help (void);
  
! int warn_percent = 200;
! int crit_percent = 200;
! int warn_size = -1;
! int crit_size = -1;
! int verbose;
! int allswaps;
  
  int
***************
*** 28,32 ****
  {
  	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];
--- 53,57 ----
  {
  	int total_swap = 0, used_swap = 0, free_swap = 0, percent_used;
! 	int total, used, free, percent;
  	int result = STATE_OK;
  	char input_buffer[MAX_INPUT_BUFFER];
***************
*** 49,63 ****
  		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);
--- 74,96 ----
  		if (sscanf (input_buffer, " %s %d %d %d", str, &total, &used, &free) == 4 &&
  		    strstr (str, "Swap")) {
  			total_swap += total;
  			used_swap += used;
  			free_swap += free;
+ 			if (allswaps) {
+ 				percent = 100 * (((float) used) / ((float) total));
+ 				if (percent >= crit_percent || free <= crit_size)
+ 					result = max_state (STATE_CRITICAL, result);
+ 				else if (percent >= warn_percent || free <= warn_size)
+ 					result = max_state (STATE_WARNING, result);
+ 				if (verbose)
+ 					asprintf (&status, "%s [%d/%d]", status, used, total);
+ 			}
  		}
  	}
  	percent_used = 100 * (((float) used_swap) / ((float) total_swap));
  	if (percent_used >= crit_percent || free_swap <= crit_size)
! 		result = max_state (STATE_CRITICAL, result);
  	else if (percent_used >= warn_percent || free_swap <= warn_size)
! 		result = max_state (STATE_WARNING, result);
  	asprintf (&status, "%s %2d%% (%d out of %d)", status, percent_used,
  	          used_swap, total_swap);
***************
*** 95,102 ****
  		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);
--- 128,143 ----
  		sscanf (input_buffer, SWAP_FORMAT, &total, &free);
  		used = total - free;
  		total_swap += total;
  		used_swap += used;
  		free_swap += free;
+ 		if (allswaps) {
+ 			percent = 100 * (((float) used) / ((float) total));
+ 			if (percent >= crit_percent || free <= crit_size)
+ 				result = max_state (STATE_CRITICAL, result);
+ 			else if (percent >= warn_percent || free <= warn_size)
+ 				result = max_state (STATE_WARNING, result);
+ 			if (verbose)
+ 				asprintf (&status, "%s [%d/%d]", status, used, total);
+ 		}
  	}
  	percent_used = 100 * ((float) used_swap) / ((float) total_swap);
***************
*** 104,114 ****
  						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 */
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! 		result = max (result, STATE_WARNING);
  
  	/* close stderr */
--- 145,155 ----
  						status, percent_used, used_swap, total_swap);
  	if (percent_used >= crit_percent || free_swap <= crit_size)
! 		result = max_state (STATE_CRITICAL, result);
  	else if (percent_used >= warn_percent || free_swap <= warn_size)
! 		result = max_state (STATE_WARNING, result);
  
  	/* If we get anything on STDERR, at least set warning */
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! 		result = max_state (result, STATE_WARNING);
  
  	/* close stderr */
***************
*** 117,121 ****
  	/* close the pipe */
  	if (spclose (child_process))
! 		result = max (result, STATE_WARNING);
  #endif
  #endif
--- 158,162 ----
  	/* close the pipe */
  	if (spclose (child_process))
! 		result = max_state (result, STATE_WARNING);
  #endif
  #endif
***************
*** 153,157 ****
  process_arguments (int argc, char **argv)
  {
! 	int c, i = 0;
  
  #ifdef HAVE_GETOPT_H
--- 194,200 ----
  process_arguments (int argc, char **argv)
  {
! 	int c = 0;  /* option character */
! 	int wc = 0; /* warning counter  */
! 	int cc = 0; /* critical counter */
  
  #ifdef HAVE_GETOPT_H
***************
*** 160,163 ****
--- 203,207 ----
  		{"warning", required_argument, 0, 'w'},
  		{"critical", required_argument, 0, 'c'},
+ 		{"all", no_argument, 0, 'a'},
  		{"verbose", no_argument, 0, 'v'},
  		{"version", no_argument, 0, 'V'},
***************
*** 172,178 ****
  	while (1) {
  #ifdef HAVE_GETOPT_H
! 		c = getopt_long (argc, argv, "+?Vhc:w:", long_options, &option_index);
  #else
! 		c = getopt (argc, argv, "+?Vhc:w:");
  #endif
  
--- 216,222 ----
  	while (1) {
  #ifdef HAVE_GETOPT_H
! 		c = getopt_long (argc, argv, "+?Vvhac:w:", long_options, &option_index);
  #else
! 		c = getopt (argc, argv, "+?Vvhac:w:");
  #endif
  
***************
*** 198,201 ****
--- 242,246 ----
  				usage ("Warning threshold must be integer or percentage!\n");
  			}
+ 			wc++;
  		case 'c':									/* critical time threshold */
  			if (is_intnonneg (optarg)) {
***************
*** 215,218 ****
--- 260,270 ----
  				usage ("Critical threshold must be integer or percentage!\n");
  			}
+ 			cc++;
+ 		case 'a':									/* verbose */
+ 			allswaps = TRUE;
+ 			break;
+ 		case 'v':									/* verbose */
+ 			verbose = TRUE;
+ 			break;
  		case 'V':									/* version */
  			print_revision (my_basename (argv[0]), "$Revision$");
***************
*** 280,286 ****
  {
  	printf
! 		("Usage: check_swap -w <used_percentage>%% -c <used_percentage>%%\n"
! 		 "       check_swap -w <bytes_free> -c <bytes_free>\n"
! 		 "       check_swap (-V|--version)\n" "       check_swap (-h|--help)\n");
  }
  
--- 332,341 ----
  {
  	printf
! 		("Usage:\n"
! 		 " %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n"
! 		 " %s [-a] -w <bytes_free> -c <bytes_free>\n"
! 		 " %s (-h | --help) for detailed help\n"
! 		 " %s (-V | --version) for version information\n",
! 		 PROGNAME, PROGNAME, PROGNAME, PROGNAME);
  }
  
***************
*** 292,300 ****
  print_help (void)
  {
! 	print_revision (PROGNAME, "$Revision$");
  	printf
! 		("Copyright (c) 2000 Karl DeBisschop\n\n"
! 		 "This plugin will check all of the swap partitions and return an\n"
! 		 "error if the the avalable swap space is less than specified.\n\n");
  	print_usage ();
  	printf
--- 347,353 ----
  print_help (void)
  {
! 	print_revision (PROGNAME, REVISION);
  	printf
! 		("Copyright (c) %s %s <%s>\n\n%s\n", COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
  	print_usage ();
  	printf
***************
*** 308,311 ****
--- 361,366 ----
  		 " -c, --critical=PERCENT%%\n"
  		 "   Exit with CRITCAL status if more than PERCENT of swap space has been used\n"
+ 		 " -a, --allswaps\n"
+ 		 "    Conduct comparisons for all swap partitions, one by one\n"
  		 " -h, --help\n"
  		 "    Print detailed help screen\n"





More information about the Commits mailing list