The following code uses Stingray's RESTful API to list all the pools defined for a cluster and for each pool it lists the nodes defined for that pool, including draining and disabled nodes. The code is written in PHP and uses STMRESTClient. This example builds on the previous listpools.php example. This program does a GET request for the list of pool and then while looping through the list of pools, a GET is done for each pool to retrieve the configuration parameters for that pool.
listpoolnodes.php
<?php # Display a list of all nodes in all pools require_once 'stmrestclient.inc'; print("<html><body>\n<br><b>Pools:</b><br>\n"); try { $client = new STMRestClient(); $response = $client->get('pools'); $pools = $response->children; foreach ($pools as $pool) { $poolName = $pool->name; $poolConfig = $client->get("pools/$poolName"); $nodes = $poolConfig->properties->basic->nodes; $draining = $poolConfig->properties->basic->draining; $disabled = $poolConfig->properties->basic->disabled; print("<br>Pool: $poolName<br>\n"); print ' Nodes: '; foreach ($nodes as $node) { print "$node "; } print "\n"; if (count($draining)) { print ' Draining Nodes: '; foreach ($draining as $node) { print "$node "; } print "<br>\n"; } if (count($disabled)) { print ' Disabled Nodes: '; foreach ($disabled as $node) { print "$node "; } print "<br>\n"; } print "<br>\n"; } } catch (exception $e) { print ("Error: " . $e->getMessage()); } print("</body></html>\n"); ?>
Running the example
This code was tested with PHP 5.3.3 and uses the STMRestClient class that can be found here: Tech Tip: A Stingray Traffic Manager REST Client for PHP
To run this program, Make it available via a web server and the output should be:
Pools:
Pool1
Nodes: 192.168.1.100 192.168.1.101
Draining: 192.168.1.101
Disabled: 192.168.1.102
Pool2
Nodes: 192.168.1.103 192.168.1.104
Read More