diff -ruN nagiosplug-save/contrib/check_mem.pl nagiosplug/contrib/check_mem.pl
--- nagiosplug-save/contrib/check_mem.pl	2002-02-28 06:42:54.000000000 +0000
+++ nagiosplug/contrib/check_mem.pl	2004-03-27 22:27:32.000000000 +0000
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -wT
 # $Id: check_mem.pl,v 1.1.1.1 2002/02/28 06:42:54 egalstad Exp $
 
 # check_mem.pl Copyright (C) 2000 Dan Larsson <dl@tyfon.net>
@@ -19,128 +19,88 @@
 # Boston, MA 02111-1307, USA
 
 # Tell Perl what we need to use
+require 5.004;
 use strict;
-use Getopt::Std;
+use lib utils.pm;
+use Plugin;
+use Plugin::Parameter qw(:DEFAULT :thresholds);
+
+use vars qw($opt_c $opt_f $opt_u $opt_w $opt_t $PROGNAME);
+
+use utils qw(%ERRORS &usage);
+
+$w_opt->description("Percent free/used when to warn");
+$c_opt->description("Percent free/used when critical");
+my $f_opt = new Plugin::Parameter(-name => "freecheck", -flags => [ 'f', 'free' ],
+				  -optional => "yes", -valueoptional => "yes", -type => "NONE",
+				  -description => "Check FREE memory");
+my $u_opt = new Plugin::Parameter(-name => "usedcheck", -flags => [ 'u', 'used' ],
+				  -optional => "yes", -valueoptional => "yes", -type => "NONE",
+				  -description => "Check USED memory");
+my $plugin = new Plugin(-revision => '$Revision: 1.1.1.1 $',
+			-copyright => "2000 Dan Larsson <dl\@tyfon.net>, 2004 Howard Wilkinson <howard\@cohtech.com>",
+			-shortcomment => "Check the usage of memory on the local machine",
+			-checker => sub { my ($plugin) = @_;
+					  if (!$opt_f and !$opt_u) {
+					    $plugin->usage();
+					    usage("$PROGNAME UNKNOWN: Select either Free or Used memory to monitor\n");
+					  }
+					  if ($opt_f and $opt_w <= $opt_c) {
+					    $plugin->usage();
+					    usage("$PROGNAME UNKNOWN: Warning level must be greater than Critical for Free memory check\n");
+					  }
+					  if ($opt_u and $opt_w >= $opt_c) {
+					    $plugin->usage();
+					    usage("$PROGNAME UNKNOWN: Warning level must be less than Critical for Used memory check\n");
+					  }
+					},
+			-parameterlists => [ [ $f_opt, $u_opt, $w_opt, $c_opt, $t_opt ], $h_opts, $V_opts ]);
 
-use vars qw($opt_c $opt_f $opt_u $opt_w
-	    $free_memory $used_memory $total_memory
-	    $crit_level $warn_level
-            %exit_codes @memlist
-            $percent $fmt_pct 
-            $verb_err $command_line);
-
-# Predefined exit codes for Nagios
-%exit_codes   = ('UNKNOWN' ,-1,
-		 'OK'      , 0,
-                 'WARNING' , 1,
-                 'CRITICAL', 2,);
+$plugin->init();
 
-# Turn this to 1 to see reason for parameter errors (if any)
-$verb_err     = 0;
+$plugin->start_timeout($opt_t, "plugin timedout waiting for vmstat");
 
 # This the unix command string that brings Perl the data
-$command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`;
 
-chomp $command_line;
-@memlist      = split(/ /, $command_line);
+$ENV{PATH} = "/usr/bin:/bin";
+$ENV{BASH_ENV}="";
 
-# Define the calculating scalars
-$used_memory  = $memlist[0];
-$free_memory  = $memlist[1];
-$total_memory = $used_memory + $free_memory;
-
-# Get the options
-if ($#ARGV le 0)
-{
-  &usage;
-}
-else
-{
-  getopts('c:fuw:');
-}
-
-# Shortcircuit the switches
-if (!$opt_w or $opt_w == 0 or !$opt_c or $opt_c == 0)
-{
-  print "*** You must define WARN and CRITICAL levels!" if ($verb_err);
-  &usage;
-}
-elsif (!$opt_f and !$opt_u)
-{
-  print "*** You must select to monitor either USED or FREE memory!" if ($verb_err);
-  &usage;
-}
+my $command_line = `free | grep -i 'Mem:'`;
 
-# Check if levels are sane
-if ($opt_w <= $opt_c and $opt_f)
-{
-  print "*** WARN level must not be less than CRITICAL when checking FREE memory!" if ($verb_err);
-  &usage;
-}
-elsif ($opt_w >= $opt_c and $opt_u)
-{
-  print "*** WARN level must not be greater than CRITICAL when checking USED memory!" if ($verb_err);
-  &usage;
-}
-
-$warn_level   = $opt_w;
-$crit_level   = $opt_c;
+chomp $command_line;
 
-if ($opt_f)
-{
-  $percent    = $free_memory / $total_memory * 100;
-  $fmt_pct    = sprintf "%.1f", $percent;
-  if ($percent <= $crit_level)
-  {
-    print "Memory CRITICAL - $fmt_pct% ($free_memory kB) free\n";
-    exit $exit_codes{'CRITICAL'};
-  }
-  elsif ($percent <= $warn_level)
-  {
-    print "Memory WARNING - $fmt_pct% ($free_memory kB) free\n";
-    exit $exit_codes{'WARNING'};
-  }
-  else
-  {
-    print "Memory OK - $fmt_pct% ($free_memory kB) free\n";
-    exit $exit_codes{'OK'};
-  }
-}
-elsif ($opt_u)
-{
-  $percent    = $used_memory / $total_memory * 100;
-  $fmt_pct    = sprintf "%.1f", $percent;
-  if ($percent >= $crit_level)
-  {
-    print "Memory CRITICAL - $fmt_pct% ($used_memory kB) used\n";
-    exit $exit_codes{'CRITICAL'};
-  }
-  elsif ($percent >= $warn_level)
-  {
-    print "Memory WARNING - $fmt_pct% ($used_memory kB) used\n";
-    exit $exit_codes{'WARNING'};
-  }
-  else
-  {
-    print "Memory OK - $fmt_pct% ($used_memory kB) used\n";
-    exit $exit_codes{'OK'};
+# Define the calculating scalars
+$command_line =~ m/^mem:\s+\d+\s+(\d+)\s+(\d+)/i;
+my $used_memory  = $1;
+my $free_memory  = $2;
+my $total_memory = $used_memory + $free_memory;
+
+if ($opt_f) {
+  my $percent    = $free_memory / $total_memory * 100;
+  my $fmt_pct    = sprintf "%.1f", $percent;
+  if ($percent <= $opt_c)
+  {
+    print "$PROGNAME CRITICAL: $fmt_pct% ($free_memory kB) free\n";
+    exit $ERRORS{'CRITICAL'};
+  }  elsif ($percent <= $opt_w) {
+    print "$PROGNAME WARNING: $fmt_pct% ($free_memory kB) free\n";
+    exit $ERRORS{'WARNING'};
+  } else {
+    print "$PROGNAME OK: - $fmt_pct% ($free_memory kB) free\n";
+    exit $ERRORS{'OK'};
+  }
+} elsif ($opt_u) {
+  my $percent    = $used_memory / $total_memory * 100;
+  my $fmt_pct    = sprintf "%.1f", $percent;
+  if ($percent >= $opt_c)
+  {
+    print "$PROGNAME CRITICAL - $fmt_pct% ($used_memory kB) used\n";
+    exit $ERRORS{'CRITICAL'};
+  } elsif ($percent >= $opt_w) {
+    print "$PROGNAME WARNING: $fmt_pct% ($used_memory kB) used\n";
+    exit $ERRORS{'WARNING'};
+  } else {
+    print "PROGNAME OK: $fmt_pct% ($used_memory kB) used\n";
+    exit $ERRORS{'OK'};
   }
 }
-
-# Show usage
-sub usage()
-{
-  print "\ncheck_mem.pl v1.0 - Nagios Plugin\n\n";
-  print "usage:\n";
-  print " check_mem.pl -<f|u> -w <warnlevel> -c <critlevel>\n\n";
-  print "options:\n";
-  print " -f           Check FREE memory\n";
-  print " -u           Check USED memory\n";
-  print " -w PERCENT   Percent free/used when to warn\n";
-  print " -c PERCENT   Percent free/used when critical\n";
-  print "\nCopyright (C) 2000 Dan Larsson <dl\@tyfon.net>\n";
-  print "check_mem.pl comes with absolutely NO WARRANTY either implied or explicit\n";
-  print "This program is licensed under the terms of the\n";
-  print "GNU General Public License (check source code for details)\n";
-  exit $exit_codes{'UNKNOWN'}; 
-}
