Compare commits

...

10 Commits

Author SHA1 Message Date
Doris Ruppert (ext.) c7ec5a7e70 Pull request #1: fixed CN env-urls
Merge in OPAPM/coco_apm_reportingbase from qxd0086/environmentyaml-1678725093987 to master

* commit '3f1c7b632836618268daca91877a014ddb23f95b':
  fixed CN env-urls
2023-03-14 13:01:05 +00:00
Doris Ruppert (ext.) 3f1c7b6328 fixed CN env-urls 2023-03-13 16:31:59 +00:00
rforstner 589d0ce28a adding py 2021-12-02 11:06:58 +01:00
rforstner 498be812ab adding py 2021-12-02 11:02:52 +01:00
rforstner 82818e5d49 adding py 2021-12-02 11:01:56 +01:00
rforstner 2ed52db914 adding py 2021-12-02 10:56:08 +01:00
rforstner 4954b4765f adding py 2021-12-02 10:51:38 +01:00
rforstner 92bff9c099 adding py 2021-12-02 10:20:36 +01:00
rforstner 6ea521b454 adding py 2021-12-02 10:16:14 +01:00
rforstner 7ab70b1011 adding py 2021-12-02 10:11:12 +01:00
3 changed files with 57 additions and 44 deletions

48
Jenkinsfile vendored
View File

@ -1,9 +1,11 @@
//not required right now as CN is reachable from EMEA as well
def loopEnvironments(environments){
print env.JENKINS_URL
environments.each { key, val ->
//Execute only if you are on the same environment
//not required right now as CN is reachable from EMEA as well
if (env.JENKINS_URL == environments."${key}"[3].'jenkins')
{
envname = environments."${key}"[0].'name'
@ -67,40 +69,13 @@
}
}
//DISTINGUISH between China and EMEA JAWS environment and execute the script only on the respective environment
//Define how to
// could also be a script block instead of a when block
//e.g. add an additional parameter to python scripts to let python choose on which environment it should execute the script (not that good, as the script should be as generic as possible)
//e.g. just put the execute python script step in both steps (not that good --> do not repeat yourself)
//e.g. create two environment.yaml files and use different files for different jenkins (not that good --> ugly)
//e.g. is the environment yaml even that good, should python be refactored to only execute one environment at time
stage('Detect Jenkins Environment CN') {
when {
expression { return env.JENKINS_URL == 'https://jaws-china.bmwgroup.net/opmaas/' }
}
stage('Execute Reporting Script') {
steps {
//env.JENKINS_URL
//env.BRANCH_NAME
print env.JENKINS_URL
print env.BRANCH_NAME
}
}
stage('Detect Jenkins Environment EMEA') {
when {
expression { return env.JENKINS_URL == 'https://jaws.bmwgroup.net/opapm/' }
}
steps {
script{environments = readYaml (file:'environment.yaml')}
sh 'echo "test" > test.csv'
loopEnvironments(environments)
//env.JENKINS_URL
//env.BRANCH_NAME
print env.JENKINS_URL
print env.BRANCH_NAME
sh 'python createReport.py'
//Only required once CN is not reachable from EMEA
//loopEnvironments(environments)
}
}
@ -109,11 +84,10 @@
script {
try {
emailext subject: env.JOB_NAME,
body: 'test',
body: 'Please find the output of your reports attached',
to: 'rene.forstner@nttdata.com',
replyTo: 'rene.forstner@nttdata.com',
from: 'coco-apm@bmw.de',
attachmentsPattern: 'test.csv'
replyTo: 'coco-apm@bmw.de',
attachmentsPattern: '*.csv'
}
catch ( mailExc ){

View File

@ -5,9 +5,9 @@ import json
import pandas as pd
from datetime import datetime
def make_request(url, headers):
def make_request(url, headers,verify):
try:
response = requests.get(url, headers=headers,verify=False)
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)
@ -25,16 +25,55 @@ def GatherReportingInfo(DTAPIToken, DTENV,friendlyName):
env = DTENV
DTAPIToken = DTAPIToken
DTAPIURL= env + "/api/config/v1/managementZones/"
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)
r = make_request(DTAPIURL,headers,verify)
print(r)
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)

View File

@ -20,11 +20,11 @@ naprod:
- jenkins: "https://jaws.bmwgroup.net/opapm/"
cnprod:
- name: "cnprod"
- env-url: "https://dynatracemgd-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
- env-url: "https://dyna-synth-cn.bmwgroup.com.cn/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-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
- env-url: "https://dyna-synth-cn.bmwgroup.com.cn/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35"
- env-token-name: "CNPREPROD_TOKEN_VAR"
- jenkins: "https://jaws-china.bmwgroup.net/opmaas/"