Forum Discussion
royster_128009
Nimbostratus
Oct 03, 2003Using iControl with Health Monitors
Hi,
I have been using BIGIPs at our company for several of our customers for a couple of years.
I have written custom monitors using perl before testing appilication avai...
royster_128009
Nimbostratus
Nov 19, 2003Hello.
Below is a copy of the script that we are currently testing with.
A few notes.
Firstly, the 'NoNew' or 'Draining' functionality is only as good as the persistence model you use. We monitor two different types of pools, http and https. The https persistence used SSL ID and for http - we inserted a cookie with a zero value for expiration so it was more session based. It seems to work very well.
Also for 'NoNew' we did a $STATE_DISABLED coupled with a $AVAILABILITY_UP in order to get it to work.
Comments welcome.
!/usr/bin/perl
BIG-IP Script to check App Status using iControl /
R.Dimbleby / Joe of F5 20/10/03
use strict;
use SOAP::Lite + trace => qw(method debug);
use SOAP::Lite;
my $programname = "web01_http_8001_checker";
if ($programname eq '') {
die "Bad data in program name\n"
}
Process ID and file where it's to be stored. The format
is significant.
my $pidfile = "/var/run/$programname.pid";
my $pid = "$$";
Maintenence. Clean up any existing EAV.
if (-f $pidfile ) {
open(PID, "<$pidfile");
my $pid = ; chomp $pid; $pid =~ m/^(\d+)$/; $pid = $1;
close(PID);
kill -9, $pid;
unlink($pidfile);
}
Create a new maintenence file.
open(PID, ">$pidfile");
print PID $pid, "\n";
close(PID);
my $sBIGIPAddress = "10.10.5.2"; Enter local BIG-IP address here
my $sUID = ""; Enter Local Username here
my $sPWD = ""; Enter Local Password here
my $sNodeIP = "10.10.11.3"; Set to nodes ip address
my $sNodePort = "8001"; Set to node's port
my $curl = "/usr/local/bin/curl";
my $timeout = 10;
my $output = "/usr/local/lib/pingers/output_$sNodeIP\_$sNodePort";
my $url = "http://$sNodeIP:$sNodePort/getstatus.jsp";
my $node_definition = { address => $sNodeIP, port => $sNodePort };
my $AVAILABILITY_ENABLED = 8;
my $AVAILABILITY_DISABLED = 9;
my $AVAILABILITY_DOWN = 1;
my $AVAILABILITY_UP = 2;
my $STATE_DISABLED = 0;
my $STATE_ENABLED = 1;
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
}
my $LocalLBNode = SOAP::Lite
-> uri('urn:iControl:ITCMLocalLB/Node')
-> readable(1)
-> proxy("https://$sBIGIPAddress/iControl/iControlPortal.cgi");
poll webserver for status code
my $sResponse = &pollWebServer();
perform node action based on status code
If nothing at all
if ( -z $output )
{ stop traffic
$LocalLBNode->set_availability
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $AVAILABILITY_DOWN )
);
}
elsif ( $sResponse eq "NotOK" )
{
stop traffic
$LocalLBNode->set_availability
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $AVAILABILITY_DOWN )
);
}
elsif ( $sResponse eq "OK" )
{
print "UP\n";
checkOKState();
}
elsif ( $sResponse eq "NoNew" )
{
"drain" connections
print "No New\n";
$LocalLBNode->set_state
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $STATE_DISABLED )
);
$LocalLBNode->set_availability
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $AVAILABILITY_UP )
)
}
pollWebServer
Get status from Webserver
sub pollWebServer {
my($returnval)="";
my $line="";
For SSL use system("$curl -m $timeout -E BigIPMonitor.pem $url > $output");
system("$curl -m $timeout $url > $output");
open(fd,"/usr/local/lib/pingers/output_$sNodeIP\_$sNodePort");
my @lines=;
foreach $line (@lines) {
if ($line =~ /\bNotOK\b/) { $returnval="NotOK"; }
if ($line =~ /\bOK\b/) { $returnval="OK"; }
if ($line =~ /NoNew/) { $returnval="NoNew"; }
}
close fd;
return($returnval);
}
checkOKState
Is the node already UP
sub checkOKState {
my $soap_response =
$LocalLBNode->get_availability
(
SOAP::Data->name ( node_def => $node_definition )
);
my $result = $soap_response->result;
print "Node $sNodeIP:$sNodePort availability: ";
if ( 0 == $result )
{
print "UNCHECKED\n";
}
elsif ( 1 == $result )
{
print "DOWN\n";
Bring back UP after failure
$LocalLBNode->set_state
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $STATE_ENABLED )
);
$LocalLBNode->set_availability
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $AVAILABILITY_UP )
)
}
elsif ( 2 == $result )
{
print "UP\n";
}
elsif ( 4 == $result )
{
print "FORCED DOWN\n";
Bring back UP after failure
$LocalLBNode->set_state
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $STATE_ENABLED )
);
$LocalLBNode->set_availability
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $AVAILABILITY_UP )
)
}
elsif ( 9 == $result )
{
print "DISABLED\n";
Bring back UP after NoNew
$LocalLBNode->set_state
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $STATE_ENABLED )
);
$LocalLBNode->set_availability
(
SOAP::Data->name ( node_defs => [$node_definition] ),
SOAP::Data->name ( state => $AVAILABILITY_UP )
)
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects