Pool_Member_Status_Page_on_a_Virtual_Server (Topic Changed)

Hi,

I am trying to use this from windows command line: DevCentral - An F5 Technical Community. I have python installed on the server. I saved the syntax/usage section to a file called check.py and modified host, user and password. I saved the main script to a file called pool_status.py. I am calling check.py from comand line and I get:

C:\Python27>c:\scripts\check.py

Traceback (most recent call last):

File “c:\scripts\check.py”, line 1, in

import pycontrol.pyControl as pyControl

ImportError: No module named pycontrol.pyControl

I have never ran a python script before, so perhaps I am doing somehting wrong. Any help would be great.

Thanks.

EDIT:

I am now going another route based on a recommendation by Jason Rahm

Working on trying to get this to work, but having issues (See further down in the topic)

Hi,

I don’t have much experience with pycontrol, but I guess that’s because you don’t have a path for python set or you don’t have the pycontrol.pycontrol file saved in the library directory. I think the path to python is expected from your environment variables:

!/bin/env python

On an LTM, this shows:

/bin/env python

Python 2.4.3 (1, Oct 18 2010, 11:25:41)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

>>>

If that’s not working on the host you’re running the script from, try setting the path explicitly in the script. You could also try copying the pycontrol.pycontrol file to your current directory.

Here are a few related links:

http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7

http://devcentral.f5.com/Default.aspx?tabid=53&aft=86059

http://stackoverflow.com/questions/1756721/what-is-causing-importerror-no-module-named-pkg-resources-after-upgrade-of-pytho

Aaron

that script is pycontrol v1. Don’t go there… üôÇ

First, you need to install the pycontrol module available here: http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/4/aff/2108/showtab/groupforums/Default.aspx Click Here

Next, you need to use this updated version below. Note that the host, username, password, and a valid pool in the second function call in main (mine below is testpool) will need to reflect your environment. The reason the pool name has to be passed as a list is a limitation in the zip python method. If you don’t pass as a list, the pool name will only be stored as the first character of the pool name.

!/usr/bin/python

def show_all_pools_status(obj):

        ''' Show the status of all pools '''
        try: 
                pools  = obj.get_list()
                status = obj.get_object_status(pool_names = pools)
        except:
                "Unable to fetch pool list or get status - check trace log" 

        combined = zip(pools, status)
        
        for x in combined:
                print "Pool: ", x[0]
                print "\t",     x[1].availability_status
                print "\t",     x[1].enabled_status
                print "\t",     x[1].status_description
                print "\n"*2

def show_pool_status(obj, pool_name = None):
        ''' show the status of a single pool '''
        status = obj.get_object_status(pool_names = [pool_name])
        combined = zip(pool_name, status)
        for x in combined:
                print "Pool: ", x[0]
                print "\t",     x[1].availability_status
                print "\t",     x[1].enabled_status
                print "\t",     x[1].status_description
                print "\n"*2

        
if __name__ == "__main__":

        import pycontrol.pycontrol as pc
        
        Setup connection
        host = '10.10.20.5'
uname = 'admin'
upass = 'admin'
        
        b = pc.BIGIP(
                 hostname = host, 
                 username   = uname, 
                 password   = upass, 
 fromurl = True,
                 wsdls = ['LocalLB.Pool']
                )

        p  = b.LocalLB.Pool

        print "Fetching pool info...\n"
        show_all_pools_status(p)

print "Fetching pool X info...\n"
show_pool_status(p, ['testpool'])

Thanks for your help. I still cannot seem to get this to work. Just to confirm, I don’t need to install anything on the load balancers themselves correct? I am basically needing somehting to show me the node status of all the nodes in every pool (we have 20 or so) without having to look at the poolstatus page on the F5. So somehting that exports to an html file, or something would work. I wanted to see what this looked like as it seemed to be close to what i needed, but not sure.

no, the script should run from a remote machine (though it’s possible to install pycontrol on your ltm: (Click Here)

This doesn’t have to be done with iControl…can be done with an iRule as well:

http://devcentral.f5.com/wiki/default.aspx/iRules/Pool\_Member\_Status\_Page\_on\_a\_Virtual\_Server.html Click Here

Wow, that sounds like it is exactly what I need (iRule version). I will try this. My only question is, once setup, how do you view the page? I did not see instructions for that in the link.

Thanks for your help!

I am having an issue with setting this up. On step 3, it mentions setting up the iRule. I do this, and then create the .class file in the class folder. When I try to click finsih, it gives me :The string class external file (/var/class/pool_member_status_list.class) has n invalid format, line: 1. It then deletes the file from that location.

Any thoughts?

are you on v10+? If so, you need this one:

http://devcentral.f5.com/wiki/default.aspx/iRules/Pool\_\_Member\_\_Status\_\_Page\_on\_a\_\_Virtual\_\_Server\_v10.html Click Here

Nope, I am on 9.4.8.

what does your class look like?

Posted By Jason Rahm on 06/17/2011 12:05 PM

what does your class look like?

I think this is what you want.

I have the code below in this path:/var/class/pool_member_status_list.class

when HTTP_REQUEST { if { [HTTP::uri] eq “/status” } { set response “BIGIP Pool Member Status - \ [clock format [clock seconds]]BIGIP Pool Member Status - [clock format [clock seconds]]\ StatusPool NameMemberPort” foreach { selectedpool } $::pool_member_status_list { if { [catch { scan $selectedpool {%[^/]/%[^:]:%s} poolname addr port switch -glob [LB::status pool $poolname member $addr $port] { “up” { append response “UP\ [string tolower $poolname]$addr$port” } “down” { append response “DOWN\ [string tolower $poolname]$addr$port” } “session_enabled” { append response “ENABLED\ [string tolower $poolname]$addr$port” } “session_disabled” { append response “DISABLED\ [string tolower $poolname]$addr$port” } Default { append response “INVALID\ [string tolower $poolname]$addr$port” } } SWITCH END } errmsg] } { append response “INVALID\ [string tolower $poolname]$addr$port” } } append response “” HTTP::respond 200 content $response “Content-Type” “text/html” “Cache-Control” “no-cache, must-revalidate” “Expires” “Mon, 26 Jul 1997 05:00:00 GMT” } if { [HTTP::uri] eq “/rss” } { set response " \ BigIP Server Pool StatusServer Pool Status \ en[clock format [clock seconds]]\60" foreach { selectedpool } $::pool_member_status_list { if { [catch { scan $selectedpool {%[^/]/%[^:]:%s} poolname addr port switch -glob [LB::status pool $poolname member $addr $port] { “up” { append response “[string tolower $poolname] Status \ Member $addr:$port is UP” } “down” { append response “[string tolower $poolname] Status \ Member $addr:$port is DOWN” } “session_enabled” { append response “[string tolower $poolname] Status \ Member $addr:$port is ENABLED” } “session_disabled” { append response “[string tolower $poolname] Status \ Member $addr:$port is DISABLED” } Default { append response “[string tolower $poolname] Status \ Member $addr:$port is INVALID” } } SWITCH END } errmsg] } { append response “[string tolower $poolname] StatusMember $addr:$port is \ INVALID” } } append response “” HTTP::respond 200 content $response “Content-Type” “text/xml” “Cache-Control” “no-cache, must-revalidate” “Expires” “Mon, 26 Jul 1997 05:00:00 GMT” } }

no, this won’t work. What you’ve done is place the iRule in the class. An external class is a file where items of like functionality are stored, like a list of urls, or in this cass, a list of pool members. The iRule should be saved either in the GUI in the iRules text window, or in the bigip.conf file in the appropriate partition, or via the iRule editor. The iRule references the class, it isn’t stored in the class.

I see. So then what exaclty is in that .class file? Is that populated by the BigIP as I add the iRUle to their pool HTTP monitors? I did not see anything defined in the link for that unless I messed it.

Ok, now I have an iRule defined with the code above, and an empty .class file. I am not sure what needs to be done next. I am also not exaclty sure how I access the page externally, or even what the URL would be (I assume the first part would be the BIGIP Manageement Page URL)

Getting closer! The .class file was populated by the BIGIP. I have assinged the iRule to one of my virtual servers… Now the question is how do I view this information externally? I assume it must be an html page of some kind…

You can access the virtual server in a browser. If the VS IP is publicly accessible now, you may want to restrict access to trusted hosts/networks either upstream or in the iRule itself.

Aaron

So you are saying that the way I view the status externally is just to go to the VIP IP? I understood this has being a holistic view of all of the Pool status’s on the BIGIP, and not just one at a time?

Thanks!

Nope… :slight_smile: Create a new virtual server that’s just for getting status of all of the pools and add this iRule to it. It will loop through and get status for all of the pools.

Aaron

Posted By hoolio on 06/17/2011 02:10 PM

Nope… :slight_smile: Create a new virtual server that’s just for getting status of all of the pools and add this iRule to it. It will loop through and get status for all of the pools.

Aaron

Oh!!! :slight_smile: Well that makes more sense!! Any other configuration needed for this Virtual Server? I have created, but for some reason I cannot connect. THe IP was responding with Ping right when I created it, then it went back to timing out. THis is just a virtual server with an IP assigned and no Pool. I am using http and the default HTTP Profile.

Avaiablbility is currently unknown (enabled) so it should work.