cancel
Showing results for 
Search instead for 
Did you mean: 

Select different pool based on specific date or point in time

SOLVED
Highlighted
New Contributor

Select different pool based on specific date or point in time

I'm wondering if it is possible to select a different pool based on a specific date or point in time. For instance when you supply an array with dates accompanied with start- and stop times, will it be possible to use a different pool than the default one for a particular virtual server?

The reason for asking is that a team of administrators will begin doing scheduled maintenance on a set of known dates in a year, in the maintenance window. For reasons that don't need further explanation, my team is responsible for web traffic and thus in control of the Stingray Traffic Manager and no-one outside our team has access to the STM. Without having to manually select a different pool in the STM, we'd like to provide a TrafficScript that uses an array with predefined dates to automatically select a maintenance pool, so that users are not affected by maintenance word and the administrators can go about and do their business.

Any ideas, tips, or better yet, TrafficScripts lying around and willing to share?

Thanks in advance

3 REPLIES
Contributor

Re: Select different pool based on specific date or point in time

Hi Dennis,

This is fairly easy to do in TrafficScript using the sys.time() and associated functions which are described starting on page 110 of the TrafficScript Guide.  Here is some rough TrafficScript pseudo code:

# Maintenance window start and stop times

$maintenance_window_start = ["Fri, 25 Jan 2013 17:00 GMT", "Fri, 15 Feb2013 17:00 GMT"];

$maintenance_window_end= ["Sat, 26 Jan 2013 17:00 GMT", "Fri, 15 Feb2013 17:00 GMT"];

# Get the current time

$current_time = sys.time();

$windows = array.length($maintenance_window_start);

for ($i = 0; $i < $windows; $i++) {

    # Convert to unix time formats

    $start = string.gmtime.parse($maintenance_window_start[$i]);

    $end= string.gmtime.parse($maintenance_window_end[$i]);

    # if we are within the maintenance window use the Maintenance Pool

    if ( ($start < $current_time) && ($current_time < $end)) {

       pool.select("Maintenance Pool");

    }

}

# Fall through and use configured pool

So basically we're just iterating through start and stop times and selecting a maintenance pool if we are within a maintenance window.  Hope this helps.

Thanks,

Faisal

New Contributor

Re: Select different pool based on specific date or point in time

Hi Faisal,

thank you for your example. I had some extra time to spare and with an example in the TrafficScript reference guide I  came up with this:

# $hourofday: maintenance hours are between 10pm and 12pm

$hourofday = sys.time.hour();

# $datestring is printed as a string like YYYYmmdd

$datestring = sys.localtime.format("%Y%m%d");

# To cast a string to an integer, perform an evaluation

$today = $datestring + 0;

# Fixed set of days in a year for maintenance, supplied as integer

$maintenance_days = [ 20130103, 20130110, 20130117, "and so on" ];

$begin = 22;

$end = 24;

if (array.contains($maintenance_days, $today)) {

   if (!($hourofday < $begin || $hourofday >= $end))

      pool.use("POOL-Sorry");

   }

}


The begin and end time are always the same, as is agreed with the business. The maintenance days are always predefined each year, so it's basically a "set and forget for a year". This script worked fine last night. It's another example, but with the same result.


Thanks,

Dennis

Contributor

Re: Select different pool based on specific date or point in time

Dennis,

That looks good.

Faisal