Advanced Search
HomeTechnical DocumentsTipsTivoliEnterprise Console › TEC Rules Based on Time

TEC Rules Based on Time

A few years ago I wrote a complex prolog rule to act on an event based on the time of day, however it wasn't until very recently that I revisited the subject after a person on the Tivoli mailing list and also an Orb Data customer both simultaneously asked how to do this.

Thankfully in TEC 3.7, 3.8 and 3.9 the solution is much simpler than the one I worked on and this short tip supplies and explains the finished solution.

Predicates

As I mentioned earlier the later versions of TEC supplies a number of rule predicates for manipulating time value. In this tip I will mention two of them:

get_local_time
The predicate get_local_time returns a value into the argument _time. The _time variable must be empty (un-instantiated) at execution.

get_local_time(_time)

The time returned is not epoch time; instead it is time structure that can be interrogated by other predicates

resolve_time
The resolve_time predicate turns this time structure (represented by the _time variable returned from the get_local_time predicate) into more readable format including hours, minutes etc. This then allows you to compare the current time/date with your range of "acceptable hours".

resolve_time(_time, _seconds, _minutes, _hours, _day_of_month, _month, _year, _day_of_week, _day_of_year, _daylight_saving)

_time must be set before calling resolve_time and the other arguments must be free.

The values will be in Greenwich Mean Time (GMT).

Most values return values as would be expected using a 24 hour clock (e.g hours return a value from 0 to 23 and minutes returns a value from 0 to 59) however the following exceptions should be noted:

  • The days of the week are returned as a value from 0 to 6 where 0 is Sunday, 1 and 6 is Saturday.
  • The day of the year returns an integer in the range 0-364.
  • The year returns an integer in the range 00-99
  • The Month returns an integer in the range 0-11.
  • Daylight saving returns an integer as reflected by the DST_ macros in <sys/time.h>. You can use this number to determine the type of daylight savings time style used on the current system. This could be useful if you need to manipulate time values returned by this predicate.

The following example shows the values from a Solaris system:

Return ValueCodeDescription
0DST_NONEnot on dst
1DST_USAUSA style dst
2DST_AUSTAustralian style dst
3DST_WETWestern European dst
4DST_METMiddle European dst
5DST_EETEastern European dst
6DST_CANCanada
7DST_GBGreat Britain and Eire
8DST_RUMRomania
9DST_TURTurkey
10DST_AUSTALTAustralian style with

Sample Rule

Now the predicates have been explained the rule is not that difficult. The example we will create is a rule that drops all events that do not arrive between Monday and Friday, 9am to 5pm.

The flow diagram below describes the event flow through the rule however essentially the rule does the following:

  • Acts on all events (event: event of_class class)
  • Gets the local time (get_local_time(_time))
  • Turns it into its component parts (resolve_time(_time, _sec, _min , _hour, _dom, _mon ,_year, _dow, _doy, _dst))
  • Tests if the day of the week (_dow) and the hour (_hour) meet the criteria for acceptable events.
  • If Yes then commit the action (commit_action)
  • Otherwise drop the event. (drop_received_event)





The complete rule listing is shown below.

Open in New Window
rule
out_of_hours
  ( 
     
event_event of_class _class,
  
reception_action
  ( 
     
get_local_time(_time),     
        
resolve_time(_time_sec_min_hour_dom_mon_year_dow_doy_dst),
        
_dow >= 1
        
_dow =< 5
        
_hour >= 9
        
_hour =< 17
        
commit_action 
), 
reception_action
(         
         
drop_received_event 
  

).  
?>