F5 Sites
  • F5.com
  • LearnF5
  • NGINX
  • MyF5
  • Partner Central
Contact
  • Under Attack?
  • F5 Support
  • DevCentral Support
  • F5 Sales
  • NGINX Sales
  • F5 Professional Services
Skip to contentBrand Logo
Forums
CrowdSRC
Articles
Groups
EventsSuggestionsHow Do I...?
RegisterSign In
  1. DevCentral
  2. Articles
  3. Technical Articles

iRule Maintenance Windows

A fun, but not well known, feature on BIG-IP is the Statistics Profile. This tech tip is the second in a series on how the Statistics Profile and iRules, when working together, can save time, product...
Published Apr 10, 2007
Version 1.0
automation
BIG-IP
dev
management
monitoring
news
tech tip
virtualization
Joe_Pruitt's avatar
Joe_Pruitt
Joined September 22, 2004
View Profile
Joe_Pruitt's avatar
Joe_Pruitt
Joined September 22, 2004
View Profile
DeVon_Jarvis's avatar
DeVon_Jarvis
Icon for Altostratus rankAltostratus
Nov 23, 2008
In my "modified" version, I had dropped the leading zeros to force numeric comparisons, thinking these would be faster. I have added back the leading zeros and you are right, string comparisons work just fine.

 

 

Here is my finished solution. I wanted only fixed outage windows, but wanted to allow more than one, so you will see the start and end times are in an array. I also optimozed the rule by only checking for the outage condition every n (currently 60) seconds. This made a huge difference on performance.

 

 

Let me know if you have any suggestions on how to improve it!

 

 

when RULE_INIT {

 

day 1=mon 7=sun, Times are HHMM with leading zeros!

 

These are list of day, start, end time for multiple outage windows

 

set ::day {7}

 

set ::start_time {0700}

 

set ::end_time {0900}

 

check_interval is in seconds

 

set ::check_interval 60

 

working variables

 

set ::check_time 0

 

set ::in_outage_window 0

 

}

 

 

when HTTP_REQUEST timing on {

 

Use the TCL "clock" command to get the current time settings.

 

set now [clock seconds]

 

if { $now >= $::check_time } {

 

set ::check_time [expr $now + $::check_interval]

 

set raw_time [clock format $now -format {%u %H %M}]

 

set raw_time [split [clock format [clock seconds] -format {%u %H %M}] " "]

 

set cur_day [lindex $raw_time 0]

 

set cur_time "[lindex $raw_time 1][lindex $raw_time 2]"

 

set temp_outage_window 0

 

foreach dayidx $::day startidx $::start_time endidx $::end_time {

 

if { ($cur_day eq $dayidx) &&

 

($cur_time >= $startidx) &&

 

($cur_time < $endidx) } {

 

set temp_outage_window 1

 

log local0. "In outage"

 

}

 

}

 

if {$temp_outage_window != $::in_outage_window } {

 

set ::in_outage_window $temp_outage_window

 

if {$temp_outage_window == 0} {

 

log local0. "End of outage"

 

} else {

 

log local0. "Start of outage"

 

}

 

}

 

}

 

if { $::in_outage_window} {

 

HTTP::respond 307 Location http://www.mysite.com/maintenance.html

 

return 0

 

}

 

}

ABOUT DEVCENTRAL

DevCentral NewsTechnical ForumTechnical ArticlesTechnical CrowdSRCCommunity GuidelinesDevCentral EULAGet a Developer Lab LicenseBecome a DevCentral MVP

RESOURCES

Product DocumentationWhite PapersGlossaryCustomer StoriesWebinarsFree Online CoursesF5 CertificationLearnF5 Training

SUPPORT

Manage SubscriptionsProfessional ServicesProfessional ServicesCreate a Service RequestSoftware DownloadsSupport Portal

PARTNERS

Find a Reseller PartnerTechnology AlliancesBecome an F5 PartnerLogin to Partner Central

F5 logo©2024 F5, Inc. All rights reserved.
TrademarksPoliciesPrivacyCalifornia PrivacyDo Not Sell My Personal Information