-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblems.py
61 lines (51 loc) · 1.93 KB
/
problems.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/python
from dynatrace import Dynatrace
import csv
import os
# Set these via
# export DT_BASE_URL="http://[YOUR-TENANT].live.dynatrace.com"
# export DT_API_TOKEN="[YOUR-TOKEN]"
dt = Dynatrace(
os.getenv("DT_BASE_URL"),
os.getenv("DT_API_TOKEN")
)
def formatdate(thedate):
if thedate:
return thedate.strftime("%Y-%m")
else:
return ""
# adjust as required
#problems = dt.problems.list(time_from="now-30m",problem_selector='status("closed")')
#problems = dt.problems.list(time_from="now-180d",problem_selector='status("closed"),managementZoneIds("mZId-1", "mzId-2")')
#problems = dt.problems.list(time_from="now-30m") #,entity_selector='type("CUSTOM_DEVICE")')
#problems = dt.problems.list(time_from="now-120d",time_to="now-60d",problem_selector='affectedEntityTypes("CUSTOM_DEVICE")')
#problems = dt.problems.list(time_from="2021-01-25T00:00:00",time_to="2023-02-10T00:00:00",problem_selector='affectedEntityTypes("CUSTOM_DEVICE")')
problems = dt.problems.list(time_from="now-1d",problem_selector='status("closed"),managementZoneIds("mZId-1", "mzId-2")')
with open('problems.csv', 'w') as file:
# create the csv writer
writer = csv.writer(file)
file.write("problem, title, status, impact_level, severity_level, start_time, end_time\n")
if not problems:
print("No problems found")
quit()
for problem in problems:
# adjust as required
pr=problem.json()
print(pr)
if 'recentComments' in pr:
co = pr['recentComments']
for c in co:
com = co['totalCount']
else:
print('Skipping comments')
com=0
# adjust as required
file.write("{},{},{},{},{},{},{}\n".format(
problem.display_id, \
problem.title,\
str(problem.status).partition(".")[2],\
str(problem.impact_level).partition(".")[2],\
str(problem.severity_level).partition(".")[2],\
formatdate(problem.start_time),\
formatdate(problem.end_time)))
file.close()