Yes, looking to determine number of usable nodes in a Pool, essentially how many nodes in a pool are UP and not disabled. This is how I am currently doing it, and it begs for a better method:
Routine for determining number of available nodes in a pool
Args: Pool Name
Returns: Number of available nodes in pool
sub AvailableNodesInPool() {
my $poolname = $_[0];
my $poolcnt = 0;
my $avail = 0;
my $enable = 0;
@tmshout = `/usr/bin/tmsh show ltm pool $poolname members`;
while ($line = shift(@tmshout)) {
skip the gobal pool info
if ($line =~ /^Pool\s+Member:\s+${poolname}\s+(.*)/) {
while ($line = shift(@tmshout)) {
Check for "Availability : available" & "State : enabled"
if ($line =~ /Availability\s+:\s+(.*)/) {
$availability = $1;
if ($debug) {print LOG "\n\tAvailability == $availability";}
if ($availability =~ /available/) {$avail = 1;}
} elsif ($line =~ /State\s+:\s+(.*)/) {
$state = $1;
if ($debug) {print LOG "\n\tState == $state";}
if ($state =~ /enabled/) {$enable = 1;}
} elsif ($line =~ /Reason/) {
Done parsing data for this node, determine status
if ($avail && $enable) {
$poolcnt++;
$avail = 0;
$enable = 0;
}
}
}
}
}
return $poolcnt;
}