adding py
parent
16a65b98c6
commit
898a8d078a
|
|
@ -10,7 +10,7 @@
|
|||
envurl = environments."${key}"[1].'env-url'
|
||||
tokenname = environments."${key}"[2].'env-token-name'
|
||||
|
||||
sh 'python test.py ${envname} '
|
||||
sh 'python createReport.py "${envname}"'
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
from decouple import config
|
||||
import yaml
|
||||
import requests
|
||||
import json
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
|
||||
def make_request(url, headers):
|
||||
try:
|
||||
response = requests.get(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.HTTPError as errh:
|
||||
return "An Http Error occurred:" + repr(errh)
|
||||
except requests.exceptions.ConnectionError as errc:
|
||||
return "An Error Connecting to the API occurred:" + repr(errc)
|
||||
except requests.exceptions.Timeout as errt:
|
||||
return "A Timeout Error occurred:" + repr(errt)
|
||||
except requests.exceptions.RequestException as err:
|
||||
return "An Unknown Error occurred" + repr(err)
|
||||
|
||||
return response
|
||||
|
||||
def GatherReportingInfo(DTAPIToken, DTENV,friendlyName):
|
||||
reportingFolder = config('REPORTING_FOLDER')
|
||||
|
||||
env = DTENV
|
||||
DTAPIToken = DTAPIToken
|
||||
|
||||
DTAPIURL= env + "/api/config/v1/managementZones/"
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Api-Token ' + DTAPIToken
|
||||
}
|
||||
|
||||
#r = requests.get(DTAPIURL,headers=headers)
|
||||
r = make_request(DTAPIURL,headers)
|
||||
|
||||
print(r)
|
||||
|
||||
with open('./environment.yaml') as file:
|
||||
doc = yaml.safe_load(file)
|
||||
|
||||
for item, doc in doc.items():
|
||||
token = dict(doc[2])
|
||||
url = dict(doc[1])
|
||||
print("Crawling through: " + item)
|
||||
print("Check if token exists in environment...")
|
||||
if(config(token.get('env-token-name')) != ""):
|
||||
print("Gather data, hold on a minute")
|
||||
DTTOKEN = config(token.get('env-token-name'))
|
||||
DTURL = url.get('env-url')
|
||||
|
||||
GatherReportingInfo(DTTOKEN,DTURL,item)
|
||||
|
||||
else:
|
||||
print("token not found, skipping " + item)
|
||||
Loading…
Reference in New Issue