Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /usr/bin/env python3
'''
author: Joshua Worley
'''
import argparse
import json
import requests
import pprint
from datetime import datetime
parser = argparse.ArgumentParser(description='S1 package retrieval')
parser.add_argument('-t', action='store', required=True,
dest='TOKEN', help='API Token')
parser.add_argument('-c', action='store', required=True,
dest='CONSOLE', help='S1 Console')
parser.add_argument('-s', action='store', required=True,
dest='SITEID', help='S1 Site ID')
P = parser.parse_args()
pp = pprint.PrettyPrinter(indent=1)
console = P.CONSOLE
api = "web/api/v2.1/update/agent/packages"
token = "ApiToken {}".format(P.TOKEN)
HEADERS = {
"Content-Type": "application/json",
"Authorization": token
}
PAYLOAD = {
"packageType": "Agent",
"siteIds": P.SITEID
}
print("S1 console: {}".format(console))
print("SiteID: {}".format(P.SITEID))
RESPONSE = []
try:
while True:
print("trying now")
# pp.pprint(PAYLOAD)
r = requests.get("{}{}".format(console, api), headers=HEADERS, params=PAYLOAD)
pp.pprint(r.json()['pagination'])
RESPONSE.extend(r.json()['data'])
if r.json()['pagination']['nextCursor'] is None:
break
PAYLOAD.update({
"cursor":r.json()['pagination']['nextCursor']
})
except:
pp.pprint(r.json()['pagination'])
pp.pprint(PAYLOAD)
exit(2)
now = datetime.now().astimezone().replace(microsecond=0).isoformat()
file_name = "s1pkgs-{}_{}.json".format(P.SITEID, now)
with open(file_name, 'w') as f:
json.dump(RESPONSE, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment