Forum Discussion

DFresh4130_2492's avatar
DFresh4130_2492
Icon for Nimbostratus rankNimbostratus
Apr 10, 2012

Script to identify if unit is active or standby

Hi All,

 

 

I currently have basic operator privileges to our F5 systems. I haven't worked with F5s much in the past and have never written scripts to interact with them before.

 

 

I'm basically trying to get a script going that will return whether the F5 is currently active or standby. I tried the obvious non-programmer route first with wget, but no luck. Can someone point me to a doc that will give me the basic overview on how to get a script working that'll just login and perform what function I want on system status? Thanks

 

4 Replies

  • Hi,

     

     

    What is your overall goal? If you're trying to programmatically modify the BIG-IP configuration you can use the iControl API. If you always want to connect to the active unit in an HA pair, you can connect to a floating self IP address.

     

     

    For details on iControl, see this index:

     

    https://devcentral.f5.com/wiki/iControl.HomePage.ashx

     

     

    Aaron
  • My goal is to enhance our current deploy script. When we deploy new code to our tomcat/jboss instances our script will invoke some java code to disable a member from the pool, deploy the code and bounce then enable the member again. Rinse and repeat. Our F5 host value is hardcoded in the shell script and I would like to make the script include a check to see if the primary is currently the active F5.

     

     

    I was hoping there would be a way to just include a wget or something without having to go further and use the API.

     

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    Some code from a past project...

     

     

    
    sub activeUnit {
      my ($FailoverAPI, $icServer)=@_;
    
      print "activeUnit:\n";
      my $soapResponse = $FailoverAPI->get_failover_state();
      my($status,$text)=&checkResponse($soapResponse);
      if(($status!=1)||($text ne "OK")) {
        print "activeUnit: status $status error [$text] from get_failover_state()\n";
        return;
      }
      print "activeUnit: status $status success [$text] from get_failover_state()\n";
      print Dumper($soapResponse->result);
    
      $fostate=$soapResponse->result;
      print "activeUnit: status $status fostate [$fostate] from get_failover_state()\n";
    
      return ($fostate eq "FAILOVER_STATE_ACTIVE");
    }
    
    

     

     

    H
  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    And also to sync from the current unit to the peer...

    
    sub syncConfig {
      my($configAPI, $synctype)=@_;
    
      print "syncConfig:\n";
      my $soapResponse = $configAPI->synchronize_configuration(SOAP::Data->name(sync_flag => $synctype));
      my($status,$text)=&checkResponse($soapResponse);
      if(($status!=1)||($text ne "OK")) {
        print "syncConfig: status $status error [$text] from synchronize_configuration($synctype)\n";
        return;
      }
      print "syncConfig: status $status success [$text] from synchronize_configuration($synctype)\n";
    
      print "syncConfig:\n";
    }
    
    

    H