You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.8 KiB
49 lines
1.8 KiB
import sys
|
|
import json
|
|
import gzip
|
|
import csv
|
|
import os
|
|
import requests
|
|
import warnings
|
|
|
|
def send_post_request(req,user,password,data=None,headers=None):
|
|
with warnings.catch_warnings():
|
|
warnings.simplefilter("ignore")
|
|
r = requests.post(url,auth=(user, password), verify=False, data=data, headers=headers)
|
|
return r
|
|
|
|
|
|
if __name__ == "__main__":
|
|
DEBUG = False
|
|
HOME = os.path.abspath(os.path.join(os.path.realpath(__file__),"..",".."))
|
|
CACHE = os.path.join(HOME,"cache")
|
|
payload = json.load(sys.stdin)
|
|
ip = payload.get('configuration', {}).get('ip', '')
|
|
user = payload.get('configuration', {}).get('user', '')
|
|
password = payload.get('configuration', {}).get('password', '')
|
|
results_file = payload.get('results_file','')
|
|
if not results_file or not ip or not user or not password:
|
|
print("Missing mandatory input", file=sys.stderr)
|
|
exit()
|
|
with gzip.open(results_file, mode="rt") as f:
|
|
reader = csv.DictReader(f)
|
|
results = [row for row in reader]
|
|
if DEBUG:
|
|
with open(os.path.join(CACHE,"data.json"),"w") as f:
|
|
json.dump(results,f,indent=4)
|
|
requests_url = []
|
|
for result in results:
|
|
if result.get("model_handle","") and result.get("event_id",""):
|
|
requests_url.append("https://"+ip+"/spectrum/restful/events/"+result["event_id"]+"/model/"+result["model_handle"])
|
|
if DEBUG:
|
|
with open(os.path.join(CACHE,"requests.json"),"w") as f:
|
|
json.dump(requests_url,f,indent=4)
|
|
r = None
|
|
for url in requests_url:
|
|
r = send_post_request(url,user,password)
|
|
if DEBUG:
|
|
with open(os.path.join(CACHE,"results.txt"),"w") as f:
|
|
f.write("Done\n")
|
|
if r:
|
|
f.write(str(r)+"\n")
|
|
f.write(r.text) |