Difference between revisions of "Transforms Tip: Transforms Based on Time"

From Zenoss Wiki
Jump to: navigation, search
 
Line 19: Line 19:
 
The following are the values which can be accessed:
 
The following are the values which can be accessed:
  
Current Year:    time.localtime()[0]
+
* Current Year:    time.localtime()[0]
Current Month:    time.localtime()[1]
+
* Current Month:    time.localtime()[1]
Current Day:      time.localtime()[2]
+
* Current Day:      time.localtime()[2]
Current Hour:    time.localtime()[3]
+
* Current Hour:    time.localtime()[3]
Current Minute:  time.localtime()[4]
+
* Current Minute:  time.localtime()[4]
Current Second:  time.localtime()[5]
+
* Current Second:  time.localtime()[5]
Current Day of Week: time.localtime()[6]
+
* Current Day of Week: time.localtime()[6]
  
 
Day of the week index:  
 
Day of the week index:  
  
0: Monday
+
* 0: Monday
1: Tuesday
+
* 1: Tuesday
2: Wednesday
+
* 2: Wednesday
3: Thursday
+
* 3: Thursday
4: Friday
+
* 4: Friday
5: Saturday
+
* 5: Saturday
6: Sunday
+
* 6: Sunday
  
 
[[Category:Tips]]
 
[[Category:Tips]]
 
[[Category:Transforms]]
 
[[Category:Transforms]]

Latest revision as of 18:45, 20 February 2015

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