Forum Discussion

Ross_Fitheridge's avatar
Ross_Fitheridge
Icon for Nimbostratus rankNimbostratus
Jul 13, 2007

increment pointer in array

I am trying to redirect to one of any hosts, to give some form of basic load balancing, like round robin, otherwise it goes to the default pool.

 

 

I guess I need an array and a pointer to increment each time the redirect gets executed, and I want it to go back to the top of the array once it has reached the bottom. What I have written to give you the gist is:

 

 

when RULE_INIT {

 

list of hosts to redirect to sequentially

 

set ibewebserver [ list \

 

"ww1" \

 

"ww2" \

 

"ww3" \

 

]

 

}

 

when HTTP_REQUEST {

 

 

if { [findstr [HTTP::uri] "/" 1 "/"] equals "oldwebsite" } {

 

set $ibewebserver + 1

 

HTTP::redirect https://$ibewebserver.acme.com[HTTP::uri]

 

}

 

}

 

 

Another problem I have with this iRule is matching case, the "oldwebsite" sometimes is in uppercase, mixed case, and I keep finding oddities.

 

 

It seems really simple and I feel ashamed to ask, but I'm not a programmer, and looking through the forum and references I have not seen anything quite like it. I know I am way off the trail, but you will make a novice very happy.

 

 

RossF

1 Reply

  • thanks Joe,

     

    I made it slightly to simple for you. My hostnames, are just random names. The uri, is actually what I am testing on. Not sure if its optimal but it works. I just need to think about how to deal with the remote hosts being off-line.

     

     

    when RULE_INIT {

     

    list of hosts to redirect to sequentially

     

    set ::HOSTNAME [list \

     

    pluto \

     

    saturn \

     

    ]

     

    set number of hosts as in list.

     

    set ::HOST_NUM [llength $::HOSTNAME]

     

     

    set number of hosts one less than in list, why? list index starts at zero.

     

    incr ::HOST_NUM -1

     

    initialize a global variable with index 0

     

    set ::REDIR_NUM 0

     

    }

     

    when HTTP_REQUEST {

     

     

    Send to Content only available on Redbus www.acme.de direct to server

     

     

    Jobs

     

    if { [findstr [string tolower [HTTP::uri] ] "/acmeonline/de/" 15 "/"] equals "jobs.nsf" } {

     

    if global index is greater than hostnum, reset it to zero

     

    if { $::REDIR_NUM > $::HOST_NUM } {

     

    set ::REDIR_NUM 0

     

    }

     

    HTTP::redirect https://[lindex $::HOSTNAME $::REDIR_NUM].rent-at-acme.com[HTTP::uri]

     

    increment the global index

     

    incr ::REDIR_NUM

     

     

    RetroClaim

     

    } elseif { [findstr [string tolower [HTTP::uri] ] "/acmeonline/" 12 "/"] equals "retroclaim.nsf" } {

     

    if global index is greater than hostnum, reset it to zero

     

    if { $::REDIR_NUM > $::HOST_NUM } {

     

    set ::REDIR_NUM 0

     

    }

     

    HTTP::redirect https://[lindex $::HOSTNAME $::REDIR_NUM].rent-at-acme.com[HTTP::uri]

     

    increment the global index

     

    incr ::REDIR_NUM

     

     

    Send www.acme.de to the Proxy Cache virtual servers.

     

    } elseif { [HTTP::host] equals "www.acme.de"} {

     

    snat none

     

    pool Cache_Server_Pool

     

    ......some additonal conditions................

     

    If there is anything else left then send to default.

     

    }

     

    }