Forum Discussion
Kevin_Davies_40
Oct 12, 2010Nacreous
Was bored today and this looked interesting... hope it helps.
F5 maintenance windows
Maintenance windows are specified in a string datagroup called maintenance_windows,
entries are space delimited in the following format, time is 24 hour.
HH:MM HH:MM Mon [Wed] [Sat] [Any]
Example would be
9:00 10:00 Mon Wed Fri
23:00 1:00 Any
If you want a custom site down web page from your web server then create a node for the server
in the maintenance pool and setup the /status page on your webserver.
when HTTP_REQUEST {
set data_source "maintenance_windows"
set maint_pool "maintenance"
current epoc time
set cur_time [clock seconds]
current day
set cur_day [string tolower [clock format $cur_time -format "%a"]]
foreach maint_window [class names $data_source] {
scan [string tolower $maint_window] {%s %s %[^:]} min_time max_time maint_days
log local0.debug "cur day $cur_day min $min_time max $max_time days $maint_days"
convert time to epoc
set min_time [clock scan $min_time]
set max_time [clock scan $max_time]
if {$max_time < $min_time} { set max_time [clock scan "tomorrow" -base $max_time] }
is it the right day?
set groundhog_day 0
if {$maint_days eq "any"} {
set groundhog_day 1
} else {
if {$maint_days contains $cur_day} {
set groundhog_day 1
}
}
if {$groundhog_day eq 0} { continue }
is it the right time?
if {$cur_time < $min_time} { continue }
if {$cur_time > $max_time} { continue }
if we got this far then we are in a maintenance window
if {[active_nodes $maint_pool] > 0} {
HTTP::uri "/status"
pool $maint_pool
} else {
HTTP::respond 200 content "Site is down for maintenance"
}
return
}
}
Note: I did have html tags around the 200 content above but this forum affects them so they were removed. If anyone can tell me the correct html tags I should be using to display iRule code I would appreciate it. Note editing does not display well in IE (esp preview mode). Should I be using a different browser?
Regards
Jarvil