Skip to content
Logs
Visit Logs on GitHub
Set theme to dark (⇧+D)

Logpush using Python (example)

import jsonimport requests
url = "https://api.cloudflare.com/client/v4/"
x_auth_email = "EMAIL_REDACTED"x_auth_key = "KEY_REDACTED"
zone_id = "ZONE_REDACTED"destination_conf = "s3://BUCKET_REDACTED/logs?region=us-west-1"
logpush_url = url + "/zones/%s/logpush" % zone_id
headers = {  'X-Auth-Email': x_auth_email,  'X-Auth-Key': x_auth_key,  'Content-Type': 'application/json'}
# Create jobr = requests.post(logpush_url + "/jobs", headers=headers, data=json.dumps({"destination_conf":destination_conf}))print(r.status_code, r.text)assert r.status_code == 201assert r.json()["result"]["enabled"] == False
# Keep id of the new jobid = r.json()["result"]["id"]
# Get jobr = requests.get(logpush_url + "/jobs/%s" % id, headers=headers)print(r.status_code, r.text)assert r.status_code == 200
# Get all jobs for a zoner = requests.get(logpush_url + "/jobs", headers=headers)print(r.status_code, r.text)assert r.status_code == 200assert len(r.json()["result"]) > 0
# Update jobr = requests.put(logpush_url + "/jobs/%s" % id, headers=headers, data=json.dumps({"enabled":True}))print(r.status_code, r.text)assert r.status_code == 200assert r.json()["result"]["enabled"] == True
# Delete jobr = requests.delete(logpush_url + "/jobs/%s" % id, headers=headers)print(r.status_code, r.text)assert r.status_code == 200