Forum Discussion

Mike_62127's avatar
Mike_62127
Icon for Nimbostratus rankNimbostratus
Mar 13, 2018

iRule catch all - to redirect if no pool selected

Hi

 

I have multiple VS's setup (~150) that use an iRule to select the appropriate pool based on host header (no default pool assigned in VS config), this is working fine.

 

I have been tasked with writing an iRule to serve up a sorry page when pool members == 0. This is also working fine.

 

My issue is that my syslog server is getting pounded with TCL errors since I applied the sorry_page iRule

 

TCL error: /Common/sorry_page_iRule - no such pool: (line 21) invoked from within "active_members [LB::server pool]"

 

I added a Debug logging rule and found that the majority of the TCL errors are due to pool selection trying to select the Virtual Server IP Address as the pool.

 

This of course triggers the TCL "no such pool" error because I do not name my pools with IP addresses.

 

I would like to add a "catch all" in the sorry_page iRule that "if no pool selected or no such pool / redirect to ;

 

Here are the two iRules I have applied to the multiple Virtual Servers -

 

Pool_Selection_iRule:

 

when HTTP_REQUEST {        
 HTTP::host [string tolower [HTTP::host]]
 set PoolName "[HTTP::host]_pool"
 if { [catch { pool $PoolName}] } {
} else { 
pool $PoolName
}
`

Sorry_Page_iRule:
`when LB_FAILED {
    log -noname "[virtual name] DEBUG: Server Pool: $PoolName SELECTED"
    if { [active_members [LB::server pool]] == 0 } {
    log -noname "Sorry Page Activated / Server Pool: $PoolName selection failed on  connection attempt from [IP::client_addr]"
    HTTP::respond 503 content {
    
    **a bunch of HTML code here**
    
    
}

Any help would be greatly appreciated.

 

  • You can change your irules like that

    Pool_Selection_iRule:

    when HTTP_REQUEST {        
        HTTP::host [string tolower [HTTP::host]]
        catch { pool  "[HTTP::host]_pool"}
    }
    

    Sorry_Page_iRule:

    when HTTP_REQUEST priority 900 {        
        set dpool [LB::server pool]
        if { $dpool equals "" } { HTTP::redirect "http://sorry_page.com" ; unset dpool; return}
        if { [active_members $dpool] == 0 } { HTTP::redirect "http://sorry_page.com"; unset dpool; return}
        unset dpool
    }
    
    when LB_FAILED {
        log -noname "[virtual name] DEBUG: Server Pool: $PoolName SELECTED"
        if { [active_members [LB::server pool]] == 0 } {
        log -noname "Sorry Page Activated / Server Pool: $PoolName selection failed on  connection attempt from [IP::client_addr]"
        HTTP::redirect "http://sorry_page.com"
    }