Forum Discussion

BaltoStar_12467's avatar
Feb 24, 2015

BIG-IP : determine active device

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 ?

 

8 Replies

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    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");
    
    }
    
  • shaggy's avatar
    shaggy
    Icon for Nimbostratus rankNimbostratus

    I was able to get v11 failover-state using 'Management.DeviceGroup.get_failover_status()' (https://devcentral.f5.com/wiki/iControl.Management__DeviceGroup__get_failover_status.ashx)

    Not sure what language you use, but the python commands are:

    Python 2.7.6
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import bigsuds
    >>> import getpass
    >>> nameuse = raw_input('user: ')
    user: admin
    >>> passuse = getpass.getpass()
    Password: xxxxxxx
    >>> b1 = bigsuds.BIGIP(hostname = "lb-01.test.com",username = nameuse,password = passuse)
    >>> b2 = bigsuds.BIGIP(hostname = "lb-02.test.com",username = nameuse,password = passuse)
    >>> print b1.Management.DeviceGroup.get_failover_status()
    {'failover_status': 'HA_STATE_STANDBY', 'color': 'COLOR_GRAY', 'status': 'STANDBY', 'details': [], 'summary': '1/1 standby'}
    >>> print b2.Management.DeviceGroup.get_failover_status()
    {'failover_status': 'HA_STATE_ACTIVE', 'color': 'COLOR_GREEN', 'status': 'ACTIVE', 'details': ['active for /Common/traffic-group-1'], 'summary': '1/1 active'}
    
  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    Hi shaggy.

     

    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.

     

  • shaggy's avatar
    shaggy
    Icon for Nimbostratus rankNimbostratus

    Hi Hamish,

    Your script uses System.Failover.get_failover_state() - https://devcentral.f5.com/wiki/iControl.System__Failover__get_failover_state.ashx. Calling that against my test HA pair (both units are active for different traffic-groups) shows:

    >>> print b1.System.Failover.get_failover_state()
    FAILOVER_STATE_ACTIVE
    
    >>> print b2.System.Failover.get_failover_state()
    FAILOVER_STATE_ACTIVE
    

    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'}
    

    I do not see anything that shows where a specified traffic-group is active - I was looking under Management.TrafficGroup (https://devcentral.f5.com/wiki/iControl.Management__TrafficGroup.ashx) but only saw calls for configuration details

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    Hmm... I'm sure I used to have a script that would show the state from the traffic-group POV... i.e. given a traffic group, find where it was active...

     

    Let me see if I can dig one out...

     

    H

     

  • When using a REST API call of

    /mgmt/tm/cm/failover-status?$select=details
    to both devices in a sync-failover device group you can expect results as follows:

    Unit being active for traffic-group-1 and traffic-group-2:

    {
      "entries": {
        "https://localhost/mgmt/tm/cm/failover-status/0": {
          "nestedStats": {
            "entries": {
              "https://localhost/mgmt/tm/cm/failoverStatus/0/details": {
                "nestedStats": {
                  "entries": {
                    "https://localhost/mgmt/tm/cm/failoverStatus/0/details/0": {
                      "nestedStats": {
                        "entries": {
                          "details": {
                            "description": "active for /Common/traffic-group-1"
                          }
                        }
                      }
                    },
                    "https://localhost/mgmt/tm/cm/failoverStatus/0/details/1": {
                      "nestedStats": {
                        "entries": {
                          "details": {
                            "description": "active for /Common/traffic-group-2"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    Unit being standby for traffic-group-1 and traffic-group-2:

      "entries": {
        "https://localhost/mgmt/tm/cm/failover-status/0": {
          "nestedStats": {
            "entries": {}
          }
        }
      }
    }
    

    Tested on TMOS v12.1.2 via BIG-IQ REST API proxy to a device service cluster of 2 BIG-IP VE.

  • In addition to my previous response the following approach looks better to me.

    Make a call via GET to
    /mgmt/tm/cm/traffic-group/traffic-group-1/stats?$select=deviceName,failoverState
    to one of the units in your sync-failover BIG-IP device service clusters in order to receive the following response:
    {
      "entries": {
        "https://localhost/mgmt/tm/cm/traffic-group/traffic-group-1/~Common~traffic-group-1:~Common~bigip61.lb-net.bit/stats": {
          "nestedStats": {
            "entries": {
              "deviceName": {
                "description": "/Common/bigip61.lb-net.bit"
              },
              "failoverState": {
                "description": "standby"
              }
            }
          }
        },
        "https://localhost/mgmt/tm/cm/traffic-group/traffic-group-1/~Common~traffic-group-1:~Common~bigip62.lb-net.bit/stats": {
          "nestedStats": {
            "entries": {
              "deviceName": {
                "description": "/Common/bigip62.lb-net.bit"
              },
              "failoverState": {
                "description": "active"
              }
            }
          }
        }
      }
    }
    
  • I know its an old thread but incase someone still looking, though above answers are also correct

    >>> state = mgmt.tm.cm.devices.get_collection()
    >>> print state[0].failoverState
    active