Hi,

I have a small patch that seems to address an issue to get the 'type'
csv values

Also, this add -U and -P switches to supply username/password
credentials for http basic auth.


Chantra


!DSPAM:4b98e00261671119019326!
diff -r fd7ee65c064b check_haproxy.pl
--- a/check_haproxy.pl	Thu Mar 11 11:25:18 2010 +0100
+++ b/check_haproxy.pl	Thu Mar 11 13:07:33 2010 +0100
@@ -55,13 +55,23 @@
 my $np = Nagios::Plugin->new(
 	version => $VERSION,
 	blurb => _gt('Plugin to check HAProxy stats url'),
-	usage => "Usage: %s [ -v|--verbose ]  -u <url> [-t <timeout>] [ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]",
+	usage => "Usage: %s [ -v|--verbose ]  -u <url> [-t <timeout>] [-U <username>] [-P <password>] [ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]",
 	timeout => $TIMEOUT+1
 );
 $np->add_arg (
 	spec => 'debug|d',
 	help => _gt('Debug level'),
 	default => 0,
+);
+$np->add_arg (
+  spec => 'username|U=s',
+  help => _gt('Username for HTTP Auth'),
+  required => 0, 
+);
+$np->add_arg (
+  spec => 'password|P=s',
+  help => _gt('Password for HTTP Auth'),
+  required => 0, 
 );
 $np->add_arg (
 	spec => 'w=f',
@@ -86,6 +96,8 @@
 
 $DEBUG = $np->opts->get('debug');
 my $verbose = $np->opts->get('verbose');
+my $username = $np->opts->get('username');
+my $password = $np->opts->get('password');
 
 # Thresholds :
 # time
@@ -114,6 +126,10 @@
 
 # Build and submit an http request :
 my $request = HTTP::Request->new('GET', $url);
+# Authenticate if username and password are supplied
+if ( defined($username) && defined($password) ) {
+  $request->authorization_basic($username, $password);
+}
 my $timer = time();
 my $http_response = $ua->request( $request );
 $timer = time()-$timer;
@@ -181,7 +197,7 @@
 		if ( !defined($stats{$values[0]}{$values[1]}) ) {
 			$stats{$values[0]}{$values[1]} = {};
 		}
-		for ( my $x = 2,; $x < $#values; $x++ ) {
+		for ( my $x = 2,; $x <= $#values; $x++ ) {
 			# $stats{pxname}{svname}{valuename}
 			$stats{$values[0]}{$values[1]}{$fields[$x]} = $values[$x];
 		}

Reply via email to