[Nagiosplug-devel] patches for HPUX for plugins 1.3.0 beta2

Joe Buehler jbuehler at hekimian.com
Thu Dec 19 06:13:04 CET 2002


I ran into two problems under HPUX 10/11 with the 1.3.0 beta2 plugins
just downloaded from the net:

1. The output of df is not all on one line if the /dev device name
is long.  My patch is quick and dirty and should be made a little more
robust.

2. The configure check for "swapinfo" is not correct -- "swapinfo -k"
returns a usage message that includes the word "disk" so configure thinks
that "swapinfo -k" is the way to go and it is not -- "swapinfo -d" is correct
for HPUX.  The patch just moves the "swapinfo -d" test before the "swapinfo -k"
test (though that's not obvious by looking at it!).

As far as df goes, it is not very portable -- output format varies between
systems.  The author of check_disk might look at the "di" utility on the net,
which is a portable df replacement.  The code could probably be integrated into
the plugin -- license allowing.

Another comment -- there is a

     /bin/sh 'some command'

invocation below.  I don't think this is portable.  The way to do it is
/bin/sh -c 'some command'.
-- 
Joe Buehler

--- plugins/check_disk.c	Mon Nov 18 02:23:15 2002
+++ plugins/check_disk.c	Wed Dec 18 16:29:54 2002
@@ -70,6 +70,7 @@
  	char mntp[MAX_INPUT_BUFFER] = "";
  	char outbuf[MAX_INPUT_BUFFER] = "";
  	char *output = "";
+	int start = 0;

  	if (process_arguments (argc, argv) != OK)
  		usage ("Could not parse arguments\n");
@@ -90,10 +91,18 @@
  		printf ("Could not open stderr for %s\n", command_line);
  	}

-	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
+	while (fgets (input_buffer+start, MAX_INPUT_BUFFER - 1 - start, child_process)) {

  		if (!index (input_buffer, '/'))
  			continue;
+
+		if (!index (input_buffer, ' ')) {
+			start = strlen(input_buffer);
+			while (start > 0 && input_buffer[start - 1] == '\n') {
+				--start;
+			}
+			continue;
+		}

  		if (sscanf
  				(input_buffer, "%s %d %d %d %d%% %s", file_system, &total_disk,
--- configure	Fri Nov 22 05:26:29 2002
+++ configure	Wed Dec 18 15:53:16 2002
@@ -6645,9 +6645,8 @@
  		echo "      using Solaris format"
  	fi
  	EXTRAS="$EXTRAS check_swap"
-elif swapinfo -k 2>&1 | egrep -i "Device" >/dev/null
+elif swapinfo -d 2>/dev/null | egrep -i "^TYPE +AVAIL +USED +FREE" >/dev/null
  then
-	echo "found swapinfo command"
  	cat >> confdefs.h <<\EOF
  #define HAVE_SWAP 1
  EOF
@@ -6655,7 +6654,7 @@
  	# Extract the first word of "swapinfo", so it can be a program name with args.
  set dummy swapinfo; ac_word=$2
  echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:6659: checking for $ac_word" >&5
+echo "configure:6713: checking for $ac_word" >&5
  if eval "test \"`echo '$''{'ac_cv_path_PATH_TO_SWAP'+set}'`\" = set"; then
    echo $ac_n "(cached) $ac_c" 1>&6
  else
@@ -6688,20 +6687,17 @@
  fi

  	cat >> confdefs.h <<EOF
-#define SWAP_COMMAND "$PATH_TO_SWAP -k"
+#define SWAP_COMMAND "/bin/sh '$PATH_TO_SWAP -d | /bin/tail -l +2'"
  EOF

-	if swapinfo -k 2>/dev/null | egrep -i "^Device +1K-blocks +Used +Avail" >/dev/null
-	then
-		cat >> confdefs.h <<EOF
+	cat >> confdefs.h <<EOF
  #define SWAP_FORMAT "%*s %d %*d %d"
  EOF

-		echo "      using FreeBSD format"
-	fi
-	EXTRAS="$EXTRAS check_swap"
-elif swapinfo -d 2>/dev/null | egrep -i "^TYPE +AVAIL +USED +FREE" >/dev/null
+	echo "        using HP-UX format HP-UX"
+elif swapinfo -k 2>&1 | egrep -i "Device" >/dev/null
  then
+	echo "found swapinfo command"
  	cat >> confdefs.h <<\EOF
  #define HAVE_SWAP 1
  EOF
@@ -6709,7 +6705,7 @@
  	# Extract the first word of "swapinfo", so it can be a program name with args.
  set dummy swapinfo; ac_word=$2
  echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:6713: checking for $ac_word" >&5
+echo "configure:6659: checking for $ac_word" >&5
  if eval "test \"`echo '$''{'ac_cv_path_PATH_TO_SWAP'+set}'`\" = set"; then
    echo $ac_n "(cached) $ac_c" 1>&6
  else
@@ -6742,14 +6738,18 @@
  fi

  	cat >> confdefs.h <<EOF
-#define SWAP_COMMAND "/bin/sh '$PATH_TO_SWAP -d | /bin/tail -l +2'"
+#define SWAP_COMMAND "$PATH_TO_SWAP -k"
  EOF

-	cat >> confdefs.h <<EOF
+	if swapinfo -k 2>/dev/null | egrep -i "^Device +1K-blocks +Used +Avail" >/dev/null
+	then
+		cat >> confdefs.h <<EOF
  #define SWAP_FORMAT "%*s %d %*d %d"
  EOF

-	echo "        using HP-UX format HP-UX"
+		echo "      using FreeBSD format"
+	fi
+	EXTRAS="$EXTRAS check_swap"
  fi

  # Extract the first word of "dig", so it can be a program name with args.





More information about the Devel mailing list