cleanup
parent
7695565018
commit
ba38d85117
|
|
@ -1,94 +0,0 @@
|
|||
from decouple import config
|
||||
import yaml
|
||||
import requests
|
||||
import json
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
|
||||
def make_request(url, headers,verify):
|
||||
try:
|
||||
response = requests.get(url, headers=headers,verify=verify)
|
||||
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):
|
||||
|
||||
env = DTENV
|
||||
DTAPIToken = DTAPIToken
|
||||
|
||||
if (DTENV.find('dynatracemgd') != -1):
|
||||
verify=False
|
||||
else:
|
||||
verify=True
|
||||
|
||||
DTAPIURL= env + "/api/v2/metrics?metricSelector=calc:service.*&fields=created,lastWritten&pageSize=499"
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Api-Token ' + DTAPIToken
|
||||
}
|
||||
|
||||
#r = requests.get(DTAPIURL,headers=headers)
|
||||
r = make_request(DTAPIURL,headers,verify)
|
||||
|
||||
df = pd.DataFrame()
|
||||
mgmt = pd.DataFrame()
|
||||
|
||||
now=datetime.now()
|
||||
strnow = now.strftime("%Y%m%d_%H%M")
|
||||
metrics = r.json()
|
||||
for metric in metrics['metrics']:
|
||||
row={'metricID':metric['metricId'],'created':metric['created'],'lastWritten':metric['lastWritten']}
|
||||
print(metric['metricId'])
|
||||
cleanedMetric = metric['metricId'].replace('\"','')
|
||||
cleanedMetric = cleanedMetric.replace('"','')
|
||||
DTAPIURL= env + "/api/config/v1/calculatedMetrics/service/" + cleanedMetric
|
||||
|
||||
response = make_request(DTAPIURL,headers,verify)
|
||||
|
||||
row.update({'name':response.json()['name']})
|
||||
for condition in response.json()['conditions']:
|
||||
i = 0
|
||||
if(condition['attribute']=='SERVICE_TAG'):
|
||||
try:
|
||||
row.update({'SERVICE_TAG_KEY_'+str(i):condition['comparisonInfo']['value']['key'],'SERVICE_TAG_VALUE_'+str(i):condition['comparisonInfo']['value']['value']})
|
||||
except:
|
||||
row.update({'SERVICE_TAG_KEY_'+str(i):'NO DATA','SERVICE_TAG_VALUE_'+str(i):'NO DATA'})
|
||||
|
||||
if(condition['attribute']=='PROCESS_GROUP_TAG'):
|
||||
try:
|
||||
row.update({'PG_TAG_KEY_'+str(i):condition['comparisonInfo']['value']['key'],'PG_TAG_VALUE_'+str(i):condition['comparisonInfo']['value']['value']})
|
||||
except:
|
||||
row.update({'PG_TAG_KEY_'+str(i):'NO DATA','SERVICE_TAG_VALUE_'+str(i):'NO DATA'})
|
||||
i=i+1
|
||||
|
||||
mgmt = mgmt.append(row,ignore_index=True)
|
||||
|
||||
# df.to_csv(reportingFolder + friendlyName + '_Restart_' + strnow +'.csv')
|
||||
mgmt.to_csv(friendlyName + '_CalculatedMetrics_' + strnow +'.csv',encoding='utf-8')
|
||||
|
||||
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)
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
euprod:
|
||||
- name: "EUprod"
|
||||
- env-url: "https://xxu26128.live.dynatrace.com"
|
||||
- env-token-name: "EUPROD_TOKEN_VAR"
|
||||
- jenkins: "https://jaws.bmwgroup.net/opapm/"
|
||||
eupreprod:
|
||||
- name: "eupreprod"
|
||||
- env-url: "https://qqk70169.live.dynatrace.com"
|
||||
- env-token-name: "EUPREPROD_TOKEN_VAR"
|
||||
- jenkins: "https://jaws.bmwgroup.net/opapm/"
|
||||
napreprod:
|
||||
- name: "napreprod"
|
||||
- env-url: "https://onb44935.live.dynatrace.com"
|
||||
- env-token-name: "NAPREPROD_TOKEN_VAR"
|
||||
- jenkins: "https://jaws.bmwgroup.net/opapm/"
|
||||
naprod:
|
||||
- name: "naprod"
|
||||
- env-url: "https://wgv50241.live.dynatrace.com"
|
||||
- env-token-name: "NAPROD_TOKEN_VAR"
|
||||
- jenkins: "https://jaws.bmwgroup.net/opapm/"
|
||||
cnprod:
|
||||
- name: "cnprod"
|
||||
- env-url: "https://dynatracemgd-tsp.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
||||
- env-token-name: "CNPROD_TOKEN_VAR"
|
||||
- jenkins: "https://jaws-china.bmwgroup.net/opmaas/"
|
||||
cnpreprod:
|
||||
- name: "cnpreprod"
|
||||
- env-url: "https://dynatracemgd-tsp.bmwgroup.net/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35"
|
||||
- env-token-name: "CNPREPROD_TOKEN_VAR"
|
||||
- jenkins: "https://jaws-china.bmwgroup.net/opmaas/"
|
||||
18
main.tf
18
main.tf
|
|
@ -1,18 +0,0 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
dynatrace = {
|
||||
version = "1.9.1"
|
||||
source = "dynatrace-oss/dynatrace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# module "configDir" {
|
||||
# source = "git::https://github.com/arnauagithub/DynatraceTerraformConfiguration.git?ref=20211130-151123"
|
||||
# }
|
||||
|
||||
|
||||
module "m1" { source = "./output/20220117-132316_EMEA_PROD/anomalies" }
|
||||
module "m2" { source = "./output/20220117-132316_EMEA_PROD/credentials" }
|
||||
module "dynatrace_custom_service" { source = "./output/20220117-132316_EMEA_PROD/custom_services" }
|
||||
module "dynatrace_service_naming" { source = "./output/20220117-132316_EMEA_PROD/naming/services" }
|
||||
Loading…
Reference in New Issue