Forum Discussion

Adam_Metzler_13's avatar
Adam_Metzler_13
Icon for Nimbostratus rankNimbostratus
Mar 17, 2015

Can an iRule perform an action if a data group list is empty

I have two iRules that I would like to compile into one if possible.

 

The primary iRule sends all traffic to a different pool and rewrites the uri to an unplanned maintenance page if all the primary pool members are offline/down.

 

The second iRule allows a list of IP addresses to access the web resource, while sending all other traffic to a planned maintenance page. This iRule is used when planned maintenance occurs and the IP list will be different every time.

 

My question is; Is it possible to perform an action if a data group is empty?

 

The idea being:

 

  1. If the group is empty AND the pool members are up, traffic goes to the normal pool and page
  2. If the group is empty AND the pool members are down, traffic goes to the unplanned pool and page
  3. If the group has IP addresses AND the pool members are up, the IPs in the group go to the normal pool and page and everyone else goes to the planned pool and page.
  4. If the group has IP addresses AND the pool members are down, everyone goes to the planned pool and page (404 for the IPs in the group is fine in this scenario)

Thanks for your help!

 

4 Replies

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    From your question is sounds like you already have the two iRules but you are looking for a way to check the number of items in a class.

    [class size className]
    returns the number of items.

    Is that what you're looking for?

  • Maybe! I'll have to test it.

    I do have the two iRules, but would like to combine them. Additionally, one of the iRules (the iRule with the list) currently doesn't use a data group list and I would like to make the new rule use one.

    The question then is; can I do

    if{[class size classname] < 1} and !{[active_members planned_pool] > 1} and !{class match [IP::client_addr] equals $::classname]}
    pool planned

  • kunjan's avatar
    kunjan
    Icon for Nimbostratus rankNimbostratus

    It works if the datagroup is empty. If you are datagroup using external file, it seems it can't be empty. at least a dummy "," is required.

     

  • This is what I ended up with. It works well, but I feel it could be much more optimized. This is my first attempt at iRule creation so I'm sure I'm missing some simple optimizations...

     

     

    Apologies for the image. I couldn't get the code uploaded.

     

    Thanks very much for your help.