Jelajahi Sumber

last changes to configure broke check_swap on RHLinux. Restore /proc/meminfo check and make check_swap ifdefs safer

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@716 f882894a-f735-0410-b71e-b25c423dba1c
Karl DeBisschop 22 tahun lalu
induk
melakukan
4b94b86bb9
2 mengubah file dengan 33 tambahan dan 25 penghapusan
  1. 7 8
      configure.in
  2. 26 17
      plugins/check_swap.c

+ 7 - 8
configure.in

@@ -1248,17 +1248,12 @@ fi
 dnl SWAP info required is amount allocated/available and amount free
 dnl SWAP info required is amount allocated/available and amount free
 dnl The plugin works through all the swap devices and adds up the total swap
 dnl The plugin works through all the swap devices and adds up the total swap
 dnl available.
 dnl available.
+AC_PATH_PROG(PATH_TO_SWAP,swap)
+AC_PATH_PROG(PATH_TO_SWAPINFO,swapinfo)
 
 
 dnl dunno why this does not work below - use hack (kbd)
 dnl dunno why this does not work below - use hack (kbd)
 dnl fine on linux, broken on solaris
 dnl fine on linux, broken on solaris
 dnl if /bin/test -e "/proc/meminfo"
 dnl if /bin/test -e "/proc/meminfo"
-
-AC_PATH_PROG(PATH_TO_SWAP,swap)
-AC_PATH_PROG(PATH_TO_SWAPINFO,swapinfo)
-
-if ( test -n "$PATH_TO_SWAP" || test -n "$PATH_TO_SWAPINFO" )
-then
-
 AC_MSG_CHECKING(for how to check memory)
 AC_MSG_CHECKING(for how to check memory)
 if [cat /proc/meminfo > /dev/null 2>&1]
 if [cat /proc/meminfo > /dev/null 2>&1]
 then
 then
@@ -1266,8 +1261,12 @@ then
 	AC_DEFINE(HAVE_PROC_MEMINFO,1,[Define if we have /proc/meminfo])
 	AC_DEFINE(HAVE_PROC_MEMINFO,1,[Define if we have /proc/meminfo])
 	AC_DEFINE_UNQUOTED(PROC_MEMINFO,"/proc/meminfo",[path to /proc/meminfo if name changes])
 	AC_DEFINE_UNQUOTED(PROC_MEMINFO,"/proc/meminfo",[path to /proc/meminfo if name changes])
 	EXTRAS="$EXTRAS check_swap"
 	EXTRAS="$EXTRAS check_swap"
+fi
+
+if ( test -n "$PATH_TO_SWAP" || test -n "$PATH_TO_SWAPINFO" )
+then
 
 
-elif [$PATH_TO_SWAP -l 2>&1 >/dev/null]
+if [$PATH_TO_SWAP -l 2>&1 >/dev/null]
 then
 then
 	ac_cv_have_swap=yes
 	ac_cv_have_swap=yes
 	ac_cv_swap_command="$PATH_TO_SWAP -l"
 	ac_cv_swap_command="$PATH_TO_SWAP -l"

+ 26 - 17
plugins/check_swap.c

@@ -59,14 +59,15 @@ main (int argc, char **argv)
 	long unsigned int dsktotal, dskused, dskfree;
 	long unsigned int dsktotal, dskused, dskfree;
 	int result = STATE_OK;
 	int result = STATE_OK;
 	char input_buffer[MAX_INPUT_BUFFER];
 	char input_buffer[MAX_INPUT_BUFFER];
-#ifdef HAVE_SWAP
+#ifdef HAVE_PROC_MEMINFO
+	FILE *fp;
+#else
+# ifdef HAVE_SWAP
 	int conv_factor;		/* Convert to MBs */
 	int conv_factor;		/* Convert to MBs */
 	char *temp_buffer;
 	char *temp_buffer;
 	char *swap_command;
 	char *swap_command;
 	char *swap_format;
 	char *swap_format;
-#endif
-#ifdef HAVE_PROC_MEMINFO
-	FILE *fp;
+# endif
 #endif
 #endif
 	char str[32];
 	char str[32];
 	char *status;
 	char *status;
@@ -88,8 +89,20 @@ main (int argc, char **argv)
 			dsktotal = dsktotal / 1048576;
 			dsktotal = dsktotal / 1048576;
 			dskused = dskused / 1048576;
 			dskused = dskused / 1048576;
 			dskfree = dskfree / 1048576;
 			dskfree = dskfree / 1048576;
-#endif
-#ifdef HAVE_SWAP
+			total_swap += dsktotal;
+			used_swap += dskused;
+			free_swap += dskfree;
+			if (allswaps) {
+				percent = 100 * (((double) dskused) / ((double) dsktotal));
+				result = max_state (result, check_swap (percent, dskfree));
+				if (verbose)
+					asprintf (&status, "%s [%lu (%d%%)]", status, dskfree, 100 - percent);
+			}
+		}
+	}
+	fclose(fp);
+#else
+# ifdef HAVE_SWAP
 	if (!allswaps && sun) {
 	if (!allswaps && sun) {
 		asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
 		asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
 		asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
 		asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
@@ -103,7 +116,7 @@ main (int argc, char **argv)
 	if (verbose >= 2)
 	if (verbose >= 2)
 		printf (_("Command: %s\n"), swap_command);
 		printf (_("Command: %s\n"), swap_command);
 	if (verbose >= 3)
 	if (verbose >= 3)
-		printf ("_(Format: %s\n"), swap_format);
+		printf (_("Format: %s\n"), swap_format);
 
 
 	child_process = spopen (swap_command);
 	child_process = spopen (swap_command);
 	if (child_process == NULL) {
 	if (child_process == NULL) {
@@ -146,7 +159,6 @@ main (int argc, char **argv)
 				printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
 				printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
 
 
 			dskused = dsktotal - dskfree;
 			dskused = dsktotal - dskfree;
-#endif
 			total_swap += dsktotal;
 			total_swap += dsktotal;
 			used_swap += dskused;
 			used_swap += dskused;
 			free_swap += dskfree;
 			free_swap += dskfree;
@@ -158,15 +170,6 @@ main (int argc, char **argv)
 			}
 			}
 		}
 		}
 	}
 	}
-	percent_used = 100 * ((double) used_swap) / ((double) total_swap);
-	result = max_state (result, check_swap (percent_used, free_swap));
-	asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
-						(100 - percent_used), free_swap, total_swap, status);
-
-#ifdef HAVE_PROC_MEMINFO
-	fclose(fp);
-#endif
-#ifdef HAVE_SWAP
 	/* If we get anything on STDERR, at least set warning */
 	/* If we get anything on STDERR, at least set warning */
 	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
 	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
 		result = max_state (result, STATE_WARNING);
 		result = max_state (result, STATE_WARNING);
@@ -177,8 +180,14 @@ main (int argc, char **argv)
 	/* close the pipe */
 	/* close the pipe */
 	if (spclose (child_process))
 	if (spclose (child_process))
 		result = max_state (result, STATE_WARNING);
 		result = max_state (result, STATE_WARNING);
+# endif
 #endif
 #endif
 
 
+	percent_used = 100 * ((double) used_swap) / ((double) total_swap);
+	result = max_state (result, check_swap (percent_used, free_swap));
+	asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
+						(100 - percent_used), free_swap, total_swap, status);
+
 	die (result, "SWAP %s:%s\n", state_text (result), status);
 	die (result, "SWAP %s:%s\n", state_text (result), status);
 	return STATE_UNKNOWN;
 	return STATE_UNKNOWN;
 }
 }