-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
sample_incidents.py
109 lines (88 loc) · 4.45 KB
/
sample_incidents.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_incidents.py
DESCRIPTION:
This sample demonstrates how to list incidents and root causes.
USAGE:
python sample_incidents.py
Set the environment variables with your own values before running the sample:
1) METRICS_ADVISOR_ENDPOINT - the endpoint of your Azure Metrics Advisor service
2) METRICS_ADVISOR_SUBSCRIPTION_KEY - Metrics Advisor service subscription key
3) METRICS_ADVISOR_API_KEY - Metrics Advisor service API key
4) METRICS_ADVISOR_DETECTION_CONFIGURATION_ID - the ID of an anomaly detection configuration
5) METRICS_ADVISOR_ALERT_CONFIGURATION_ID - the ID of an alert configuration
6) METRICS_ADVISOR_INCIDENT_ID - the ID of an incident
7) METRICS_ADVISOR_ALERT_ID - the ID of an alert
"""
import os
def sample_list_incidents_for_detection_configuration():
# [START list_incidents_for_detection_configuration]
import datetime
from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential, MetricsAdvisorClient
service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
results = client.list_incidents(
detection_configuration_id=detection_configuration_id,
start_time=datetime.datetime(2021, 1, 1),
end_time=datetime.datetime(2021, 9, 9),
)
for result in results:
print("Metric id: {}".format(result.metric_id))
print("Incident ID: {}".format(result.id))
print("Severity: {}".format(result.severity))
print("Status: {}".format(result.status))
# [END list_incidents_for_detection_configuration]
def sample_list_incident_root_cause():
# [START list_incident_root_cause]
from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential, MetricsAdvisorClient
service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
incident_id = os.getenv("METRICS_ADVISOR_INCIDENT_ID")
client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
results = client.list_incident_root_causes(
detection_configuration_id=detection_configuration_id,
incident_id=incident_id,
)
for result in results:
print("Score: {}".format(result.score))
print("Description: {}".format(result.description))
# [END list_incident_root_cause]
def sample_list_incidents_for_alert():
# [START list_incidents_for_alert]
from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential, MetricsAdvisorClient
service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
alert_configuration_id = os.getenv("METRICS_ADVISOR_ALERT_CONFIGURATION_ID")
alert_id = os.getenv("METRICS_ADVISOR_ALERT_ID")
client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
results = client.list_incidents(
alert_configuration_id=alert_configuration_id,
alert_id=alert_id,
)
for result in results:
print("Metric id: {}".format(result.metric_id))
print("Incident ID: {}".format(result.id))
print("Severity: {}".format(result.severity))
print("Status: {}".format(result.status))
# [END list_incidents_for_alert]
if __name__ == '__main__':
print("---List incidents for detection configuration...")
sample_list_incidents_for_detection_configuration()
print("---List root causes...")
sample_list_incident_root_cause()
print("---List incidents for alert configuration...")
sample_list_incidents_for_alert()