diff -ruN nagiosplug-save/plugins-scripts/check_disk_smb.pl nagiosplug/plugins-scripts/check_disk_smb.pl
--- nagiosplug-save/plugins-scripts/check_disk_smb.pl	2003-09-15 15:26:54.000000000 +0100
+++ nagiosplug/plugins-scripts/check_disk_smb.pl	2004-03-27 21:54:48.000000000 +0000
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -wT
 #
 #
 # check_disk.pl <host> <share> <user> <pass> [warn] [critical] [port]
@@ -22,251 +22,187 @@
 require 5.004;
 use POSIX;
 use strict;
-use Getopt::Long;
-use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $verbose);
-use vars qw($PROGNAME);
 use lib utils.pm ;
-use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
-
-sub print_help ();
-sub print_usage ();
-
-$PROGNAME = "check_disk_smb";
+use Plugin;
+use Plugin::Parameter qw ($helpparameterlist $versionparameterlist $hostnameparameter
+			  $userparameter $passwordparameter $warningparameter
+			  $criticalparameter $portparameter $timeoutparameter
+			  $verboseparameter);
+use Getopt::Long;
+use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s
+	    $opt_W $opt_u $opt_p $opt_w $opt_c
+	    $opt_t $opt_v $spacecheck $PROGNAME);
+use lib $main::runtimedir;
+use utils qw(%ERRORS &usage);
 
 $ENV{'PATH'}='';
 $ENV{'BASH_ENV'}=''; 
 $ENV{'ENV'}='';
 
-Getopt::Long::Configure('bundling');
-GetOptions
-	("v"   => \$verbose, "verbose"    => \$verbose,
-	 "P=s" => \$opt_P, "port=s"     => \$opt_P,
-	 "V"   => \$opt_V, "version"    => \$opt_V,
-	 "h"   => \$opt_h, "help"       => \$opt_h,
-	 "w=s" => \$opt_w, "warning=s"  => \$opt_w,
-	 "c=s" => \$opt_c, "critical=s" => \$opt_c,
-	 "p=s" => \$opt_p, "password=s" => \$opt_p,
-	 "u=s" => \$opt_u, "username=s" => \$opt_u,
-	 "s=s" => \$opt_s, "share=s"    => \$opt_s,
-	 "W=s" => \$opt_W, "workgroup=s" => \$opt_W,
-	 "H=s" => \$opt_H, "hostname=s" => \$opt_H);
-
-if ($opt_V) {
-	print_revision($PROGNAME,'$Revision: 1.10 $'); #'
-	exit $ERRORS{'OK'};
-}
+$hostnameparameter->description("NetBIOS name of the server");
+my $shareparameter = new Plugin::Parameter(-name => "share", -flags => [ 's', 'share' ],
+					   -optional => "no", -valueoptional => 0, -type => "SMBPATH",
+					   -checker => \&Plugin::Parameter::_check_smbpath,
+					   -description => "Share name to be tested" );
+my $workgroupparameter = new Plugin::Parameter(-name => "workgroup", -flags => [ 'W', 'workgroup', 'domain' ],
+					       -optional => "yes", -valueoptional => 0, -type => "WORKGROUP",
+					       -default => "WORKGROUP",
+					       -description => "Workgroup or Domain to be used");
+
+my $sizechecker = sub { my ($opt, $parameter, $plugin) = @_;
+			if ($$opt !~ /^(100(\.0+)?%?)$/ && $$opt !~ /^([1-9][0-9](\.[0-9]+)?%?)$/
+			    && $$opt !~ /^([1-9][0-9]*[kMG])$/) {
+			  $plugin->usage();
+			  usage("$PROGNAME UNKNOWN: Invalid argument (--" . $parameter->name() ."): $$opt\n");
+			} else {
+			  $$opt = $1; # Untaint option
+			}
+		      };
+$userparameter->default("guest");
+$passwordparameter->default("guest");
+$warningparameter->default(85);
+$warningparameter->type("THRESHOLD");
+$warningparameter->checker($sizechecker);
+$warningparameter->description("Percentage of used space at which a warning status will be generated - May also specify amount of free space with k, M, G qualifier");
+$criticalparameter->default(95);
+$criticalparameter->type("THRESHOLD");
+$criticalparameter->checker($sizechecker);
+$warningparameter->description("Percentage of used space at which a critical status will be generated - May also specify amount of free space with k, M, G qualifier");
+$portparameter->description("Port to connect to. Some Windows boxes use 139 others use 445 - use smbclient default if no specified");
+@{$portparameter->flags()}[0] = 'P';
+
+my @commandparameterlist = ( $hostnameparameter,
+			     $shareparameter,
+			     $workgroupparameter,
+			     $userparameter,
+			     $passwordparameter,
+			     $warningparameter,
+			     $criticalparameter,
+			     $portparameter,
+			     $timeoutparameter,
+			     $verboseparameter );
+
+my $plugin = new Plugin(-revision => '$Revision: 1.10 $',
+			-copyright => "2000 Michael Anthon/Karl DeBisschop, 2004 Howard Wilkinson <howard\@cohtech.com>",
+			-shortcomment => "Perl Check SMB Disk plugin for Nagios.",
+			-longcomment  => "If thresholds are followed by either a k, M, or G then check to see if that much disk space is available (kilobytes, Megabytes, Gigabytes). Warning percentage should be less than critical. Warning (remaining) disk space should be greater than critical.",
+			-checker => sub { my ($plugin) = @_;
+					  # check if both warning and critical are percentage or size
+					  if ($opt_w =~ /^(([0-9]){1,2})%?$/ && $opt_c =~ /^(([0-9]){1,2})%?$/ ) {
+					    $opt_w =~ /^(\d+)%?$/;
+					    $opt_w = $1;
+					    $opt_c =~ /^(\d+)%?$/;
+					    $opt_c = $1;
+					    if ($opt_w >= $opt_c) {
+					      $plugin->usage();
+					      usage("$PROGNAME UNKNOWN: Percentage: warning ($opt_w) should be less than critical ($opt_c) \n");
+					    }
+					    $spacecheck = 0;
+					  } elsif ($opt_w =~ /^(\d+)[kMG]$/ && $opt_c =~ /^(\d+)[kMG]$/) {
+					    $opt_w =~ /^(\d+)([kMG])$/;
+					    $opt_w = $1;
+					    $opt_w *= 1024 if ($2 ne 'k');
+					    $opt_w *= 1024 if ($2 ne 'M');
+					    $opt_c =~ /^(\d+)([kMG])$/;
+					    $opt_c = $1;
+					    $opt_c *= 1024 if ($2 ne 'k');
+					    $opt_c *= 1024 if ($2 ne 'M');
+					    if ($opt_w <= $opt_c) {
+					      $plugin->usage();
+					      usage("$PROGNAME UNKNOWN: Disk size: warning ($opt_w) should be greater than critical ($opt_c) \n");
+					    }
+					    $spacecheck = 1;
+					  } else {
+					    $plugin->usage();
+					    usage("$PROGNAME UNKNOWN: Both warning and critical should be same type - warning: $opt_w critical: $opt_c \n");
+					  }
+					},
+			-parameterlists => [ \@commandparameterlist, $helpparameterlist, $versionparameterlist ] );
 
-if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
+$plugin->init();
 
 my $smbclient= "$utils::PATH_TO_SMBCLIENT " ;
 my $smbclientoptions= $opt_P ? "-p $opt_P " : "";
 
-
-# Options checking
-
-($opt_H) || ($opt_H = shift) || usage("Host name not specified\n");
-my $host = $1 if ($opt_H =~ /^([-_.A-Za-z0-9]+\$?)$/);
-($host) || usage("Invalid host: $opt_H\n");
-
-($opt_s) || ($opt_s = shift) || usage("Share volume not specified\n");
-my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9]+\$?)$/);
-($share) || usage("Invalid share: $opt_s\n");
-
-($opt_u) || ($opt_u = shift) || ($opt_u = "guest");
-my $user = $1 if ($opt_u =~ /^([-_.A-Za-z0-9\\]+)$/);
-($user) || usage("Invalid user: $opt_u\n");
-
-($opt_p) || ($opt_p = shift) || ($opt_p = "guest");
-my $pass = $1 if ($opt_p =~ /(.*)/);
-
-($opt_w) || ($opt_w = shift) || ($opt_w = 85);
-my $warn = $1 if ($opt_w =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/);
-($warn) || usage("Invalid warning threshold: $opt_w\n");
-
-($opt_c) || ($opt_c = shift) || ($opt_c = 95);
-my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/);
-($crit) || usage("Invalid critical threshold: $opt_c\n");
-
-# check if both warning and critical are percentage or size
-unless( ( ($opt_w =~ /([0-9]){1,2}$/ ) && ($opt_c =~ /([0-9]){1,2}$/ )  )|| (( $opt_w =~ /[kMG]/ ) && ($opt_c =~ /[kMG]/) )  ){
-	usage("Both warning and critical should be same type- warning: $opt_w critical: $opt_c \n");
-}
-
-# verify warning is less than critical
-if ( $opt_w =~ /[kMG]/) {
-	unless ( $warn > $crit) {
-		usage("Disk size: warning ($opt_w) should be greater than critical ($opt_c) \n");
-	}
-}else{
-	unless ( $warn < $crit) {
-		usage("Percentage: warning ($opt_w) should be less than critical ($opt_c) \n");
-	}
-}
-
-my $workgroup = $1 if (defined($opt_W) && $opt_W =~ /(.*)/);
-
-# end of options checking
-
-
 my $state = "OK";
 my $answer = undef;
-my $res = undef;
 my @lines = undef;
 
-# Just in case of problems, let's not hang Nagios
-$SIG{'ALRM'} = sub { 
-	print "No Answer from Client\n";
-	exit $ERRORS{"UNKNOWN"};
-};
-alarm($TIMEOUT);
+# Untaint opt_W which is not checked anywhere been a bit lazy
+$opt_W =~ m/^(.*)$/;
+$opt_W = $1;
+
+$plugin->start_timeout($opt_t, "No answer from SMBClient");
 
 # Execute an "ls" on the share using smbclient program
 # get the results into $res
-if (defined($workgroup)) {
-	$res = qx/$smbclient \/\/$host\/$share $pass -W $workgroup -U $user $smbclientoptions -c ls/;
-} else {
-	print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -c ls\n" if ($verbose);
-	$res = qx/$smbclient \/\/$host\/$share $pass -U $user $smbclientoptions -c ls/;
-}
-#Turn off alarm
-alarm(0);
+print "$smbclient " . "\/\/$opt_H\/$opt_s" ." '$opt_p' -W $opt_W -U $opt_u $smbclientoptions -c ls\n" if ($opt_v);
+my $res = qx/$smbclient \/\/$opt_H\/$opt_s '$opt_p' -W $opt_W -U $opt_u $smbclientoptions -c ls/;
+
+$plugin->stop_timeout();
 
 #Split $res into an array of lines
 @lines = split /\n/, $res;
 
 #Get the last line into $_
 $_ = $lines[$#lines];
-#print "$_\n";
 
-#Process the last line to get free space.  
+#Process the last line to get free space.
 #If line does not match required regexp, return an UNKNOWN error
 if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
 
-	my ($avail) = ($3*$2)/1024;
-	my ($avail_bytes) = $avail;
-	my ($capper) = int(($3/$1)*100);
-	my ($mountpt) = "\\\\$host\\$share";
-
-	#Check $warn and $crit for type (%/M/G) and set up for tests
-	#P = Percent, K = KBytes
-	my $warn_type;
-	my $crit_type;
-
-	if ($opt_w =~ /^([0-9]+$)/) {
-		$warn_type = "P";
-	} elsif ($opt_w =~ /^([0-9]+)k$/) {
-		$warn_type = "K";
-		$warn = $1;
-	} elsif ($opt_w =~ /^([0-9]+)M$/) {
-		$warn_type = "K";
-		$warn = $1 * 1024;
-	} elsif ($opt_w =~ /^([0-9]+)G$/) {
-		$warn_type = "K";
-		$warn = $1 * 1048576;
-	}
-	if ($opt_c =~ /^([0-9]+$)/) {
-		$crit_type = "P";
-	} elsif ($opt_c =~ /^([0-9]+)k$/) {
-		$crit_type = "K";
-		$crit = $1;
-	} elsif ($opt_c =~ /^([0-9]+)M$/) {
-		$crit_type = "K";
-		$crit = $1 * 1024;
-	} elsif ($opt_c =~ /^([0-9]+)G$/) {
-		$crit_type = "K";
-		$crit = $1 * 1048576;
-	}
-
-	if (int($avail / 1024) > 0) {
-		$avail = int($avail / 1024);
-		if (int($avail /1024) > 0) {
-			$avail = (int(($avail / 1024)*100))/100;
-			$avail = $avail ."G";
-		} else {
-			$avail = $avail ."M";
-		}
-	} else {
-		$avail = $avail ."K";
-	}
-
-#print ":$warn:$warn_type:\n";
-#print ":$crit:$crit_type:\n";
-#print ":$avail:$avail_bytes:$capper:$mountpt:\n";
-
-	if ((($warn_type eq "P") && (100 - $capper) < $warn) || (($warn_type eq "K") && ($avail_bytes > $warn))) { 
-		$answer = "Disk ok - $avail ($capper%) free on $mountpt\n";
-	} elsif ((($crit_type eq "P") && (100 - $capper) < $crit) || (($crit_type eq "K") && ($avail_bytes > $crit))) {
-		$state = "WARNING";
-		$answer = "WARNING: Only $avail ($capper%) free on $mountpt\n";
-	} else {
-		$state = "CRITICAL";
-		$answer = "CRITICAL: Only $avail ($capper%) free on $mountpt\n";
-	}
+  my ($avail) = ($3*$2)/1024;
+  my ($avail_bytes) = $avail;
+  my ($capper) = int(($3/$1)*100);
+  my ($mountpt) = "\\\\$opt_H\\$opt_s";
+
+  #Check $warn and $crit for type (%/M/G) and set up for tests
+  #P = Percent, K = KBytes
+
+  if (int($avail / 1024) > 0) {
+    $avail = int($avail / 1024);
+    if (int($avail /1024) > 0) {
+      $avail = (int(($avail / 1024)*100))/100;
+      $avail = $avail ."G";
+    } else {
+      $avail = $avail ."M";
+    }
+  } else {
+    $avail = $avail ."K";
+  }
+
+  if (((!$spacecheck) && (100 - $capper) < $opt_w) || (($spacecheck) && ($avail_bytes > $opt_w))) {
+    $answer = "Disk ok - $avail ($capper%) free on $mountpt\n";
+  } elsif (((!$spacecheck) && (100 - $capper) < $opt_c) || (($spacecheck) && ($avail_bytes > $opt_c))) {
+    $state = "WARNING";
+    $answer = "WARNING: Only $avail ($capper%) free on $mountpt\n";
+  } else {
+    $state = "CRITICAL";
+    $answer = "CRITICAL: Only $avail ($capper%) free on $mountpt\n";
+  }
 } else {
-	$answer = "Result from smbclient not suitable\n";
-	$state = "UNKNOWN";
-	foreach (@lines) {
-		if (/(Access denied|NT_STATUS_LOGON_FAILURE)/) {
-			$answer = "Access Denied\n";
-			$state = "CRITICAL";
-			last;
-		}
-		if (/(Unknown host \w*|Connection.*failed)/) {
-			$answer = "$1\n";
-			$state = "CRITICAL";
-			last;
-		}
-		if (/(You specified an invalid share name|NT_STATUS_BAD_NETWORK_NAME)/) {
-			$answer = "Invalid share name \\\\$host\\$share\n";
-			$state = "CRITICAL";
-			last;
-		}
-	}
-}
-
-
-print $answer;
-print "$state\n" if ($verbose);
-exit $ERRORS{$state};
-
-sub print_usage () {
-	print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password> 
-      -w <warn> -c <crit> [-W <workgroup>] [-P <port>]\n";
+  $answer = "Result from smbclient not suitable\n";
+  $state = "UNKNOWN";
+  foreach (@lines) {
+    if (/(Access denied|NT_STATUS_LOGON_FAILURE)/) {
+      $answer = "Access Denied\n";
+      $state = "CRITICAL";
+      last;
+    }
+    if (/(Unknown host \w*|Connection.*failed)/) {
+      $answer = "$1\n";
+      $state = "CRITICAL";
+      last;
+    }
+    if (/(You specified an invalid share name|NT_STATUS_BAD_NETWORK_NAME)/) {
+      $answer = "Invalid share name \\\\$opt_H\\$opt_s\n";
+      $state = "CRITICAL";
+      last;
+    }
+  }
 }
 
-sub print_help () {
-	print_revision($PROGNAME,'$Revision: 1.10 $');
-	print "Copyright (c) 2000 Michael Anthon/Karl DeBisschop
-
-Perl Check SMB Disk plugin for Nagios
-
-";
-	print_usage();
-	print "
--H, --hostname=HOST
-   NetBIOS name of the server
--s, --share=STRING
-   Share name to be tested
--W, --workgroup=STRING
-   Workgroup or Domain used (Defaults to \"WORKGROUP\")
--u, --user=STRING
-   Username to log in to server. (Defaults to \"guest\")
--p, --password=STRING
-   Password to log in to server. (Defaults to \"guest\")
--w, --warning=INTEGER or INTEGER[kMG]
-   Percent of used space at which a warning will be generated (Default: 85%)
-      
--c, --critical=INTEGER or INTEGER[kMG]
-   Percent of used space at which a critical will be generated (Defaults: 95%)
--P, --port=INTEGER
-   Port to be used to connect to. Some Windows boxes use 139, others 445 (Defaults to smbclient default)
-   
-   If thresholds are followed by either a k, M, or G then check to see if that
-   much disk space is available (kilobytes, Megabytes, Gigabytes)
 
-   Warning percentage should be less than critical
-   Warning (remaining) disk space should be greater than critical.
+print "$PROGNAME $state: $answer";
 
-";
-	support();
-}
+exit $ERRORS{$state};
