cancel
Showing results for 
Search instead for 
Did you mean: 

TrafficScript: Disabling a node/pool when it fails

mithadriel
Not applicable

TrafficScript: Disabling a node/pool when it fails

Submitting this for community use. It's a TrafficScript - pretty ugly and in a very early stage but it does what I need it to do and others might find it useful

Big thanks to Riverbed Support for helping me get the REST API enabled as I spent ages trying to figure out why that wasn't working only to discover it was a menu option (doh!).

The requirement was pretty specific, we're dealing with an application which can handle a failover to a secondary node, but can't handle failing back. So we're not using the Stingray as a load balancer in this case, more as a clever failover utility. The client didn't want the Stingray failing back to the primary node/pool once it was fixed and the Stingray doesn't support no-failback as a default option so we had to revert to a TrafficScript to do what we wanted. Hopefully the code is pretty clear, but if there are any questions or indeed suggestions on how to improve it further let me know!


################################################################################


# Script Name:   killSwitch


# Author:        Johnathan Williamson


# Version:       0.1 Alpha


# Disclaimer:    Not recommended for production use, YMMV !


# Description    This rule disables the primary pools node on initial failure.


#


# The rule runs on every page load.


#


# It uses the subroutines in the stmrestclient rule


################################################################################






import stmrestclient;




## First we pull the current state of each pool. This helps us determine what to do next.


$ActivePool = pool.checknode("ActivePool","192.168.60.11",80);


$SecondaryPool = pool.checknode("SecondaryPool","192.168.60.12",80);




$accept = "application/json";


$resource = "pools/ActivePool";




# If a pool is dead, it indicates all nodes inside it have stopped responding


if ($ActivePool == "DEAD") {


   # Get current pool config and set node to disabled


   $response = stmrestclient.stmRestGet($resource, $accept);


   if ($response["rc"] == 1) {


      $poolConfig = $response["data"];


      $poolConfig["properties"]["basic"]["disabled"] = ["192.168.60.11:80"];


      # The following line results in a few moans in the logs about missing node config, but also means no double node entries in the GUI


      #$poolConfig["properties"]["basic"]["nodes"] = [];


   }




   # Now we've got our disabled node in the poolConfig ... submit it for action


   $response = stmrestclient.stmRestPut($resource, $accept, $poolConfig);


   if ($response["rc"] == 0) {


      log.warn ("CUSTOM TRAFFIC SCRIPT FAILURE - : " . lang.dump($poolConfig));


   }


 


} else if ( $ActivePool == "DISABLED" ) {


   # Secondary failover kicks in automatically


}








## Some debug stuff


#log.warn("Primary pool is " . $ActivePool);


#log.warn("Secondary pool is " . $SecondaryPool$);


#log.info ("disabled nodes are " . lang.dump($poolConfig["properties"]["basic"]["disabled"]));


#log.info ("active nodes are " . lang.dump($poolConfig["properties"]["basic"]["nodes"]));


#log.info ("full hash looks like: " . lang.dump($poolConfig));



1 REPLY 1
ebrandsberg
New Contributor

Re: TrafficScript: Disabling a node/pool when it fails

Another approach that rolls the disabling into the monitor itself is available at Disabling a server when it goes offline