Skip to content

Commit 1b018cd

Browse files
committed
update to work with gen3
1 parent 6897e57 commit 1b018cd

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

code/app.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55

66
#############################################################################
7-
# USAGE TODO
7+
# USAGE
88
# python app.py \
99
# -ten=https://abc12345.live.dynatrace.com \
1010
# -ocid=dt0s02.**** \
@@ -60,8 +60,11 @@
6060
# Strip potential trailing slash in case user left it in
6161
tenant_url = tenant_url.strip("/")
6262

63-
# Use incoming tenant_url to set the biz event ingest URL
64-
biz_event_url = f"{tenant_url}/api/v2/bizevents/ingest"
63+
# Set up debug mode and dry run switches
64+
DEBUG_MODE = False
65+
if debug_mode.lower() == "true":
66+
print("> Debug mode is ON")
67+
DEBUG_MODE = True
6568

6669
# Change OAuth endpoint based on environment
6770
# Currently supports "dev", "sprint" or "prod" (default)
@@ -70,11 +73,17 @@
7073
if ".sprint." in tenant_url.lower():
7174
oauth_endpoint = OAUTH_SPRINT_ENDPOINT
7275

73-
# Set up debug mode and dry run switches
74-
DEBUG_MODE = False
75-
if debug_mode.lower() == "true":
76-
print("> Debug mode is ON")
77-
DEBUG_MODE = True
76+
# Use incoming tenant_url to set the biz event ingest URL
77+
biz_event_url = ""
78+
79+
if ".apps." in tenant_url:
80+
# Using the new DT platform
81+
# Set the bizevent ingest endpoint appropriately
82+
biz_event_url = f"{tenant_url}/platform/classic/environment-api/v2/bizevents/ingest"
83+
if DEBUG_MODE:
84+
print(f"Got a gen3 endpoint. biz_event_url is: {biz_event_url}")
85+
else:
86+
biz_event_url = f"{tenant_url}/api/v2/bizevents/ingest"
7887

7988
# Set up the OAuth body payload
8089
oauth_body = {
@@ -113,7 +122,6 @@
113122
################################################
114123
# Step 2: Use Access Token to push bizevent
115124
################################################
116-
biz_event_url = f"{tenant_url}/api/v2/bizevents/ingest"
117125
biz_event_headers = {
118126
"Authorization": f"Bearer {access_token_value}",
119127
"Content-Type": "application/json"
@@ -128,6 +136,7 @@
128136
if biz_event_resp.status_code == 202:
129137
print("Bizevent successfully sent!")
130138
else:
139+
print(f"Response Status Code: {biz_event_resp.status_code}")
131140
print(f"{biz_event_resp.json()}")
132141
print(f"Error sending bizevent. Please investigate. Exiting.")
133142
exit(1)

0 commit comments

Comments
 (0)