Compare commits

..

No commits in common. "c7ec5a7e702393bdf0abc170911db25847d52935" and "ea725499290ec9831b376d2c6e38c6bc28d34985" have entirely different histories.

3 changed files with 44 additions and 57 deletions

48
Jenkinsfile vendored
View File

@ -1,11 +1,9 @@
//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'
@ -69,13 +67,40 @@
}
}
stage('Execute Reporting Script') {
//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/' }
}
steps {
sh 'python createReport.py'
//Only required once CN is not reachable from EMEA
//loopEnvironments(environments)
//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
}
}
@ -84,10 +109,11 @@
script {
try {
emailext subject: env.JOB_NAME,
body: 'Please find the output of your reports attached',
body: 'test',
to: 'rene.forstner@nttdata.com',
replyTo: 'coco-apm@bmw.de',
attachmentsPattern: '*.csv'
replyTo: 'rene.forstner@nttdata.com',
from: 'coco-apm@bmw.de',
attachmentsPattern: 'test.csv'
}
catch ( mailExc ){

View File

@ -5,9 +5,9 @@ import json
import pandas as pd
from datetime import datetime
def make_request(url, headers,verify):
def make_request(url, headers):
try:
response = requests.get(url, headers=headers,verify=verify)
response = requests.get(url, headers=headers,verify=False)
response.raise_for_status()
except requests.exceptions.HTTPError as errh:
return "An Http Error occurred:" + repr(errh)
@ -25,55 +25,16 @@ 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"
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,verify)
r = make_request(DTAPIURL,headers)
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')
print(r)
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://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"
- jenkins: "https://jaws-china.bmwgroup.net/opmaas/"
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"
- jenkins: "https://jaws-china.bmwgroup.net/opmaas/"