Compare commits
No commits in common. "master" and "Tokenfix" have entirely different histories.
|
|
@ -19,6 +19,7 @@ def get_request(url, headers):
|
|||
return "A Timeout Error occurred:" + repr(errt)
|
||||
except requests.exceptions.RequestException as err:
|
||||
return "An Unknown Error occurred" + repr(err)
|
||||
|
||||
return response
|
||||
|
||||
def post_request(url, headers,body):
|
||||
|
|
@ -33,6 +34,7 @@ def post_request(url, headers,body):
|
|||
return "A Timeout Error occurred:" + repr(errt)
|
||||
except requests.exceptions.RequestException as err:
|
||||
return "An Unknown Error occurred" + repr(err)
|
||||
|
||||
return response
|
||||
|
||||
def put_request(url, headers,body):
|
||||
|
|
@ -47,53 +49,93 @@ def put_request(url, headers,body):
|
|||
return "A Timeout Error occurred:" + repr(errt)
|
||||
except requests.exceptions.RequestException as err:
|
||||
return "An Unknown Error occurred" + repr(err)
|
||||
|
||||
return response
|
||||
|
||||
def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
||||
|
||||
env = DTENV
|
||||
DTAPIToken = DTAPIToken
|
||||
|
||||
|
||||
DTAPIURL = env + "/api/v2/apiTokens"
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Api-Token ' + DTAPIToken
|
||||
}
|
||||
|
||||
DynatraceInstaller = [
|
||||
|
||||
"InstallerDownload",
|
||||
"SupportAlert"
|
||||
]
|
||||
|
||||
]
|
||||
|
||||
DevOps_Read = [
|
||||
|
||||
"DataExport", # Access problem and event feed, metrics, and topology.
|
||||
|
||||
"DTAQLAccess", # User sessions.
|
||||
|
||||
"ReadSyntheticData", # Read synthetic monitors, locations, and nodes.
|
||||
|
||||
"metrics.read", # Read metrics.
|
||||
|
||||
"entities.read", # Read entities.
|
||||
|
||||
"problems.read", # Read problems.
|
||||
|
||||
"syntheticLocations.read", # Read synthetic locations.
|
||||
|
||||
"slo.read", # Read SLO.
|
||||
|
||||
"releases.read", # Read releases.
|
||||
|
||||
"activeGates.read"
|
||||
]
|
||||
|
||||
]
|
||||
ReadAll = [
|
||||
|
||||
"DataExport", # Access problem and event feed, metrics, and topology.
|
||||
|
||||
"ReadConfig", # Read configuration.
|
||||
|
||||
"DTAQLAccess", # User sessions.
|
||||
|
||||
"ReadSyntheticData", # Read synthetic monitors, locations, and nodes.
|
||||
|
||||
"auditLogs.read", # Read audit logs.
|
||||
|
||||
"metrics.read", # Read metrics.
|
||||
|
||||
"entities.read", # Read entities.
|
||||
|
||||
"problems.read", # Read problems.
|
||||
|
||||
"networkZones.read", # Read network zones.
|
||||
|
||||
"activeGates.read", # Read ActiveGates.
|
||||
|
||||
"credentialVault.read", # Read credential vault entries.
|
||||
|
||||
"extensions.read", # Read extensions.
|
||||
|
||||
"extensionConfigurations.read", # Read extension monitoring configurations.
|
||||
|
||||
"extensionEnvironment.read", # Read extension environment configurations.
|
||||
|
||||
"securityProblems.read", # Read security problems.
|
||||
|
||||
"syntheticLocations.read", # Read synthetic locations.
|
||||
|
||||
"slo.read", # Read SLO.
|
||||
|
||||
"releases.read", # Read releases.
|
||||
|
||||
"apiTokens.read" # Read API tokens.
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
temp=[]
|
||||
if "DynatraceInstaller" in scope:
|
||||
|
|
@ -103,6 +145,7 @@ def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
|||
if "ReadAll" in scope:
|
||||
temp.extend(ReadAll)
|
||||
|
||||
|
||||
if not temp:
|
||||
print("scope not supported")
|
||||
sys.exit()
|
||||
|
|
@ -113,8 +156,8 @@ def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
|||
r = post_request(DTAPIURL,headers,data)
|
||||
print(r)
|
||||
row = {'Environment':dtEnvInfo,'DT_API_URL':env +"/api", 'DT_[API|PAAS]_TOKEN':r.json()['token'],'DT_NETWORK_ZONE':nwzone}
|
||||
return row
|
||||
|
||||
return row
|
||||
#################
|
||||
##main
|
||||
#################
|
||||
|
|
@ -149,8 +192,10 @@ for item, doc in doc.items():
|
|||
print("Gather data, hold on a minute")
|
||||
DTTOKEN = config(token.get('env-token-name'))
|
||||
DTURL = url.get('env-url')
|
||||
|
||||
row = CreateToken(DTTOKEN,DTURL,nwzone.get('network-zone'),dtEnvInfo.get('env-info'),tokenname,scope)
|
||||
df = df.append(row,ignore_index=True)
|
||||
|
||||
else:
|
||||
print("token not found, skipping " + item)
|
||||
print(df)
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ naprod:
|
|||
- env-info: "E2E/PROD"
|
||||
cnprod:
|
||||
- name: "cnprod"
|
||||
- env-url: "https://dyna-synth-cn.bmwgroup.com.cn/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
||||
- env-url: "https://dynatracemgd-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
||||
- env-token-name: "CNPROD_TOKEN_VAR"
|
||||
- network-zone: "coco.cn.aws-tsp.prod"
|
||||
- env-info: "E2E/PROD"
|
||||
cnpreprod:
|
||||
- name: "cnpreprod"
|
||||
- env-url: "https://dyna-synth-cn.bmwgroup.com.cn/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35"
|
||||
- env-url: "https://dynatracemgd-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
||||
- env-token-name: "CNPREPROD_TOKEN_VAR"
|
||||
- network-zone: "coco.cn.aws-tsp.preprod"
|
||||
- env-info: "DEV/INT"
|
||||
|
|
|
|||
Loading…
Reference in New Issue