Forum Discussion
Tim_Moomaw_9220
Nimbostratus
18 years agoScheduled Maintenance Window
--- Obligatory "I'm new to iRules" ----
I'm trying to create a rule to return a maintenance page every Saturday morning between 0200 and 0600. I have copied a few examples ...
hoolio
Cirrostratus
18 years agoWhen you use 'clock format' using %k (without the leading zero for the hour field) it pads single digit hours with a space. This extra space generates an empty list element when passed to split and causes the TCL error about a null length string.
Rule snippet showing the problem:
log local0. "Clock output: [clock format [clock seconds] -format {%A %k %M}], \$k: $k"
set k [split [clock format [clock seconds] -format {%A %k %M}] " "]
log local0. "\$k split output llength: [llength $k]"
Log output:
Clock output: Thursday 9 05, $k: Thursday {} 9 05
$k split output llength: 4
Rule snippet:
log local0. "Clock output: [clock format [clock seconds] -format {%A %H %M}], \$H: $H"
set H [split [clock format [clock seconds] -format {%A %H %M}] " "]
log local0. "\$H split output llength: [llength $H]"
Log output:
Clock output: Thursday 09 05, $H: Thursday 09 05
$H split output llength: 3
You can work around this by using scan to parse the day, hour and minute regardless of the spaces:
Get time in seconds, formatted as day of week (%A) hour (%k) minute (%M)
Use scan to save output as $cur_day $cur_hour $cur_minute
scan [clock format [clock seconds] -format {%A %k %M}] {%s %d %d} cur_day cur_hour cur_minute
set cur_time ${cur_hour}${cur_minute}
So this example should work. In a simple test if the cur_time is 600 the comparison 600 >= 0600 is true. Though I haven't tested the rule completely.
when HTTP_REQUEST {
Change the following to set schedule
set maintenance_start_time "0200";
set maintenance_end_time "0600";
set maintenance_day "Saturday";
Get time in seconds, formatted as day of week (%A) hour (%k) minute (%M)
Use scan to save output as $cur_day $cur_hour $cur_minute
scan [clock format [clock seconds] -format {%A %k %M}] {%s %d %d} cur_day cur_hour cur_minute
set cur_time ${cur_hour}${cur_minute}
log local0. "\$cur_day: $cur_day, \$cur_hour: $cur_hour, \$cur_minute: $cur_minute, \$cur_time: $cur_time"
if { ($cur_day eq $maintenance_day) &&
($cur_time >= $maintenance_start_time) &&
($cur_time <= $maintenance_end_time) } {
HTTP::respond "Maintenance message"
log local0. "Maintenance message"
}
}
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects