F5 BIG-IP Virtual Edition v11.4.1 (Build 635.0) LTM on ESXi
Via iControl API :
How to determine if a specific device is operating in active or standby mode for an active-standby sync-failover device-group ? For a floating traffic-group ?
Alternately, for device-group or traffic-group , how to determine active device ?
Here’s one from walkF5Stats that I wrote a few years back… There’s some additional bits in there that track elapsed time to call, logging etc. but the important part is the call to System/Failover and get_failover_state
Now that’s (below) only for a device. In v11 with traffic-groups it’s slightly different. Hold on a bit and I’ll see if I can dig that up (I wrote something a couple of months ago for that, just need to find it )
sub getFailoverState {
my ($dbh, $dev)=(@_);
my $t0=[gettimeofday];
my $devID=$dev->{ID};
my $devFQDN=$dev->{FQDN};
my $icServer=$dev->{MgmtAddr};
my $icPort=$dev->{MgmtPort};
dbprint "getFailoverState: cookiejar (Before)\n";
print Dumper($cookieJar);
my $Failover = SOAP::Lite
-> uri('urn:iControl:System/Failover')
-> proxy("$sProtocol://$icUser:$icPass\@$icServer:$icPort/iControl/iControlPortal.cgi", cookie_jar => $cookieJar);
-> proxy("$sProtocol://$icUser:$icPass\@$icServer:$icPort/iControl/iControlPortal.cgi"i,
$Failover->transport->cookie_jar($cookieJar);
dbprint "getFailoverState: Getting failover state for $devFQDN\n";
my $soapResponse = $Failover->get_failover_state();
dbprint "getFailoverState: cookiejar (After)\n";
print Dumper($cookieJar);
&checkResponse($soapResponse);
my $failoverState=$soapResponse->result;
dbprint "getFailoverState: state=$failoverState\n";
my $updatestr="update device set fostate='$failoverState' where id=$devID";
dbprint "getFailoverState: SQL [$updatestr]\n";
my $update=$dbh->prepare($updatestr);
$update->execute;
my $elapsed=tv_interval ( $t0 );
log_action($elapsed, 0, "getFailoverState", "$updatestr");
}
That’s the same call as above. But I’m not sure it has the detail that’s required if you run many traffic-groups. Does the details change if you have 10 traffic-groups active for example?
There’s another call in the v11 iControl that’s gets the status of the traffic-group itself. Saves parsing out any comment that may or may not be the same in a few versions time.
Sorry, can’t find my notes that I made from when I looked at this, but if you look in Management::TrafficGroup you should find what you need to determine where a traffic-group is currently living.
When calling Management.DeviceGroup.get_failover_status(), output shows the failover status per device with more detail, such as all active traffic-groups on that device. For example, the same call with 10 traffic groups. 1-5 are active on lb-01 and 6-10 are active on lb-02:
>>> print b1.Management.DeviceGroup.get_failover_status()
{'failover_status': 'HA_STATE_ACTIVE', 'color': 'COLOR_GREEN', 'status': 'ACTIVE', 'details': ['active for /Common/traffic-group-10', 'active for /Common/traffic-group-7', 'active for /Common/traffic-group-6', 'active for /Common/traffic-group-9', 'active for /Common/traffic-group-8'], 'summary': '5/10 active'}
>>> print b2.Management.DeviceGroup.get_failover_status()
{'failover_status': 'HA_STATE_ACTIVE', 'color': 'COLOR_GREEN', 'status': 'ACTIVE', 'details': ['active for /Common/traffic-group-1', 'active for /Common/traffic-group-3', 'active for /Common/traffic-group-4', 'active for /Common/traffic-group-2', 'active for /Common/traffic-group-5'], 'summary': '5/10 active'}