Created
January 27, 2022 17:15
-
-
Save BrooksCunningham/f71ee593adb4eea29d971a52842ce8ae to your computer and use it in GitHub Desktop.
get logs from signal sciences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, calendar, os, time | |
from datetime import datetime, timedelta | |
# For details see | |
# https://docs.fastly.com/signalsciences/developer/extract-your-data/ | |
# Get environment variables | |
SIGSCITOKEN = os.getenv('SIGSCITOKEN') | |
SIGSCIEMAIL = os.environ.get('SIGSCIEMAIL') | |
# Calculate UTC timestamps for the previous full hour | |
# For example, if now is 9:05 AM UTC, the timestamps will be 8:00 AM and 9:00 AM | |
until_time = datetime.utcnow().replace(minute=0, second=0, microsecond=0) | |
from_time = until_time - timedelta(hours=1) | |
until_time = calendar.timegm(until_time.utctimetuple()) | |
from_time = calendar.timegm(from_time.utctimetuple()) | |
query = {'from': from_time, 'until': until_time} | |
headers = {'x-api-user': SIGSCIEMAIL, 'x-api-token': SIGSCITOKEN} | |
#TODO needs updating for URL corp and site | |
url = "https://dashboard.signalsciences.net/api/v0/corps/[some corp]/sites/[some site]/feed/requests" | |
resp = requests.get(url, params=query, headers=headers) | |
print(resp.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment