Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Time based iRule question

Brad_146558
Nimbostratus
Nimbostratus

Hi everyone,

I'm writing an iRule that triggers a daily maintenance page. I'm trying to get this page to come up between two certain time periods each and every day. I used an iRule I'd found in an article from hoolio as I'd never done a time based iRule before. I'm running into an error that I posted just below the iRule. I'm thinking that I'm receiving this because I don't have the appropriate wild cards in for the dates. Any help would be appreciated! 😃

    when RULE_INIT {

    Start of maintenance window in YYYY-mm-dd HH:MM format
   set static::start_date "11:00"

    End of maintenance window in YYYY-mm-dd HH:MM format
   set static::end_date "5:00"

    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 my_maintenance_pool
   }
    Default action is to use the virtual server default pool
}

 - can't read "static::end": no such variable     while executing "if {$now >$static::start and $now < $static::end}{       pool my_maintenance_pool    }"

2 REPLIES 2

Vijay_E
Cirrus
Cirrus

Check out the iRule provided by Joe here.

 

Stanislas_Piro2
Cumulonimbus
Cumulonimbus

Hi,

look at this irule to change action based on time and week day:

https://devcentral.f5.com/questions/irule-to-block-access-of-vs-on-specific-days

clock scan commands must not be executed in RULE_INIT event if only hour is set. it will convert hour from the day you last loaded the irule.

if today, you load the irule with set

static::start [clock scan "5:00"]
, it will not work for next days but only for today.

If you want for every days, use a variable in CLIENT_ACCEPTED and not a static variable in RULE_INIT