-
Notifications
You must be signed in to change notification settings - Fork 14
/
event_test.py
43 lines (32 loc) · 1.31 KB
/
event_test.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
import argparse
import json
import sys
from socotratools.client import SocotraClient
from socotratools import dates
def process_events(events):
for event in events:
print event['id'] + ' - ' + event['type'] + ' - ' + event['timestamp']
def main(argv):
parser = argparse.ArgumentParser(
description='Main Test Application')
# times should be in YYYY-MM-dd format
parser.add_argument('-s', '--start', required=True)
parser.add_argument('-n', '--hostname', required=True)
parser.add_argument('-u', '--username',
default='alice.lee', required=False)
parser.add_argument('-p', '--password', default='socotra', required=False)
args = parser.parse_args(argv)
print 'Authenticating with tenant: ' + args.hostname
client = SocotraClient.get_authenticated_client_for_hostname(
args.hostname, args.username, args.password)
start = dates.date_to_millis(args.start,
'America/Los_Angeles', '%Y-%m-%d')
response = client.get_events(start_timestamp=start)
while True:
process_events(response['events'])
token = response['pagingToken']
response = client.get_events(paging_token=token)
if len(response['events']) == 0:
break
if __name__ == "__main__":
main(sys.argv[1:])