Forum Discussion

4 Replies

  • I don't think you can selectively have the rule or not, the rule's presence against a virtual server is determined at load time. You can however, use time and date to determine on whether or not your commands fire.

    
    when RULE_INIT {
      set off_hours 0
      set ::time_min [clock scan {10:00}]
      set ::time_max [clock scan {17:00}]
    }  
    when CLIENT_ACCEPTED {
      set current_day [clock format [clock seconds] -format {%a} ]
      set current_time [clock seconds]
      if {($current_day == {Sat}) or ($current_day == {Sun})} {
        set off_hours 1
      } elseif {($current_time < $::time_min) or ($current_time > $::time_max)} {
        set off_hours 1
      }
    }
    when HTTP_REQUEST {
      if { !$off_hours} {
        log local0. "Work Hours...processing event commands."
      } else { log local0. "Off Hours...exit event." }
    }
    when HTTP_RESPONSE {
      if { !$off_hours} {
        log local0. "Work Hours...processing event commands."
      } else { log local0. "Off Hours...exit event." }
    } 

    When first running this rule, I set the time min to 08:00, and the logs showed:

    Dec 12 09:54:19 tmm tmm[9977]: Rule time_based : Work Hours...processing event commands.

    Dec 12 09:54:19 tmm tmm[9977]: Rule time_based : Work Hours...processing event commands.

    I then updated the time_min to 10:00, and the logs showed:

    Dec 12 09:58:41 tmm tmm[9977]: Rule time_based : Off Hours...exit event.

    Dec 12 09:58:41 tmm tmm[9977]: Rule time_based : Off Hours...exit event.

    This configuration modified from the excellent contribution from Deathbywedgie here:

    http://devcentral.f5.com/default.aspx?tabid=53&view=topic&forumid=5&postid=8008Click here
  • Another alternative would be to write an iControl script to add/remove the iRule from your virtual(s) at the desired times.
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    citizen_elah is correct here. There is currently no way to indicate an execution time for your iRule as a whole, just portions from within the iRule itself.

     

     

    HTH,

     

    Colin