Synthetic Operational Framework

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: