Forum Discussion

James_Flood_401's avatar
James_Flood_401
Icon for Nimbostratus rankNimbostratus
Jun 26, 2007

Maintenance iRule Issue

I'm trying to use the iRule below to allow some of our web server developers be able to up and down a single node in a pool via simple input to a uri. I used the Maintenance iRule that was recently mailed in an F5 Tech Tip as my basis but seem to have something buggy in my coding someplace. My web_maintenance statistics profile has a single field of "hostname" (minus quotes). The only parts that actually appear to return any data are the "/disable*" without any additional input after, and the "/usage". Any input is appreciated..thanks in advance.

 

 

when HTTP_REQUEST {

 

set TITLE "Web Maintenance"

 

set PROFILE_NAME "web_maintenance"

 

 

switch -glob [string tolower [HTTP::uri]] {

 

"/disable*" {

 

 

set params [split [HTTP::uri] "/"]

 

if { [llength $params] < 3} {

 

HTTP::respond 200 content "

 

$TITLE

 

Usage: http://[HTTP::host]/disable/host

 

"

 

} else {

 

 

STATS::set $PROFILE_NAME "hostname" [lindex $params 2]

 

HTTP::respond 200 content "

 

$TITLE

 

Maintenance host is downed

 

"

 

}

 

}

 

 

"/enable" {

 

 

STATS::set $PROFILE_NAME "hostname" 0

 

HTTP::respond 200 content "

 

$TITLE

 

All Hosts enabled

 

"

 

}

 

 

"/check" {

 

 

set downhost [STATS::get $PROFILE_NAME "hostname"]

 

HTTP::respond 200 content "

 

$TITLE

 

Currently $downhost is down for maintenance

 

"

 

}

 

 

"/usage" {

 

 

HTTP::respond 200 content "

 

$TITLE

 

Usage: http://[HTTP::host]/\[command\]

 

/disable/host - down host /enable - enable all hosts /check - check downed hosts /usage - display this message

 

 

"

 

}

 

 

default {

 

 

set hostdown [STATS::get $PROFILE_NAME "hostname"]

 

 

if {$hostdown eq "web1"} {

 

use node 192.168.0.1 80

 

} elseif { $hostdown eq "web2" } {

 

use node 192.168.0.2 80

 

} else {

 

use pool http_192_168_0.p }

 

}

 

}

 

}
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    It looks like the only two cases in the switch that are returning results are those that don't use the STATS:: commands. Are you getting any info in your /var/log/ltm file that shows an issue when trying to execute those commands?

     

     

    The syntax looks fine from what I can see. I'd recommend checking your log, and if nothing's there, start adding some log lines in each case to see if they're matching, and then going from there.

     

     

    Colin
  • Just wanted to give everyone a follow up. First I explicitly used the profile name in each instance where it was referenced to get away from setting the variable. Second I removed the double quotes when setting or getting the value from my statistics profile.

     

     

    After doing that combination of two this maintenance iRule works great!!