forked from grihey/atsd-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_messages.py
39 lines (31 loc) · 1.4 KB
/
export_messages.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
from __future__ import print_function
from __future__ import unicode_literals
from atsd_client import connect, connect_url
from atsd_client.models import EntityFilter, DateFilter, MessageQuery
from atsd_client.services import MessageService
from atsd_client.utils import print_tags
'''
Export messages from ATSD into CSV-file using specified start_date, end_date, type, source and entity.
'''
# Connect to ATSD server
#connection = connect('/path/to/connection.properties')
connection = connect_url('https://atsd_hostname:8443', 'username', 'password')
# set export parameters
start_date = "2018-05-01T00:00:00Z"
end_date = "now"
type = "logger"
source = "com.axibase.tsd.service.search.searchserviceimpl"
entity = "7eacbc4723ed"
message_service = MessageService(connection)
ef = EntityFilter(entity=entity)
df = DateFilter(start_date=start_date, end_date=end_date)
query = MessageQuery(entity_filter=ef, date_filter=df, type=type, source=source)
messages = message_service.query(query)
with open('export.csv', 'w') as f:
print('date, entity, type, source, severity, tags, message', file=f)
for message in messages:
# make message body single line
msg = message.message.replace("\n", r"\n").replace("\t", r"\t")
print('%s, %s, %s, %s, %s, %s, %s' % (
message.date, message.entity, message.type, message.source, message.severity, print_tags(message.tags), msg),
file=f)