iRule Maintenance Windows
A fun, but not well known, feature on BIG-IP is the Statistics Profile. This tech tip is the second in a series on how the Statistics Profile and iRules, when working together, can save time, product...
Published Apr 10, 2007
Version 1.0DeVon_Jarvis
Nov 23, 2008Nimbostratus
In my "modified" version, I had dropped the leading zeros to force numeric comparisons, thinking these would be faster. I have added back the leading zeros and you are right, string comparisons work just fine.
Here is my finished solution. I wanted only fixed outage windows, but wanted to allow more than one, so you will see the start and end times are in an array. I also optimozed the rule by only checking for the outage condition every n (currently 60) seconds. This made a huge difference on performance.
Let me know if you have any suggestions on how to improve it!
when RULE_INIT {
day 1=mon 7=sun, Times are HHMM with leading zeros!
These are list of day, start, end time for multiple outage windows
set ::day {7}
set ::start_time {0700}
set ::end_time {0900}
check_interval is in seconds
set ::check_interval 60
working variables
set ::check_time 0
set ::in_outage_window 0
}
when HTTP_REQUEST timing on {
Use the TCL "clock" command to get the current time settings.
set now [clock seconds]
if { $now >= $::check_time } {
set ::check_time [expr $now + $::check_interval]
set raw_time [clock format $now -format {%u %H %M}]
set raw_time [split [clock format [clock seconds] -format {%u %H %M}] " "]
set cur_day [lindex $raw_time 0]
set cur_time "[lindex $raw_time 1][lindex $raw_time 2]"
set temp_outage_window 0
foreach dayidx $::day startidx $::start_time endidx $::end_time {
if { ($cur_day eq $dayidx) &&
($cur_time >= $startidx) &&
($cur_time < $endidx) } {
set temp_outage_window 1
log local0. "In outage"
}
}
if {$temp_outage_window != $::in_outage_window } {
set ::in_outage_window $temp_outage_window
if {$temp_outage_window == 0} {
log local0. "End of outage"
} else {
log local0. "Start of outage"
}
}
}
if { $::in_outage_window} {
HTTP::respond 307 Location http://www.mysite.com/maintenance.html
return 0
}
}