infra-utils/cloudflare/get_log.py

37 lines
1015 B
Python
Raw Normal View History

2018-08-15 21:41:57 +00:00
#!/usr/bin/env python3
import os
import json
2018-08-15 21:41:57 +00:00
import CloudFlare
2018-11-19 14:04:08 +00:00
email = 'jakub@status.im'
token = os.environ['CF_TOKEN']
cf = CloudFlare.CloudFlare(email, token)
#zones = cf.zones.get(params = {'per_page':100})
#zone_id = zones[0]['id']
#zone_name = zones[0]['id']
#print('Zones:', [z['name'] for z in zones])
2018-08-15 21:41:57 +00:00
2018-11-19 14:04:08 +00:00
logs = cf.organizations.audit_logs.get('113ef908d19933ef327f079a3def53fc',
params={
'since': '2018-01-01',
'per_page': 5000,
'order': 'when',
'direction': 'asc',
'zone.name': 'status.im'
}
)
for log in logs:
if log['action']['type'] not in ['add', 'delete']:
continue
2018-11-19 14:04:08 +00:00
print('{:30} {:20} {:12} {:>10} {:>7} {:30} {}'.format(
log['when'],
log['actor'].get('email', log['metadata'].get('acted_on_behalf_of')),
log['metadata'].get('zone_name'),
log['action'].get('type'),
log['metadata'].get('type') or '',
log['metadata'].get('name') or '',
log['metadata'].get('content') or ''
))