Forum Discussion

Anthony_Hatch_3's avatar
Anthony_Hatch_3
Icon for Nimbostratus rankNimbostratus
Mar 27, 2011

External class and class command

I recently came across the 2009 iRule Winner by Chetan Bhatt, Click Here, and wanted to implement it on our v10.2.0 LTMs. I have modified the cron job to write the external class file in the appropriate format and modified the iRule to use class commands instead of scanning each line.

 

The problem is that, my output will only show the last member of each pool. For example, if there are three entries in the class like shown below, the iRule will only output the last. So if there are 10 pools, all with 3 members, I will only get 10 entries in the output rather than 30. Additionally, when I check the size of the class using class size class_name, I would get 10 as the return value.

 

"test_http-pool" := "1.1.1.1:http",

 

"test_http-pool" := "2.2.2.2:http",

 

"test_http-pool" := "3.3.3.3:http",

 

 

Here is the cron change I made to query for all pools all members and write out the class file:

 

b pool all member all | grep POOL | awk '{print "\""$3"\","}' | sed -e 's/\//\" \:\= \"/g' | sort >/var/class/pool_member_status_list.class

 

Is the problem in using duplicates of a single name even when each of their value pairings are unique?

 

Here are the main changes to the iRule:

 

when HTTP_REQUEST {

 

...

...

 

for {set i 0} {$i < [class size pool_member_status_list]} {incr i} {

if { [catch {

 

set poolname [class element -name $i pool_member_status_list]

 

set addrport [class element -value $i pool_member_status_list]

 

scan [split $addrport ":"] %s%s addr port

 

switch -glob [LB::status node $addr] {

 

...

 

...

 

}

 

} errmsg] } {

 

...

 

...

 

}

 

}

 

}

 

 

Thanks in advance for any assistance, and for providing a great resource!

 

Anthony

7 Replies

  • Hi Anthony,

     

     

    On a test unit running 10.2.1 this command returns the correct number of pool members:

     

     

    b pool all member all | grep POOL | awk '{print "\""$3"\","}' | sed -e 's/\//\" \:\= \"/g' | sort

     

     

    What does it show on your LTM?

     

     

    Aaron
  • Thanks for the response Aaron! This works as I intended and outputs correctly. The problem isn't actually with that command, but with how the class commands are processing the contents of the class file that is output from that command. I was actually just in the process of posting an update when you replied. üôÇ

    It looks like the problem may be that all keys that are output from the command are not unique. Therefore when I run commands like class size class_name, I get a result that identifies the number of unique keys and not the total number of keys as I had originally intended. As a possible resolution, I was thinking of modifying the command to output each key (poolname) uniquely and then stripping out the unique identifier during iRule processing. An example output might instead look something like this:

    
    "test_http-pool_1" := "1.1.1.1:http",
    "test_http-pool_2" := "2.2.2.2:http",
    "test_http-pool_3" := "3.3.3.3:http",
    

    Is my thinking correct on this?
  • I just realized something that I had completely missed before. I could probably cut out much of the code from the iRule by not using the switch statements to test against the result of the LB::status commands for each pool member. I hadn't noticed that the b pool all member all command actually gives the status of the pool member. So if I change up how the class file gets written when the cron job is run, I can get the pool name, pool member, service port, and status all at once and just use the iRule to parse the data out properly. An an example of the command to get the output would now look like:

     

     

    b pool all member all | grep POOL | awk '{print "\""$3"\""" \:\= ""\""$4"\""","}' | sort

     

     

    With the resulting output now in the format of:

     

     

    "test_http-pool/172.20.75.151:http" := "active,up",

     

    "test_http-pool/172.20.75.152:http" := "active,up",

     

    "test_http-pool/172.20.75.153:http" := "active,up",

     

     

    This solves the original issue of the keys having to all be unique and allows for a shorter iRule. I'll try and post the finished iRule once I have it completed.
  • My initial testing looks good. I no longer run into any issues relating to the size of the class.
  • I guess I should have done some more research into some of the things I was trying to do. Hadn't even noticed this great article Click Here!
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    I'm glad to see you found a solution. Let us know if you've got any more questions.

     

     

    Colin
  • Very nicely done folks. Trying to look at the pool members that are displayed and display them as their DNS name or possibly editing the code to display only the last two octets (if IP)? Have any ideas? I'm not very handy with the awk command, so any help would be appreciated... Thanks