|
4 | 4 | import json
|
5 | 5 |
|
6 | 6 | #############################################################################
|
7 |
| -# USAGE TODO |
| 7 | +# USAGE |
8 | 8 | # python app.py \
|
9 | 9 | # -ten=https://abc12345.live.dynatrace.com \
|
10 | 10 | # -ocid=dt0s02.**** \
|
|
60 | 60 | # Strip potential trailing slash in case user left it in
|
61 | 61 | tenant_url = tenant_url.strip("/")
|
62 | 62 |
|
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 |
65 | 68 |
|
66 | 69 | # Change OAuth endpoint based on environment
|
67 | 70 | # Currently supports "dev", "sprint" or "prod" (default)
|
|
70 | 73 | if ".sprint." in tenant_url.lower():
|
71 | 74 | oauth_endpoint = OAUTH_SPRINT_ENDPOINT
|
72 | 75 |
|
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" |
78 | 87 |
|
79 | 88 | # Set up the OAuth body payload
|
80 | 89 | oauth_body = {
|
|
113 | 122 | ################################################
|
114 | 123 | # Step 2: Use Access Token to push bizevent
|
115 | 124 | ################################################
|
116 |
| -biz_event_url = f"{tenant_url}/api/v2/bizevents/ingest" |
117 | 125 | biz_event_headers = {
|
118 | 126 | "Authorization": f"Bearer {access_token_value}",
|
119 | 127 | "Content-Type": "application/json"
|
|
128 | 136 | if biz_event_resp.status_code == 202:
|
129 | 137 | print("Bizevent successfully sent!")
|
130 | 138 | else:
|
| 139 | + print(f"Response Status Code: {biz_event_resp.status_code}") |
131 | 140 | print(f"{biz_event_resp.json()}")
|
132 | 141 | print(f"Error sending bizevent. Please investigate. Exiting.")
|
133 | 142 | exit(1)
|
0 commit comments