Time based iRule example
Problem this snippet solves:
Here's a simple example of taking action in an iRule based on a time window. We use the clock scan and clock seconds commands to convert a timestamp in a user-friendly format to UTC (time since the Unix epoch of 0.0.1970) and check it against the current time.
Tcl clock wiki page: http://www.tcl.tk/man/tcl8.4/TclCmd/clock.htm
Contribution
Hoolio plus help with others in the forums
Code :
when RULE_INIT { # Start of maintenance window in YYYY-mm-dd HH:MM format set static::start_date "2011-05-29 18:45" # End of maintenance window in YYYY-mm-dd HH:MM format set static::end_date "2011-05-29 18:50" # Convert start/end times to seconds from the epoch for easier date comparisons set static::start [clock scan $static::start_date] set static::end [clock scan $static::end_date] } when CLIENT_ACCEPTED { # Get the current time in seconds since the Unix epoch of 0-0-1970 set now [clock seconds] # Check if the current time is between the start and end times if {$now > $static::start and $now < $static::end}{ pool MAINT_POOL } # Default action is to use the virtual server default pool }
Published Mar 18, 2015
Version 1.0hooleylist
Cirrostratus
Joined September 08, 2005
hooleylist
Cirrostratus
Joined September 08, 2005
- Brad_146558Nimbostratus
Great iRule!
One question though, let's say we would want to use this multiple days in a row at the same time, how would you wildcard the date?
- Brad_146558Nimbostratus
If anyone else was wondering the same thing, there is a solution in the article below.
 
https://devcentral.f5.com/s/feed/0D51T00006i7elZSAQ
 
- jgsec_333386Nimbostratus
Great job! Really useful!
- NickTurnerAltostratus
Exactly what i was after - thanks!