forked from grihey/atsd-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-availability.py
49 lines (37 loc) · 1.51 KB
/
data-availability.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
42
43
44
45
46
47
48
49
from atsd_client import connect, connect_url
from atsd_client.models import SeriesFilter, EntityFilter, DateFilter, SeriesQuery, ForecastFilter
from atsd_client.services import SeriesService
'''
Monitor data availability. The inputs stored in a data-availability.csv table.
'''
# Connect to ATSD server
#connection = connect('/path/to/connection.properties')
connection = connect_url('https://atsd_hostname:8443', 'username', 'password')
# Initialize services
svc = SeriesService(connection)
filename = 'data-availability.csv'
with open(filename) as fp:
line = fp.readline()
while line:
# skip commented lines
if line.startswith('#'):
line = fp.readline()
continue
metric_name, entity_name, interval, end_date, forecast_name, comments = line.split(',')
count, unit = interval.split('-')
sf = SeriesFilter(metric=metric_name)
ef = EntityFilter(entity=entity_name)
df = DateFilter(end_date=end_date, interval={'count': count, 'unit': unit})
ff = None
if forecast_name:
sf.set_type('FORECAST')
if forecast_name != '-':
ff = ForecastFilter(forecast_name=forecast_name)
query = SeriesQuery(series_filter=sf, entity_filter=ef, date_filter=df, forecast_filter=ff)
series = svc.query(query)
if series:
if not series[0].data:
print('No data for: %s' % line)
else:
print('Empty response for %s' % line)
line = fp.readline()