# Synthetic Operational Framework

**URL:** <https://community.dynatrace.com/t/synthetic-operational-framework/41542>\
**Category:** Synthetic Monitoring\
**Tags:** http-monitor, browser-monitors, synthetic-monitoring, private-synthetic-locations\
**Created:** [September 6, 2023, 3:17pm UTC](https://community.dynatrace.com/t/synthetic-operational-framework/41542 "2023-09-06T15:17:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saldrich](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@saldrich](https://community.dynatrace.com/u/saldrich)\
**Post date:** [September 6, 2023, 3:17pm UTC](https://community.dynatrace.com/t/synthetic-operational-framework/41542/1 "2023-09-06T15:17:34Z")

</div>

Looking for a way to include in our application testing cycle (CI/CD pipeline for lower environments) validation code with the following steps:

1) Enable Synthetic Monitor.  
2) Run Synthetic Monitor.  
3) Validate if the Synthetic Monitor succeeded or failed

4) Pull important metrics from the succeeded execution (ie. failure rate, performance, availability, etc)  
4) Follow or fail the process according to the above result.

5)&nbsp;Disable Synthetic Monitor.

Is there a simple way through the API to determine if the Synthetic Monitor ran successfully or failed?

Does anyone have a tip on how I could get the above information?&nbsp; As mentioned above, want to create an Operational Framework where this can be built into CI/CD pipeline for lower environment validations / executions.

Thanks for your feedback.

---

<div class="post-metadata">

**Author:** ![hannahmac](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/hannahmac/32/41823_2.png) [@hannahmac](https://community.dynatrace.com/u/hannahmac)\
**Post date:** [September 6, 2023, 3:37pm UTC](https://community.dynatrace.com/t/synthetic-operational-framework/41542/2 "2023-09-06T15:37:22Z")

</div>

Does this help?&nbsp;[On-demand synthetic monitor executions for CI/CD in Classic — Dynatrace Docs](https://www.dynatrace.com/support/help/platform-modules/digital-experience/synthetic-monitoring/general-information/on-demand-executions#api)

---

<div class="post-metadata">

**Author:** ![natanael\_mendes](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/natanael_mendes/32/15264_2.png) [@natanael\_mendes](https://community.dynatrace.com/u/natanael_mendes)\
**Post date:** [September 6, 2023, 6:19pm UTC](https://community.dynatrace.com/t/synthetic-operational-framework/41542/3 "2023-09-06T18:19:13Z")

</div>

To include Dynatrace Synthetic Monitors as part of your CI/CD pipeline for lower environment validations and executions, you can use the Dynatrace Synthetic Monitoring API to programmatically interact with Synthetic Monitors and retrieve their results. Here’s an outline of the steps you can follow:

1. \*\*Enable Synthetic Monitor:\*\*  
- Use the Dynatrace Synthetic Monitoring API to enable the Synthetic Monitor for your application.

2. \*\*Run Synthetic Monitor:\*\*  
- Trigger the Synthetic Monitor execution via the API.

3. \*\*Validate Monitor Status:\*\*  
- Monitor the status of the Synthetic Monitor execution to determine if it succeeded or failed.

4. \*\*Retrieve Metrics:\*\*  
- If the monitor succeeds, use the API to retrieve important metrics such as failure rate, performance, availability, etc., from the Synthetic Monitor results.

5. \*\*Follow or Fail the Process:\*\*  
- Based on the results and metrics obtained, you can proceed with the CI/CD pipeline if the monitor succeeds or fail the process if it fails.

6. \*\*Disable Synthetic Monitor:\*\*  
- Optionally, use the API to disable the Synthetic Monitor when it’s no longer needed.

Here’s more detail on steps 3 and 4:

\*\*3. Validate Monitor Status:\*\*

To determine if the Synthetic Monitor execution succeeded or failed, you can use the `/synthetic/monitors/{monitorId}/executions` endpoint of the Synthetic Monitoring API. When you trigger a monitor execution, it will return an execution ID. You can then query the status of that execution ID to check if it succeeded or failed.

\*\*4. Retrieve Metrics:\*\*

If the Synthetic Monitor execution is successful, you can use the `/synthetic/monitors/{monitorId}/executions/{executionId}/results` endpoint to retrieve metrics and results from that specific execution. You can extract metrics such as failure rate, performance, and availability from the response.

Here’s a high-level example in Python using the `requests` library to interact with the Synthetic Monitoring API:

```python  
import requests

# Set your API token and URL  
api\_token = “YOUR\_API\_TOKEN”  
api\_url = “https://YOUR\_DYNATRACE\_INSTANCE/api/v1”

# Enable the Synthetic Monitor  
# Run the Synthetic Monitor  
# (Code for steps 1 and 2)

# Check the status of the monitor execution  
execution\_id = “EXECUTION\_ID”  
execution\_status\_response = requests.get(  
f"{api\_url}/synthetic/monitors/{monitor\_id}/executions/{execution\_id}“,  
headers={“Authorization”: f"Api-Token {api\_token}”}  
)

if execution\_status\_response.status\_code == 200:  
execution\_status = execution\_status\_response.json()[“result”][“status”]

if execution\_status == “FINISHED”:  
# Retrieve metrics if the execution is successful  
execution\_metrics\_response = requests.get(  
f"{api\_url}/synthetic/monitors/{monitor\_id}/executions/{execution\_id}/results",  
headers={“Authorization”: f"Api-Token {api\_token}"}  
)

if execution\_metrics\_response.status\_code == 200:  
metrics = execution\_metrics\_response.json()  
# Extract and use the desired metrics (e.g., failure rate, performance)

else:  
# Handle the case where metrics retrieval fails  
pass  
else:  
# Handle the case where the monitor execution failed  
pass  
else:  
# Handle the case where execution status retrieval fails  
pass

# Continue with your CI/CD pipeline based on the results  
```

Make sure to replace placeholders like `YOUR_API_TOKEN`, `YOUR_DYNATRACE_INSTANCE`, `EXECUTION_ID`, and `monitor_id` with your actual values. This code provides a basic structure for interacting with the Dynatrace Synthetic Monitoring API to achieve your desired integration within your CI/CD pipeline.

See this Documentation page:

> **[On-demand synthetic monitor executions for CI/CD in Classic](https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/general-information/on-demand-executions)**
>
> Execute synthetic monitors on demand from public or private locations

---

<div class="post-metadata">

**Author:** ![saldrich](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@saldrich](https://community.dynatrace.com/u/saldrich)\
**Post date:** [September 6, 2023, 7:23pm UTC](https://community.dynatrace.com/t/synthetic-operational-framework/41542/4 "2023-09-06T19:23:26Z")

</div>

Wow this is great details. Are you able to provide more information on Steps 1 - 3? Thanks so much.

1. \*\*Enable Synthetic Monitor:\*\*  
- Use the Dynatrace Synthetic Monitoring API to enable the Synthetic Monitor for your application.

2. \*\*Run Synthetic Monitor:\*\*  
- Trigger the Synthetic Monitor execution via the API.

3. \*\*Validate Monitor Status:\*\*  
- Monitor the status of the Synthetic Monitor execution to determine if it succeeded or failed.

---

<div class="post-metadata">

**Author:** ![saldrich](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@saldrich](https://community.dynatrace.com/u/saldrich)\
**Post date:** [September 7, 2023, 7:37pm UTC](https://community.dynatrace.com/t/synthetic-operational-framework/41542/5 "2023-09-07T19:37:38Z")

</div>

Good afternoon and thanks for the above.

Wow this is great details you provided for step 4 - 6. Are you able to provide more information on Steps 1 - 3? Thanks so much.

1. \*\*Enable Synthetic Monitor:\*\*  
- Use the Dynatrace Synthetic Monitoring API to enable the Synthetic Monitor for your application.

2. \*\*Run Synthetic Monitor:\*\*  
- Trigger the Synthetic Monitor execution via the API.

3. \*\*Validate Monitor Status:\*\*  
- Monitor the status of the Synthetic Monitor execution to determine if it succeeded or failed.

---

<div class="post-metadata">

**Author:** ![hannahmac](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/hannahmac/32/41823_2.png) [@hannahmac](https://community.dynatrace.com/u/hannahmac)\
**Post date:** [September 8, 2023, 12:52pm UTC](https://community.dynatrace.com/t/synthetic-operational-framework/41542/6 "2023-09-08T12:52:50Z")

</div>

1. \*\*Enable Synthetic Monitor:\*\*  
- Use the Dynatrace Synthetic Monitoring API to enable the Synthetic Monitor for your application.

> **[Synthetic monitors API - PUT a monitor](https://docs.dynatrace.com/docs/dynatrace-api/environment-api/synthetic/synthetic-monitors/put-a-monitor)**
>
> Edit a synthetic monitor via the Synthetic v1 API.

2. \*\*Run Synthetic Monitor:\*\*  
- Trigger the Synthetic Monitor execution via the API.

> **[Synthetic monitor executions API v2 - POST batch execution](https://docs.dynatrace.com/docs/dynatrace-api/environment-api/synthetic-v2/synthetic-monitor-execution/post-batch-execution)**
>
> Trigger a batch execution of synthetic monitors via the Dynatrace API.

3. \*\*Validate Monitor Status:\*\*  
- Monitor the status of the Synthetic Monitor execution to determine if it succeeded or failed.

> **[Synthetic monitor executions API v2 - GET summary of a batch execution](https://docs.dynatrace.com/docs/dynatrace-api/environment-api/synthetic-v2/synthetic-monitor-execution/get-batch-summary)**
>
> View the summary of a batch execution of synthetic monitors via the Dynatrace API.
