Forum Discussion

Tim_Moomaw_9220's avatar
Tim_Moomaw_9220
Icon for Nimbostratus rankNimbostratus
Nov 09, 2008

Scheduled 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 from DevCentral which work great except for any period of time that includes an 08 or 09. The log entries clearly indicate that it's having an issue with non-octal numbers being returned but I can't figure out how to get around it. I'm betting it's something hugely simple. Suggestions welcomed. Here's the rule as it's written now and the error that is received at 0208, 0209, 0308, 0309,08xx, 09xx etc. Thanks in advance.

 

 

when HTTP_REQUEST {

 

Change the following to set schedule

 

set start_time "0200";

 

set end_time "0600";

 

set day "Saturday";

 

 

set l [split [clock format [clock seconds] -format {%A %H %M}] " "]

 

set cur_day [lindex $l 0]

 

set cur_time [expr [expr {[lindex $l 1] *100}] + [lindex $l 2]]

 

if { ($cur_day eq $day) &&

 

($cur_time >= $start_time) &&

 

($cur_time <= $end_time) } {

 

HTTP::respond ----text here----

 

 

 

 

TCL error: m-window-test HTTP_REQUEST - cant use invalid octal number as operand of * while executing expr {[lindex $l 1] *100}

 

 

Also receive this error:

 

 

TCL error: m-window-test HTTP_REQUEST - expected integer but got 08 looks like invalid octal number while executing expr [expr {[lindex $l 1] *100}] + [lindex $l 2]]

 

 

 

 

29 Replies

  • How do you update the timezone... the clock commands don't ever seem to relate to the timezone I have set on the F5.
  • This should pull the local time from the device locally and format it into HH:MM:SS.

     

     

    [clock format [clock seconds] -format {%H:%M:%S}]
  • Thanks Aaron this rule worked fine on my 11.1 BigIP, except for this little error: you typed static::start_end instead of static::end_date in the 11th line.

    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::start_end]
    }
    when CLIENT_ACCEPTED {
    
        Save the current time in seconds since the epoch
       set now [clock seconds]
    
        Use the maintenance pool if we're in the maintenance window
       if {$now > $static::start and $now < $static::end}{
          pool MAINT-POOL
       }
    }
    

    Once corrected, it does the trick pretty well, even when using an european timezone

    Regards !

  • Hi Cyril,

     

     

    Thanks for catching that. I updated my original post as well.

     

     

    Aaron
  • Thanks to you for this usefull code ! As you are here I wanted to know what is, according to you, the benefit of using static variables in the Rule_Init section instead of guenuine variables in the client_accepted section ?

     

     

  • It's more efficient to convert the dates to UTC once in RULE_INIT and save them to static variables compared with doing that conversion to UTC on every connection.

     

     

    Aaron
  • Guess as I am not an expert here what is the output\function of this iRule? What should I see and to what do I apply this rule too? Thanks for all the Excellent Info.

     

    • Kevin_Stewart's avatar
      Kevin_Stewart
      Icon for Employee rankEmployee

      Assuming you're talking about the last submission from Cyril, the iRule would be placed on the application VIP. You'd need a separate pool containing some static "We're under maintenance" webpage, so that when users make a request to the site within the start and end times defined, the request will be sent (pooled) to this static resource which will return the maintenance page.