diff -ruN nagiosplug-save/contrib/check_apc_ups.pl nagiosplug/contrib/check_apc_ups.pl
--- nagiosplug-save/contrib/check_apc_ups.pl	2002-08-14 20:02:31.000000000 +0100
+++ nagiosplug/contrib/check_apc_ups.pl	2004-03-27 21:17:45.000000000 +0000
@@ -1,82 +1,83 @@
 #! /usr/bin/perl -wT
 #
 # Check_apc_ups - Check APC UPS status via SNMP
-# Shamelessly copied from check_breeze.pl
 #
 # To do:
-# - Send SNMP queries directly, instead of forking `snmpget`.
 # - Make the status less verbose.  Maybe we can send an "onLine, time
 #   remaining: hh:mm:ss" if all is well, and a list of specific problems
-#   if something is broken. 
+#   if something is broken.
 
+require 5.004;
 use strict;
-use Getopt::Long;
-use vars qw($opt_V $opt_h $opt_H $opt_T $opt_t $opt_R $opt_r 
-  $opt_L $opt_l $PROGNAME);
-use lib utils.pm;
-use utils qw(%ERRORS &print_revision &support &usage);
-
-sub print_help ();
-sub print_usage ();
-sub get_snmp_int_val ($);
+use lib utils.pm ;
+use Plugin;
+use Plugin::Parameter qw($helpparameterlist $versionparameterlist $hostnameparameter
+			 $communityparameter $portparameter $timeoutparameter
+			 $verboseparameter);
+
+use Net::SNMP;
+use vars qw($opt_V $opt_h $opt_H $opt_T $opt_S $opt_R
+	    $opt_r $opt_L $opt_l $xml $opt_C $opt_p
+	    $opt_t $PROGNAME);
+use utils qw(%ERRORS &usage);
+
+sub get_snmp_int_values ($$$$$);
 sub escalate_exitval ($);
 
 $ENV{'PATH'}='';
-$ENV{'BASH_ENV'}=''; 
+$ENV{'BASH_ENV'}='';
 $ENV{'ENV'}='';
+$ENV{'CDPATH'}='';
 
-Getopt::Long::Configure('bundling');
-GetOptions
-	("V"   => \$opt_V, "version"		=> \$opt_V,
-	 "h"   => \$opt_h, "help"		=> \$opt_h,
-	 "T=s" => \$opt_T, "temp-critical"	=> \$opt_T,
-	 "t=s" => \$opt_t, "temp-warning"	=> \$opt_t,
-	 "R=s" => \$opt_R, "runtime-critical"	=> \$opt_R,
-	 "r=s" => \$opt_r, "runtime-warning"	=> \$opt_r,
-	 "L=s" => \$opt_L, "load-critical"	=> \$opt_L,
-	 "l=s" => \$opt_l, "load-warning"	=> \$opt_l,
-	 "H=s" => \$opt_H, "hostname=s"		=> \$opt_H);
-
-if ($opt_V) {
-	print_revision($PROGNAME,'$Revision: 1.2 $');
-	exit $ERRORS{'OK'};
-}
-
-if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
-
-($opt_H) || ($opt_H = shift) || usage("Host name/address not specified\n");
-my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
-($host) || usage("Invalid host: $opt_H\n");
-
-# Defaults
-
-$opt_R *= 60 * 100 if (defined $opt_R);	# Convert minutes to secs/100
-$opt_r *= 60 * 100 if (defined $opt_R);
+my $tempcriticalparameter = new Plugin::Parameter(-name => "criticaltemperature", -flags => [ 'T', 'temp-critical' ],
+						  -optional => 1, -valueoptional => 0, -type => "TEMPERATURE", -default => 60,
+						  -checker => \&Plugin::Parameter::_check_temperature,
+						  -description => "Battery degress C above which a CRITICAL status will result");
+my $tempwarningparameter = new Plugin::Parameter(-name => "warningtemperature", -flags => [ 'S', 'temp-warning' ],
+						 -optional => 1, -valueoptional => 0, -type => "TEMPERATURE", -default => 40,
+						  -checker => \&Plugin::Parameter::_check_temperature,
+						 -description => "Battery degress C above which a WARNING status will result");
+my $runtimecriticalparameter = new Plugin::Parameter(-name => "runtimecritical", -flags => [ 'R', 'runtime-critical' ],
+						     -optional => 1, -valueoptional => 0, -type => "MINUTES", -default => 30,
+						     -checker => \&Plugin::Parameter::_check_time,
+						     -description => "Minutes remaining below which a CRITICAL status will result");
+my $runtimewarningparameter = new Plugin::Parameter(-name => "runtimewarning", -flags => [ 'r', 'runtime-warning' ],
+						    -optional => 0, -valueoptional => 0, -type => "MINUTES", -default => 60,
+						    -checker => \&Plugin::Parameter::_check_time,
+						    -description => "Minutes remaining below which a WARNING status will result");
+my $loadcriticalparameter = new Plugin::Parameter(-name => "criticalload", -flags => [ 'L', 'load-critical' ],
+						  -optional => 0, -valueoptional => 0, -type => "PERCENT", -default => 85,
+						  -checker => \&Plugin::Parameter::_check_percent,
+						  -description => "Output load pct above which a CRITICAL status will result");
+my $loadwarningparameter = new Plugin::Parameter(-name => "warningload", -flags => [ 'l', 'load-warning'],
+						 -optional => 0, -valueoptional => 0, -type => "PERCENT", -default => 50,
+						  -checker => \&Plugin::Parameter::_check_percent,
+						 -description => "Output load pct above which a WARNING status will result");
+$portparameter->default("snmp");
+my @commandparameterlist = ( $hostnameparameter,
+			     $communityparameter,
+			     $tempcriticalparameter,
+			     $tempwarningparameter,
+			     $runtimecriticalparameter,
+			     $runtimewarningparameter,
+			     $loadcriticalparameter,
+			     $loadwarningparameter,
+			     $timeoutparameter,
+			     $portparameter,
+			     $verboseparameter);
+
+my $plugin = new Plugin(-revision             => '$Revision: 1.2 $',
+			-copyright            => "2001 Gerald Combs/Jeffrey Blank/Karl DeBisschop, 2004 Howard Wilkinson <howard\@cohtech.com>",
+			-shortcomment         => "This plugin reports the status of an APC UPS equipped with an SNMP management module.",
+			-parameterlists       => [ \@commandparameterlist, $helpparameterlist, $versionparameterlist ] );
 
-my $tempcrit    = $opt_T || 60;
-my $tempwarn    = $opt_t || 40;
-my $runtimecrit = $opt_R || 30 * 60 * 100;     # Secs / 100
-my $runtimewarn = $opt_r || 60 * 60 * 100;
-my $loadcrit    = $opt_L || 85;
-my $loadwarn    = $opt_l || 50;
 
-if ($tempcrit !~ /\d+/) { usage ("Invalid critical temperature threshold.\n"); }
-if ($tempwarn !~ /\d+/) { usage ("Invalid critical temperature threshold.\n"); }
+$plugin->init();
 
-if ($runtimecrit !~ /\d+/) {
-  usage ("Invalid critical run time threshold.\n");
-}
-if ($runtimewarn !~ /\d+/) {
-  usage ("Invalid warning run time threshold.\n");
-}
-
-if ($loadcrit !~ /\d+/ || $loadcrit < 0 || $loadcrit > 100) {
-  usage ("Invalid critical load threshold.\n");
-}
-if ($loadwarn !~ /\d+/ || $loadwarn < 0 || $loadwarn > 100) {
-  usage ("Invalid warning load threshold.\n");
-}
+# Defaults
 
+$opt_R *= 60 * 100;	# Convert minutes to secs/100
+$opt_r *= 60 * 100;
 
 # APC UPS OIDs
 # APC MIBs are available at ftp://ftp.apcftp.com/software/pnetmib/mib
@@ -140,164 +141,147 @@
   [ "testInProgress",	$ERRORS{'OK'} ],	# 4
 );
 
-my $exitval     = $ERRORS{'UNKNOWN'};
-my $data;
+my $sep         = ", ";
+my $exitval     = $ERRORS{'OK'};
 my $onbattery   = 3;
 
-$data = get_snmp_int_val( $upsBasicOutputStatus );
+my $data = &get_snmp_int_values( $opt_H, $opt_C, $opt_t, $opt_p,
+				 [ $upsBasicOutputStatus,
+				   $upsBasicBatteryStatus,
+				   $upsAdvInputLineFailCause,
+				   $upsAdvBatteryTemperature,
+				   $upsAdvBatteryRunTimeRemaining,
+				   $upsAdvBatteryReplaceIndicator,
+				   $upsAdvOutputLoad,
+				   $upsAdvTestDiagnosticsResults ] );
+
+if (!defined $data) {
+  print "Status UNKNOWN\n";
+  exit $ERRORS{'UNKNOWN'};
+}
+
+my $OutputStatus = $data->{$upsBasicOutputStatus};
+my $BatteryStatus = $data->{$upsBasicBatteryStatus};
+my $InputLineFailCause = $data->{$upsAdvInputLineFailCause};
+my $BatteryTemperature = $data->{$upsAdvBatteryTemperature};
+my $BatteryRunTimeRemaining = $data->{$upsAdvBatteryRunTimeRemaining};
+my $BatteryReplaceIndicator = $data->{$upsAdvBatteryReplaceIndicator};
+my $OutputLoad = $data->{$upsAdvOutputLoad};
+my $TestDiagnosticsResults = $data->{$upsAdvTestDiagnosticsResults};
 
 print "Output status: ";
-if (defined ($data) && defined ($outputStatVals[$data][0])) {
-  print "$outputStatVals[$data][0] | ";
-  escalate_exitval($outputStatVals[$data][1]);
+if (defined ($OutputStatus) && defined ($outputStatVals[$OutputStatus][0])) {
+  print "$outputStatVals[$OutputStatus][0]$sep";
+  escalate_exitval($outputStatVals[$OutputStatus][1]);
 } else {
-  print "unknown | ";
+  print "unknown$sep";
 }
 
-$data = get_snmp_int_val( $upsAdvBatteryRunTimeRemaining );
-
 print "Rem time: ";
-if (defined ($data)) {
-  my $hrs  = int($data / (60 * 60 * 100)); # Data is hundredths of a second
-  my $mins = int($data / (60 * 100)) % 60;
-  my $secs = ($data % 100) / 100;
-  printf "%d:%02d:%05.2f | ", $hrs, $mins, $secs;
-  if ($data <= $runtimecrit) {
+if (defined ($BatteryRunTimeRemaining)) {
+  my $hrs  = int($BatteryRunTimeRemaining / (60 * 60 * 100)); # Data is hundredths of a second
+  my $mins = int($BatteryRunTimeRemaining / (60 * 100)) % 60;
+  my $secs = ($BatteryRunTimeRemaining % 100) / 100;
+  printf "%d:%02d:%05.2f$sep", $hrs, $mins, $secs;
+  if ($BatteryRunTimeRemaining <= $opt_R) {
     escalate_exitval($ERRORS{'CRITICAL'});
-  } elsif ($data <= $runtimewarn) {
+  } elsif ($BatteryRunTimeRemaining <= $opt_r) {
     escalate_exitval($ERRORS{'WARNING'});
   } else {
     escalate_exitval($ERRORS{'OK'});
   }
 } else {
-  print "unknown | ";
+  print "unknown$sep";
 }
 
-$data = get_snmp_int_val( $upsBasicBatteryStatus );
-
 print "Battery status: ";
-if (defined ($data) && defined ($battStatVals[$data][0])) {
+if (defined ($BatteryStatus) && defined ($battStatVals[$BatteryStatus][0])) {
   my $failcause = "unknown";
-  my $fc = get_snmp_int_val( $upsAdvInputLineFailCause );
-  if ($data == $onbattery) {
-    if (defined ($failCauseVals[$fc])) { $failcause = $failCauseVals[$fc]; }
-    print "$battStatVals[$data][0] ($failcause) | ";
+  if ($BatteryStatus == $onbattery) {
+    if (defined ($failCauseVals[$InputLineFailCause])) {
+      $failcause = $failCauseVals[$InputLineFailCause];
+    }
+    print "$battStatVals[$BatteryStatus][0] ($failcause)$sep";
   } else {
-    print "$battStatVals[$data][0] | ";
+    print "$battStatVals[$BatteryStatus][0]$sep";
   }
-  escalate_exitval($battStatVals[$data][1]);
+  escalate_exitval($battStatVals[$BatteryStatus][1]);
 } else {
-  print "unknown | ";
+  print "unknown$sep";
 }
 
-$data = get_snmp_int_val( $upsAdvBatteryTemperature );
-
 print "Battery temp(C): ";
-if (defined ($data)) {
-  print "$data | ";
-  if ($data >= $tempcrit) {
+if (defined ($BatteryTemperature)) {
+  print "$BatteryTemperature$sep";
+  if ($BatteryTemperature >= $opt_T) {
     escalate_exitval($ERRORS{'CRITICAL'});
-  } elsif ($data >= $tempwarn) {
+  } elsif ($BatteryTemperature >= $opt_S) {
     escalate_exitval($ERRORS{'WARNING'});
   } else {
     escalate_exitval($ERRORS{'OK'});
   }
 } else {
-  print "unknown | ";
+  print "unknown$sep";
 }
 
-$data = get_snmp_int_val( $upsAdvBatteryReplaceIndicator );
-
 print "Battery repl: ";
-if (defined ($data) && defined ($battReplVals[$data][0])) {
-  print "$battReplVals[$data][0] | ";
-  escalate_exitval($battReplVals[$data][1]);
+if (defined ($BatteryReplaceIndicator) && defined ($battReplVals[$BatteryReplaceIndicator][0])) {
+  print "$battReplVals[$BatteryReplaceIndicator][0]$sep";
+  escalate_exitval($battReplVals[$BatteryReplaceIndicator][1]);
 } else {
-  print "unknown | ";
+  print "unknown$sep";
 }
 
-$data = get_snmp_int_val( $upsAdvOutputLoad );
-
 print "Output load (%): ";
-if (defined ($data)) {
-  print "$data | ";
-  if ($data >= $loadcrit) {
+if (defined ($OutputLoad)) {
+  print "$OutputLoad$sep";
+  if ($OutputLoad >= $opt_L) {
     escalate_exitval($ERRORS{'CRITICAL'});
-  } elsif ($data >= $loadwarn) {
+  } elsif ($OutputLoad >= $opt_l) {
     escalate_exitval($ERRORS{'WARNING'});
   } else {
     escalate_exitval($ERRORS{'OK'});
   }
 } else {
-  print "unknown | ";
+  print "unknown$sep";
 }
 
-$data = get_snmp_int_val( $upsAdvTestDiagnosticsResults );
-
 print "Diag result: ";
-if (defined ($data) && defined ($diagnosticsResultsVals[$data][0])) {
-  print "$diagnosticsResultsVals[$data][0]\n";
-  escalate_exitval($diagnosticsResultsVals[$data][1]);
+if (defined ($TestDiagnosticsResults)
+    && defined ($diagnosticsResultsVals[$TestDiagnosticsResults][0])) {
+  print "$diagnosticsResultsVals[$TestDiagnosticsResults][0]$sep";
+  escalate_exitval($diagnosticsResultsVals[$TestDiagnosticsResults][1]);
 } else {
-  print "unknown\n";
+  print "unknown$sep";
 }
 
+foreach my $key (keys %ERRORS) {
+  if ($ERRORS{$key} == $exitval) {
+    print "Status $key\n";
+    last;
+  }
+}
 
 exit $exitval;
 
 
-sub print_usage () {
-	print "Usage: $PROGNAME -H <host> -T temp -t temp -R minutes -r minutes\n";
-	print "  -L percent -l percent\n";
-}
-
-sub print_help () {
-	print_revision($PROGNAME,'$Revision: 1.2 $');
-	print "Copyright (c) 2001 Gerald Combs/Jeffrey Blank/Karl DeBisschop
-
-This plugin reports the status of an APC UPS equipped with an SNMP management
-module.
-
-";
-	print_usage();
-	print "
--H, --hostname=HOST
-   Name or IP address of host to check
--T --temp-critical
-   Battery degrees C above which a CRITICAL status will result (default: 60)
--t --temp-warning
-   Battery degrees C above which a WARNING status will result (default: 40)
--R --runtime-critical
-   Minutes remaining below which a CRITICAL status will result (default: 30)
--r --runtime-warning
-   Minutes remaining below which a WARNING status will result (default: 60)
--L --load-critical
-   Output load pct above which a CRITICAL status will result (default: 85
--l --load-warning
-   Output load pct above which a WARNING status will result (default: 50
-
-";
-	support();
-}
-
-sub get_snmp_int_val ($) {
-  my $val=0;
-  my $oid = shift(@_);
-
-  $val = `/usr/bin/snmpget $host public $oid 2> /dev/null`;
-  my @test = split(/ /,$val,3);
-
-  return undef unless (defined ($test[2]));
-
-  if ($test[2] =~ /\(\d+\)/) {	# Later versions of UCD SNMP
-    ($val) = ($test[2] =~ /\((\d+)\)/);
-  } elsif ($test[2] =~ /: \d+/) {
-    ($val) = ($test[2] =~ /: (\d+)/);
-  } else {
-    $val = $test[2];
+sub get_snmp_int_values ($$$$$) {
+
+  my ( $host, $community, $timeout, $port, $oids ) = @_;
+
+  my $response = undef;
+
+  my ($session, $error) = Net::SNMP->session(-hostname => $host,
+					     -community => $community,
+					     -timeout => $timeout,
+					     -port => $port,
+					     -translate => undef);
+  if (defined($session)) {
+    $response=$session->get_request(-varbindlist => $oids);
+    $session->close;
   }
 
-  return $val;
+  return $response
 }
 
 sub escalate_exitval ($) {
