Compare commits
No commits in common. "master" and "staging" have entirely different histories.
|
|
@ -1,42 +1,14 @@
|
|||
//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'
|
||||
envurl = environments."${key}"[1].'env-url'
|
||||
tokenname = environments."${key}"[2].'env-token-name'
|
||||
|
||||
sh 'python createReport.py "${envname}"'
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
pipeline {
|
||||
options {
|
||||
ansiColor('xterm')
|
||||
}
|
||||
//label libraryBuild is available in CN JAWS and ROW JAWS, therefore this one was used; no additional intents
|
||||
agent {label 'libraryBuild'}
|
||||
agent{label 'libraryBuild'}
|
||||
|
||||
|
||||
//here comes the trigger according to crontabs - jenkins is in UTC
|
||||
//here comes the trigger according to crontabs
|
||||
triggers {
|
||||
//every 1st of every month at 00:00
|
||||
cron('0 0 1 * *')
|
||||
|
||||
//every day at 08:00
|
||||
//cron('0 8 * * *')
|
||||
|
||||
//every monday at 08:00
|
||||
//cron('0 8 * * MON')
|
||||
|
||||
|
||||
}
|
||||
environment {
|
||||
//ProxySettings
|
||||
|
|
@ -60,44 +32,15 @@
|
|||
}
|
||||
|
||||
stages {
|
||||
stage('install required python packages') {
|
||||
stage('install required packages') {
|
||||
steps {
|
||||
sh '''
|
||||
pip install --user -r requirements.txt
|
||||
pip install -upgrade pip
|
||||
pip install -r requirements.txt
|
||||
'''
|
||||
print env.JENKINS_URL
|
||||
}
|
||||
}
|
||||
|
||||
stage('Execute Reporting Script') {
|
||||
steps {
|
||||
|
||||
sh 'python createReport.py'
|
||||
|
||||
//Only required once CN is not reachable from EMEA
|
||||
//loopEnvironments(environments)
|
||||
}
|
||||
|
||||
}
|
||||
stage('Send report') {
|
||||
steps {
|
||||
script {
|
||||
try {
|
||||
emailext subject: env.JOB_NAME,
|
||||
body: 'Please find the output of your reports attached',
|
||||
to: 'rene.forstner@nttdata.com',
|
||||
replyTo: 'coco-apm@bmw.de',
|
||||
attachmentsPattern: '*.csv'
|
||||
|
||||
}
|
||||
catch ( mailExc ){
|
||||
echo "Sending Email Failed: ${mailExc}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
post {
|
||||
always {
|
||||
cleanWs()
|
||||
|
|
|
|||
135
README.md
135
README.md
|
|
@ -1,134 +1 @@
|
|||
# Dynatrace Reporting Pipeline
|
||||
|
||||
This repository is used as a template to create automated Dynatrace reports through Jenkins (JAWS) which are sent as attachement through mail.
|
||||
***
|
||||
## Jenkins environments
|
||||
EMEA & NA: https://jaws.bmwgroup.net/opapm/
|
||||
|
||||
CN: https://jaws-china.bmwgroup.net/opmaas/
|
||||
|
||||
### Request access
|
||||
Access is granted manually through stephan.oertelt@bmw.de and Mohammed.Abadel@bmw.de
|
||||
|
||||
### Multi-Branch Pipelines
|
||||
- master (=latest) --> for testing and developing stuff
|
||||
- staging --> pre-release branch, if stuff tested successfully here merge it to production
|
||||
- production --> actively used, productive reports
|
||||
|
||||
***
|
||||
## Minimum Content of a Dynatrace Reporting Repo
|
||||
|
||||
### Repository & Pipeline Naming
|
||||
- Repository and Pipelines must have identical names
|
||||
- Naming must start with CoCo_APM_Reporting_**report name here**
|
||||
|
||||
### readme-File
|
||||
|
||||
The readme file must contain a useful description **what** is reported **when** to **whom**
|
||||
|
||||
Example: <br>
|
||||
> This report is reporting all installed OneAgent versions including:
|
||||
> - Hostnames
|
||||
> - Environment Tag
|
||||
> - PaaS Tag
|
||||
>
|
||||
> Sent to: coco-apm@bmw.de
|
||||
>
|
||||
> Executed on each Monday of every week <br>
|
||||
> Executed on every Dynatrace environment
|
||||
|
||||
### requirements.txt
|
||||
The requirements.txt file must contain **all** python packages which are used within the script through ```import``` <br>
|
||||
|
||||
e.g.: <br>
|
||||
``` python-decouple
|
||||
pyyaml
|
||||
pandas
|
||||
decouple
|
||||
requests
|
||||
datetime
|
||||
argparse
|
||||
```
|
||||
### environments.yaml
|
||||
The environments.yaml contains all environments on which the script should be executed, environments which should not be executed may be excluded through ```#```
|
||||
|
||||
**Do NOT change the environments names, the pipeline script is configured to distingue between EMEA/NA and CN as their are different Jenkins environments!**
|
||||
|
||||
The following snipped shows an environment file, which is only executed on Dynatrace prod environments.
|
||||
|
||||
```
|
||||
euprod:
|
||||
- name: "euprod"
|
||||
- env-url: "https://xxu26128.live.dynatrace.com"
|
||||
- env-token-name: "EUPROD_TOKEN_VAR"
|
||||
#eupreprod:
|
||||
- name: "eupreprod"
|
||||
- env-url: "https://qqk70169.live.dynatrace.com"
|
||||
- env-token-name: "EUPREPROD_TOKEN_VAR"
|
||||
#napreprod:
|
||||
- name: "napreprod"
|
||||
- env-url: "https://onb44935.live.dynatrace.com"
|
||||
- env-token-name: "NAPREPROD_TOKEN_VAR"
|
||||
naprod:
|
||||
- name: "naprod"
|
||||
- env-url: "https://wgv50241.live.dynatrace.com"
|
||||
- env-token-name: "NAPROD_TOKEN_VAR"
|
||||
cnprod:
|
||||
- name: "cnprod"
|
||||
- env-url: "https://dynatracemgd-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
||||
- env-token-name: "CNPROD_TOKEN_VAR"
|
||||
#cnpreprod:
|
||||
- name: "cnpreprod"
|
||||
- env-url: "https://dynatracemgd-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
||||
- env-token-name: "CNPREPROD_TOKEN_VAR"
|
||||
```
|
||||
|
||||
### Jenkinsfile
|
||||
The Jenkinsfile is the pipeline script itself including:
|
||||
- Time-Trigger
|
||||
- Install package step
|
||||
- Execute script step
|
||||
- Send Mail step
|
||||
|
||||
### Python Script
|
||||
The script itself will gather and aggregate the data from the Dynatrace environments.
|
||||
|
||||
Script output must be a csv or excel file in the **folder where the script is executed**
|
||||
***
|
||||
## First Usage - Create a new Pipeline
|
||||
|
||||
### Fork this repo
|
||||
Do **NOT** clone this repo, create a fork instead.
|
||||
|
||||
1. On the left menue bar click on *Create fork*
|
||||
|
||||

|
||||
|
||||
2. Choose Project *Offboard Platform - APM - Application Performance Monitoring*
|
||||
3. Choose a name starting with *CoCo_APM_Reporting_* and a useful suffix
|
||||
4. Uncheck *Enable fork syncing*
|
||||
|
||||

|
||||
|
||||
5. Edit readme.md and describe your report
|
||||
6. Change/Update the environment, requirements and script according to your needs
|
||||
7. Login to Jenkins and select the folder *Coco APM Reporting*
|
||||
8. Click the *New Item* Button
|
||||
9. Enter the name of your repo (e.g. *CoCo_APM_Reporting_OneAgentVersion*)
|
||||
10. Select *Multibranch Pipeline*
|
||||
11. Click *OK* Button
|
||||
|
||||

|
||||
|
||||
12. On The Pipeline Settings go to *Branch Sources*, click *ADD SOURCE* and select *Bitbucket*
|
||||
- Server: **ATC**
|
||||
- Credentials: **qqjaws7**
|
||||
- Owner: **OPAPM**
|
||||
- Repository Name: **your forked repository**
|
||||
- Behavious: **According to screenshot**
|
||||
<br>
|
||||
|
||||

|
||||
|
||||
<br>
|
||||
Your pipeline will automatically test-run for all 3 branches.
|
||||
init repo
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 141 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 53 KiB |
|
|
@ -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 +1,24 @@
|
|||
euprod:
|
||||
- name: "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://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/"
|
||||
|
|
|
|||
Loading…
Reference in New Issue