For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

pyControl Node Alert

Problem this snippet solves:

Synopsis: This code will iterate over a list of pools and populate a webpage listing down nodes only, per pool. You'll need Python2.5, cgi, and a webserver to get this all done. Apart of the main code is a blacklist program which allows you to edit a list of pools you wouldn't otherwise want to monitor.*

How to use this snippet:

Installation

  • Copy contents of cgi-bin and www files to their respective places.
  • Apache will need to be configured for CGI, with .py extensions enabled.
    • The apache2 user, (www-data) will need read/write perms to black.list in the www directory.
  • Both blacklist.py and nodeAlert.py will need to be configured. You'll want to add username/password (readonly is plenty) and the IP of your f5 to each respective script.
  • You'll need to add your own bar.png and orangex.png

nodeAlert.cgi

Code :

#!/usr/bin/python2.5

import os, sys
from time import asctime
from socket import gethostbyaddr
import pycontrol.pyControl as pyControl

#################
# David C. Isom #
# RR Bowker LLC #
# August 2008   #
########################
#    BIG IP CONFIG     #
host = '123.4.56.789'  #
username = 'readonly'  #
password = 'readonly'  #
########################

print "Content-Type: text/html\n"
print
print "F5 Status\n"
print ""
print "F5 Node Status  -",asctime(),""
print "Blacklist"

# these get cached on the box anyway(linux)   
def nslook(ip):
        try: 
                output = gethostbyaddr(ip)
                return output[0]
        except: 
                output = "Host_Name_Not_Found" 
                return output

def blackcheck(poolName):
        blackFile = open("/var/www/black.list", "r")
        while True:
                line = blackFile.readline()[:-1]
                if len(line) == 0:
                        break
                if str(line) == str(poolName):
                        return True
        blackFile.close()

# Create object and bitbucket the wsdl messages
sys.stdout = open(os.devnull, "w")
b = pyControl.BIGIP(
        hostname = host, 
        username   = username, 
        password   = password, 
        wsdl_files = ['LocalLB.Pool', 'LocalLB.PoolMember']
        )
sys.stdout = sys.__stdout__ 

# quick object recreation
p = b.LocalLB_Pool
m = b.LocalLB_PoolMember

# get work done
poolDown = 0 
poolList = p.get_list()['return']
status = m.get_monitor_status(pool_names = poolList)['return']
combined = zip(poolList, status)
for x in combined:
   
   # Check the blacklist
   if blackcheck(str(x[0])) == True:
      continue

   incr = len(x[1])
   while incr > 0:
      currentStatus = x[1][incr - 1]['monitor_status']
      if currentStatus == "MONITOR_STATUS_DOWN":
         address = x[1][incr - 1]['member']['address'] 
         hostName = nslook(address)
         if poolDown == 0:
            print ""

         print ""

         poolDown = 1

      incr -= 1

   if poolDown == 1:
      poolDown = 0
      print "
"+x[0]+"
"+address+" "+hostName+"
" print ""
Published Mar 09, 2015
Version 1.0
No CommentsBe the first to comment