Ruby with the F5 BigIP API

Something i found kind of useful.
Original Instructions found on F5’s page:

I assume you’re running ubuntu or debian

1. Install Ruby Gems

apt-get install ruby rubygems libopenssl-ruby

2. Download iControl
iControl Ruby Gem

3. Install iControl gem

gem install f5-icontrol-10.2.0.gem

Run one of the example files (located in /var/lib/gems/1.8/gems/f5-icontrol-10.2.0.a.1/examples/ if installed as ‘root’)

ruby get_version.rb <f5address> <username> <pass>
=> BIG-IP_v10.1.0

And Lastly Here’s a little script to grab the Down/Disabled/Active Pool Members of a given pool
This was constructed with the help of some of the example scripts that installed with the icontrol gem.
Example usage:

f5-pool-members.rb -b bigIPAddress -u user -p pass -n poolname
    -b bigip-address,                BIGIP Load balancer address
    -u, --bigip-user bigip-user      Username of BIGIP admin
    -p, --bigip-pass bigip-pass      Password of BIGIP admin
    -n, --pool-name pool-name        Name of pool
    -h, --help                       Display this screen
#!/usr/bin/env ruby
# == Synopsis
# f5-node-initiator - Quickly add nodes to pools
# == Usage
# f5-node-initiator [OPTIONS]
# -h, --help:
#    show help
# --bigip-address, -b [hostname]:
#    specify the destination BIG-IP for virtual and pool creation
# --bigip-user, -u [username]:
#    username for destination BIG-IP
# --bigip-pass, -p [password]:
#    password for destination BIG-IP
# --pool-name, -n [name]:
#    name of pool to add node to
# --node-definition, -d [ip address:port]:
#    definition for node being added to pool, example:

require 'rubygems'
require 'f5-icontrol'
require 'optparse'

bigip_address = ''
bigip_user = ''
bigip_pass = ''
pool_name = ''
node_address = ''
node_port = 80

# Current script's name
currentFile = File.basename(__FILE__)

# IF options undefined set to help option
if ARGV.empty?
  ARGV[0] = '-h'

 # This hash will hold all of the options
 opt = {}
 optparse = do |opts|
   # Set a banner, displayed at the top of help screen
   opts.banner = "#{currentFile} -b bigIPAddress -u user -p pass -n poolname"

   # Define the options, and what they do
   opts.on( '-b', '--bigip-address bigip-address', 'BIGIP Load balancer address' ) do |x|
     bigip_address = x
   opts.on( '-u', '--bigip-user bigip-user', 'Username of BIGIP admin' ) do |x|
     bigip_user = x
   opts.on( '-p', '--bigip-pass bigip-pass', 'Password of BIGIP admin' ) do |x|
     bigip_pass = x
   opts.on( '-n', '--pool-name pool-name', 'Name of pool' ) do |x|
     pool_name = x
   #opts.on( '-d', '--node-definition node-definition', 'definition for node being added to pool, example:' ) do |x|
   #  node_definition = x

   # This displays the help screen
   opts.on( '-h', '--help', 'Display this screen' ) do
     puts opts
     exit 1

# Parse Command options

# Initiate SOAP RPC connection to BIG-IP
bigip =, bigip_user, bigip_pass, ['LocalLB.Pool']).get_interfaces

# Insure that target pool exists
unless bigip['LocalLB.Pool'].get_list.include? pool_name
  puts 'ERROR: target pool "' + pool_name +'" does not exist'
  exit 1

ActiveMembers =
DisabledMembers =
DownMembers =

bigip['LocalLB.Pool'].get_monitor_instance([ pool_name ])[0].collect do |pool_member1|
  node_addr = pool_member1['instance']['instance_definition']['ipport']['address'].to_s
  node_port = pool_member1['instance']['instance_definition']['ipport']['port'].to_s
  if pool_member1['instance_state'].to_s =~ /INSTANCE_STATE_DOWN/
    DownMembers.push node_addr
  elsif pool_member1['enabled_state'].to_s =~ /false/
    DisabledMembers.push node_addr
    ActiveMembers.push node_addr
  #puts "Node: #{node_addr}:#{node_port}"
  #puts "Node Health: #{pool_member1['instance_state']}"
  #puts "Enabled State: #{pool_member1['enabled_state']}"

puts "Poolname: " + pool_name
puts "=============== Unhealthy State Nodes ================"
DownMembers.each do |x|
  puts x
puts "=============== Disabled State Nodes ================"
DisabledMembers.each do |x|
  puts x
puts "=============== Active and Healthy State Nodes ================"
ActiveMembers.each do |x|
  puts x

Example Output:

Poolname: myf5_pool
=============== Unhealthy State Nodes ================
=============== Disabled State Nodes ================
=============== Active and Healthy State Nodes ================

F5 Loadbalancers – getting active members list from a pool

This wasn’t my original way of querying them but to my surprise F5 created something already.
Download iControl

$ cd iControl-11.1.0 2/sdk/samples/soap/perl/soaplite/LocalLB
$ ./
Usage: host port uid pwd [pool_name]