-
Notifications
You must be signed in to change notification settings - Fork 0
/
dd-events.py
41 lines (36 loc) · 1.3 KB
/
dd-events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python3
import os
import sys
import time
import subprocess
import logging
from datadog import initialize, api
class DDAGGREGATOR(object):
"""This class is used to pull alerts from DataDog and push them into a Kafka topic.
"""
def __init__(self):
self.options = {"api_key" : 'XXXXXXXXXXXX', \
'app_key':'XXXXXXXXXXXXX'}
initialize(**self.options)
@staticmethod
def prep_timing():
"""This function is used to set the time frame that events will be pulled from
datadog. Returns an object with 2 KV pairs, start_time:int() and end_time:int()
"""
end_time = time.time()
start_time = end_time - (60 * 60 * 24) #86400 = 1day
times = {"start_time": start_time, "end_time": end_time}
return times
def collect_events(self, times):
"""This function collects the datadog events for a time frame specified by the times
object. We pull the full list from the API then format the pieces we want, returning
a list.
"""
all_events = api.Event.query(start=times["start_time"], end=times["end_time"])
print(all_events)
DDA = DDAGGREGATOR()
while True:
TIMES = DDA.prep_timing()
EVENT_ARRAY = DDA.collect_events(TIMES)
print(EVENT_ARRAY)
time.sleep(5)