Transforms Tip: Transforms Based on Time

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

In some cases, you may want to have certain actions kick off based on the time that the event comes in. Here are some quick examples of how you could do this...

In the following example, we want to drop an event for the device named "ottawa" between 3am and 4am:

import timeif evt.device == 'ottawa':
    if time.localtime()[3] >= 3 and time.localtime()[3] < 4:
        evt._action = 'drop'

If we wanted to do the same thing, but for 3pm to 4pm we would do:

import timeif evt.device == 'ottawa':
    if time.localtime()[3] >= 15 and time.localtime()[3] < 16:
        evt._action = 'drop'

The following are the values which can be accessed:

  • Current Year: time.localtime()[0]
  • Current Month: time.localtime()[1]
  • Current Day: time.localtime()[2]
  • Current Hour: time.localtime()[3]
  • Current Minute: time.localtime()[4]
  • Current Second: time.localtime()[5]
  • Current Day of Week: time.localtime()[6]

Day of the week index:

  • 0: Monday
  • 1: Tuesday
  • 2: Wednesday
  • 3: Thursday
  • 4: Friday
  • 5: Saturday
  • 6: Sunday