<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
#use strict;    # turn on compiler restrictions
use LWP::Simple;

my $file  = "";  my @field   = ();  
my $specific_line = "pg_farm";
my $num_args = $#ARGV +1;
if ($num_args &lt; 3) {
# SHould be at least 2 variables... Server &amp; JBoss Node1
  print "\nUsage: check_hastats.pl [servername]:[port] [warn] [critical] \n Only $num_args was supplied...\n";
  exit;
}else
{
	 $mServer = $ARGV[0]; $mPort = $ARGV[1]; 
	 $mWARN = $ARGV[2]; $mCRIT = $ARGV[3]; 
}
my $browser = LWP::UserAgent-&gt;new;
 my @ns_headers = (  'Accept-Charset' =&gt; 'iso-8859-1,*,utf-8',
   'Authorization' =&gt; 'Basic YWRtaW46YWJjMTIz' );

my $mFile = "/tmp/inha.stats";
my $url = "http://$mServer:$mPort/haproxy?stats;csv";
my $content = $browser-&gt;get($url, @ns_headers);  die "Couldn't get $url" unless defined $content;
open (MYFILE, "&gt; $mFile");
print MYFILE $content-&gt;content;
close (MYFILE);

open( INFILE, $mFile )  or die("Can not open input file: $mFile");
my $mStats ="";   my $mWarnOk=0;
my $mPerfs ="|";  my $mHitCrit=0;
my $mAlert = "All Slaves OK:";

while ( $file = &lt;INFILE&gt; ) {
    @field = parse_csv($file);
    chomp(@field);
		
    if ( ($field[0] eq $specific_line ) &amp;&amp; !($field[1] eq "BACKEND") ) {
        $mStats = "$mStats $field[1]=$field[4]";
        $mPerfs = "$mPerfs $field[1]=$field[4]";
        if (!($field[1] eq "FRONTEND") ) {
        	  if (($field[4] &gt; $mWARN) &amp;&amp; ($mHitCrit==0)) {  $mAlert ="Slave Overload:"; 
        	  	 $mWarnOk=1;  if ($field[4] &gt; $mCRIT) {$mAlert ="Slave CRITICAL:"; $mHitCrit=1;}
        	  } 
        }
    }
}
close(INFILE);  
unlink($mFile);
print "$mAlert $mStats $mPerfs";
exit $mWarnOk;


sub parse_csv {
    my $text = shift;
    my @new  = ();
    push( @new, $+ ) while $text =~ m{
       "([^\"\\]*(?:\\.[^\"\\]*)*)",?
           |  ([^,]+),?
           | ,
       }gx;
    push( @new, undef ) if substr( $text, -1, 1 ) eq ',';
    return @new;
}
</pre></body></html>