Forum Discussion

Exploitation_Ca's avatar
Exploitation_Ca
Icon for Nimbostratus rankNimbostratus
Oct 23, 2013

IRULES - LB::reselect

Hello,

I want integrate this irule on my loadbalancer. But you can say me if this irule is totaly correct? Because I dont know how "lb::reselect" will react.

When my request arrive on my node, if my node send 500 error. I want mark this node as down. And i want that this request be sent to another node.

set poolname "TEST"
set fqdn "TEST.com"
set NbNode 2

when HTTP_REQUEST {
          if {[HTTP::host] equals $fqdn}
         {
                        pool $poolname
        }
}

when HTTP_RESPONSE {
        if{([HTTP::status] == 500) or ([HTTP::status] == 404) or ([HTTP::status] == 503)}
      {
               LB::reselect pool $poolname
                if{[active_members $poolname] > $NbNode}
                {
                      LB::down
                }
        }
}

thank.

10 Replies

  • OK, so, you may want to always specify the fqdn as lowercase and also lower what your matching against:

    if { [string tolower [HTTP::host]] equals $fqdn }
    

    I'd also reorder your logic as it's possible you'll mark the newly selected node as down:

    when HTTP_RESPONSE {
      if { ([HTTP::status] == 500) or ([HTTP::status] == 404) or ([HTTP::status] == 503) } {
        if { [active_members $poolname] > $NbNode } {
          LB::down
          LB::reselect pool $poolname
        }
        else {
          LB::reselect pool $poolname
        }
      }
    }
    

    I'm pretty sure you could shorten the HTTP::status lookup too but I'm too tired to try.

    Also not you don't have any spaces between your if's and the opening brace {.

  • I have testing this irule so i have three errors:

    What is the probléme, i can't create a variable in a irule? Or its not the right method?

    the error:

    01070151:3: Rule [/Common/irule_TEST] error:
    line 1: [command is not valid in the current scope] [set poolname "TEST"]
    line 2: [command is not valid in the current scope] [set fqdn "TEST.com"]
    line 3: [command is not valid in the current scope] [set NbNode 2]
    line 16: [command is not valid in current event context (HTTP_RESPONSE)][LB::reselect pool $poolname]
    

    the script:

    set poolname "TEST"
    set fqdn "TEST.com"
    set NbNode 2
    
    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] equals $fqdn }
        {
            pool $poolname
        }
    }
    
    when HTTP_RESPONSE {
      if { ([HTTP::status] == 500) or ([HTTP::status] == 404) or ([HTTP::status] == 503) } {
        if { [active_members $poolname] > $NbNode } {
          LB::down
          LB::reselect pool $poolname
        }
        else {
          LB::reselect pool $poolname
        }
      }
    }
    
  • hello,

     

    i can not used command "LB::reselect" in event "HTTP_RESPONSE"? A solution exist?

     

    Thank you

     

  • I seen in devcentral site.

    l can do?

    when HTTP_REQUEST {
        set poolname "TEST"
        set fqdn "TEST.com"
        set NbNode 2
        if { [string tolower [HTTP::host]] equals $fqdn }
        {
            set request_headers [HTTP::request]
            pool $poolname
        }
    }
    
    when HTTP_RESPONSE {
      if { ([HTTP::status] == 500) or ([HTTP::status] == 404) or ([HTTP::status] == 503) } {
        if { [active_members $poolname] > $NbNode } {
          LB::down
          HTTP::retry $request_headers
        }
        else {
          HTTP::retry $request_headers
        }
      }
    }
    
    • What_Lies_Bene1's avatar
      What_Lies_Bene1
      Icon for Cirrostratus rankCirrostratus
      That would work although I don't see the point of LB::down; this functionality should be performed by a monitor.
  • hello,

     

    When "lb::down" command is executed. Normaly on "network map" i can see my node is down or no?

     

    Because when my irule is active on my pool.

     

    All request is retry and i haven't error during my load test.

     

    But all node up on "network map". There is no down node

     

    My new code is correcte or no?

     

    when HTTP_REQUEST {
        set poolname "TEST"
        set fqdn "TEST.com"
        if { [string tolower [HTTP::host]] equals $fqdn }
        {
            set request_headers [HTTP::request]
            pool $poolname
        }
    }
    
    when HTTP_RESPONSE {
      set currentnode [LB::server addr]
      set portnumber "80"
      if { ([HTTP::status] == 500) or ([HTTP::status] == 404) or ([HTTP::status] == 503) }
         {
          LB::down pool $poolname member $currentnode $portnumber
          HTTP::retry $request_headers
          log "Server $poolname $currentnode $portnumber down!"
         }
    }

    thank you.

     

  • You are correct. The moment you execute the LB::down command this will trigger a health monitor for that probe and as that will be successful nothing will be marked down in the network map or elsewhere. As I said earlier this functionality should be performed by a monitor.