aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2003-09-11 08:02:04 +0000
committerGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2003-09-11 08:02:04 +0000
commit4b94b86bb9ddc521e8c61d50f90093a4e7b9f246 (patch)
tree26772924b57dc929bf97980da6a4ccbfe986d140
parentfee4763db44ef71dff247d97d28ec4f670acbed0 (diff)
downloadmonitoring-plugins-4b94b86bb9ddc521e8c61d50f90093a4e7b9f246.tar.gz
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
-rw-r--r--configure.in15
-rw-r--r--plugins/check_swap.c43
2 files changed, 33 insertions, 25 deletions
diff --git a/configure.in b/configure.in
index 0fdd8f63..37baafa8 100644
--- a/configure.in
+++ b/configure.in
@@ -1248,17 +1248,12 @@ fi
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 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 fine on linux, broken on solaris
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)
if [cat /proc/meminfo > /dev/null 2>&1]
then
@@ -1266,8 +1261,12 @@ then
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])
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
ac_cv_have_swap=yes
ac_cv_swap_command="$PATH_TO_SWAP -l"
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 3bbea77b..3a799c32 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -59,14 +59,15 @@ main (int argc, char **argv)
long unsigned int dsktotal, dskused, dskfree;
int result = STATE_OK;
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 */
char *temp_buffer;
char *swap_command;
char *swap_format;
-#endif
-#ifdef HAVE_PROC_MEMINFO
- FILE *fp;
+# endif
#endif
char str[32];
char *status;
@@ -88,8 +89,20 @@ main (int argc, char **argv)
dsktotal = dsktotal / 1048576;
dskused = dskused / 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) {
asprintf(&swap_command, "%s", "/usr/sbin/swap -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)
printf (_("Command: %s\n"), swap_command);
if (verbose >= 3)
- printf ("_(Format: %s\n"), swap_format);
+ printf (_("Format: %s\n"), swap_format);
child_process = spopen (swap_command);
if (child_process == NULL) {
@@ -146,7 +159,6 @@ main (int argc, char **argv)
printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
dskused = dsktotal - dskfree;
-#endif
total_swap += dsktotal;
used_swap += dskused;
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 */
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
result = max_state (result, STATE_WARNING);
@@ -177,8 +180,14 @@ main (int argc, char **argv)
/* close the pipe */
if (spclose (child_process))
result = max_state (result, STATE_WARNING);
+# 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);
return STATE_UNKNOWN;
}