Monitoring Bea Weblogic thread pools with a Perl script

Recently i developed a Perl script for a TLC company to monitor thread pools of a weblogic cluster
with nagios, here i’m going to post a sample version.

#!/usr/bin/perl
 
use warnings;
use Getopt::Std;
 
our($opt_H, $opt_p, $opt_w, $opt_c, $opt_q);
 
getopt('Hpwcsq');
 
my $username = 'XXX';
my $pwd = 'XXX';
 
my $port = 10080;
my $service = "ExecuteQueueRuntime";
my $warn = 85;
my $crit = 95;
my @queues;
my $q = 0;
$opt_H or help();
 
if($opt_w){
	$warn = $opt_w;
}
if($opt_c){
	$crit = $opt_c;
}
if($opt_p){
	$port = $opt_p;
}
if($opt_s){
	$service = $opt_s;
}
if($opt_q){
	$q=$opt_q;
}
 
$ENV{JAVA_HOME}='/opt/java/';
$ENV{WL_HOME}='/opt/weblogic81/';
$ENV{CLASSPATH}=$ENV{WL_HOME} . 'server/lib/weblogic.jar';
my $i;
$ret = `$ENV{JAVA_HOME}/bin/java weblogic.Admin -url t3://$opt_H:$port -username $username -password $pwd GET -pretty -type $service 2>/dev/null`;
open FD, ";
if(!$q){
	print $ret . "\n";
	exit(1);
}
for($i = 1; $i< scalar(@buf); $i++){
	$found = 0;
	if($buf[$i] =~ /^\tObjectName: $q$/){
		$found = 1;
		last;
	}
}
 
if(!$found){
	print "UNKNOWN - Queue \"$q\" not found\n";
	exit(1);
}
 
$buf[$i-3] =~ s/\t//g;
$buf[$i-4] =~ s/\t//g;
$buf[$i-3] =~ m/(\d+)/;
$total = $1;
$buf[$i-4] =~ m/(\d+)/;
$idle = $1;
 
$working = $total - $idle;
 
$ratio = 100 * $working / $total;
 
if($ratio >= $crit){
	$status = "CRITICAL";
}elsif($ratio >= $warn){
	$status = "WARNING";
}else{
	$status = "OK";
}
 
print "$status - Working threads $ratio%\n";
 
exit 0;
 
sub help{
	print "HELP\n";
	print "USAGE: command -H ipaddress [-s servicename] [-p port] [-w warn threshold] [-c crit threshold]\n";
	exit(1);
}
Share

Leave a Reply

Your e-mail address will not be published. Required fields are marked *