/[nagios-plugins-perl]/trunk/plugins/check_haproxy.pl
ViewVC logotype

Diff of /trunk/plugins/check_haproxy.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 131 by racvision, Fri Feb 26 11:22:11 2010 UTC revision 135 by racvision, Fri Mar 12 17:26:57 2010 UTC
# Line 55  textdomain('nagios-plugins-perl'); Line 55  textdomain('nagios-plugins-perl');
55  my $np = Nagios::Plugin->new(  my $np = Nagios::Plugin->new(
56          version => $VERSION,          version => $VERSION,
57          blurb => _gt('Plugin to check HAProxy stats url'),          blurb => _gt('Plugin to check HAProxy stats url'),
58          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> ]",
59          timeout => $TIMEOUT+1          timeout => $TIMEOUT+1
60  );  );
61  $np->add_arg (  $np->add_arg (
# Line 64  $np->add_arg ( Line 64  $np->add_arg (
64          default => 0,          default => 0,
65  );  );
66  $np->add_arg (  $np->add_arg (
67      spec => 'username|U=s',
68      help => _gt('Username for HTTP Auth'),
69      required => 0,
70    );
71    $np->add_arg (
72      spec => 'password|P=s',
73      help => _gt('Password for HTTP Auth'),
74      required => 0,
75    );
76    $np->add_arg (
77          spec => 'w=f',          spec => 'w=f',
78          help => _gt('Warning request time threshold (in seconds)'),          help => _gt('Warning request time threshold (in seconds)'),
79          default => 2,          default => 2,
# Line 86  $np->getopts; Line 96  $np->getopts;
96    
97  $DEBUG = $np->opts->get('debug');  $DEBUG = $np->opts->get('debug');
98  my $verbose = $np->opts->get('verbose');  my $verbose = $np->opts->get('verbose');
99    my $username = $np->opts->get('username');
100    my $password = $np->opts->get('password');
101    
102  # Thresholds :  # Thresholds :
103  # time  # time
# Line 114  if ( defined($ENV{'http_proxy'}) ) { Line 126  if ( defined($ENV{'http_proxy'}) ) {
126    
127  # Build and submit an http request :  # Build and submit an http request :
128  my $request = HTTP::Request->new('GET', $url);  my $request = HTTP::Request->new('GET', $url);
129    # Authenticate if username and password are supplied
130    if ( defined($username) && defined($password) ) {
131      $request->authorization_basic($username, $password);
132    }
133  my $timer = time();  my $timer = time();
134  my $http_response = $ua->request( $request );  my $http_response = $ua->request( $request );
135  $timer = time()-$timer;  $timer = time()-$timer;
# Line 181  if ( $http_response->is_success() ) { Line 197  if ( $http_response->is_success() ) {
197                  if ( !defined($stats{$values[0]}{$values[1]}) ) {                  if ( !defined($stats{$values[0]}{$values[1]}) ) {
198                          $stats{$values[0]}{$values[1]} = {};                          $stats{$values[0]}{$values[1]} = {};
199                  }                  }
200                  for ( my $x = 2,; $x < $#values; $x++ ) {                  for ( my $x = 2,; $x <= $#values; $x++ ) {
201                          # $stats{pxname}{svname}{valuename}                          # $stats{pxname}{svname}{valuename}
202                          $stats{$values[0]}{$values[1]}{$fields[$x]} = $values[$x];                          $stats{$values[0]}{$values[1]}{$fields[$x]} = $values[$x];
203                  }                  }

Legend:
Removed from v.131  
changed lines
  Added in v.135

  ViewVC Help
Powered by ViewVC 1.1.8