0
# Alerts Management
1
2
Monitor and manage cost alerts and budget notifications across Azure resources. Set up automated alerts for cost thresholds, budget overruns, and anomaly detection to proactively manage cloud spending.
3
4
## Capabilities
5
6
### Alert Listing and Retrieval
7
8
List and retrieve cost alerts for specific scopes including budget alerts, usage alerts, and system-generated anomaly alerts.
9
10
```python { .api }
11
def list(scope: str) -> AlertsResult:
12
"""
13
List all alerts for the specified scope.
14
15
Args:
16
scope (str): The scope to list alerts for (subscription, resource group, etc.)
17
18
Returns:
19
AlertsResult: Collection of alerts with pagination support
20
"""
21
22
def get(scope: str, alert_id: str) -> Alert:
23
"""
24
Get a specific alert by ID.
25
26
Args:
27
scope (str): The scope containing the alert
28
alert_id (str): Unique identifier of the alert
29
30
Returns:
31
Alert: Alert details and properties
32
"""
33
34
def list_external(
35
external_cloud_provider_type: str,
36
external_cloud_provider_id: str
37
) -> AlertsResult:
38
"""
39
List alerts for external cloud providers like AWS.
40
41
Args:
42
external_cloud_provider_type (str): Provider type (e.g., "aws")
43
external_cloud_provider_id (str): Provider account identifier
44
45
Returns:
46
AlertsResult: Collection of external provider alerts
47
"""
48
```
49
50
### Alert Management
51
52
Manage alert states including dismissing active alerts and handling alert notifications.
53
54
```python { .api }
55
def dismiss(scope: str, alert_id: str, parameters: DismissAlertPayload) -> Alert:
56
"""
57
Dismiss an active alert.
58
59
Args:
60
scope (str): The scope containing the alert
61
alert_id (str): Unique identifier of the alert to dismiss
62
parameters (DismissAlertPayload): Dismissal information and reason
63
64
Returns:
65
Alert: Updated alert with dismissed status
66
"""
67
```
68
69
## Usage Examples
70
71
### List All Alerts for a Subscription
72
73
```python
74
scope = "/subscriptions/{subscription-id}"
75
alerts_result = client.alerts.list(scope)
76
77
print(f"Found {len(alerts_result.value)} alerts")
78
for alert in alerts_result.value:
79
properties = alert.properties
80
print(f"Alert ID: {properties.alert_id}")
81
print(f"Type: {properties.type}")
82
print(f"Status: {properties.status}")
83
print(f"Source: {properties.source}")
84
print(f"Description: {properties.description}")
85
print(f"Created Time: {properties.creation_time}")
86
print("---")
87
```
88
89
### Get Specific Alert Details
90
91
```python
92
alert_id = "budget-alert-123"
93
alert = client.alerts.get(scope, alert_id)
94
95
properties = alert.properties
96
print(f"Alert Details:")
97
print(f" Category: {properties.category}")
98
print(f" Criteria: {properties.criteria}")
99
print(f" Status: {properties.status}")
100
print(f" Cost Entity ID: {properties.cost_entity_id}")
101
print(f" Creation Time: {properties.creation_time}")
102
print(f" Close Time: {properties.close_time}")
103
print(f" Modification Time: {properties.modification_time}")
104
105
# Check alert details if available
106
if properties.details:
107
details = properties.details
108
print(f" Current Spend: ${details.current_spend}")
109
print(f" Budget: ${details.budget}")
110
print(f" Unit: {details.unit}")
111
print(f" Threshold: {details.threshold_value}")
112
```
113
114
### Dismiss Active Alerts
115
116
```python
117
from azure.mgmt.costmanagement.models import DismissAlertPayload
118
119
# Dismiss a budget alert
120
dismiss_payload = DismissAlertPayload(
121
definition=DismissAlertDefinition(
122
type="Budget",
123
category="Cost",
124
criteria="CostThresholdExceeded"
125
)
126
)
127
128
dismissed_alert = client.alerts.dismiss(scope, alert_id, dismiss_payload)
129
print(f"Alert {alert_id} dismissed. New status: {dismissed_alert.properties.status}")
130
```
131
132
### Monitor Budget Alerts
133
134
```python
135
# Filter for budget alerts only
136
all_alerts = client.alerts.list(scope)
137
budget_alerts = [
138
alert for alert in all_alerts.value
139
if alert.properties.type == "Budget"
140
]
141
142
print(f"Budget Alerts ({len(budget_alerts)}):")
143
for alert in budget_alerts:
144
properties = alert.properties
145
if properties.details:
146
spend_percentage = (properties.details.current_spend / properties.details.budget) * 100
147
print(f" {properties.alert_id}: {spend_percentage:.1f}% of budget spent")
148
print(f" Current: ${properties.details.current_spend}")
149
print(f" Budget: ${properties.details.budget}")
150
print(f" Status: {properties.status}")
151
```
152
153
### Handle External Cloud Provider Alerts
154
155
```python
156
# List AWS alerts
157
aws_alerts = client.alerts.list_external(
158
external_cloud_provider_type="aws",
159
external_cloud_provider_id="123456789012"
160
)
161
162
print(f"AWS Alerts: {len(aws_alerts.value)}")
163
for alert in aws_alerts.value:
164
print(f" AWS Alert: {alert.properties.alert_id}")
165
print(f" Status: {alert.properties.status}")
166
print(f" Description: {alert.properties.description}")
167
```
168
169
## Data Models
170
171
### Alert Models
172
173
```python { .api }
174
class Alert:
175
id: str
176
name: str
177
type: str
178
properties: AlertPropertiesDetails
179
180
class AlertPropertiesDetails:
181
type: str
182
category: str
183
criteria: str
184
source: str
185
status: str
186
creation_time: str
187
close_time: str
188
modification_time: str
189
alert_id: str
190
description: str
191
cost_entity_id: str
192
details: AlertPropertiesDefinition
193
194
class AlertPropertiesDefinition:
195
type: str
196
category: str
197
criteria: str
198
current_spend: float
199
budget: float
200
unit: str
201
operator: str
202
threshold_value: float
203
time_grain: str
204
period_start_date: str
205
triggered_by: str
206
207
class AlertsResult:
208
value: List[Alert]
209
next_link: str
210
211
class DismissAlertPayload:
212
def __init__(self, definition: DismissAlertDefinition): ...
213
214
class DismissAlertDefinition:
215
def __init__(self, type: str, category: str, criteria: str): ...
216
```
217
218
## Alert Enumerations
219
220
```python { .api }
221
class AlertType(str, Enum):
222
BUDGET = "Budget"
223
INVOICE = "Invoice"
224
CREDIT = "Credit"
225
QUOTA = "Quota"
226
GENERAL = "General"
227
X_CLOUD = "xCloud"
228
229
class AlertCategory(str, Enum):
230
COST = "Cost"
231
USAGE = "Usage"
232
BILLING = "Billing"
233
SYSTEM = "System"
234
235
class AlertStatus(str, Enum):
236
NONE = "None"
237
ACTIVE = "Active"
238
OVERRIDDEN = "Overridden"
239
RESOLVED = "Resolved"
240
DISMISSED = "Dismissed"
241
242
class AlertCriteria(str, Enum):
243
COST_THRESHOLD_EXCEEDED = "CostThresholdExceeded"
244
USAGE_THRESHOLD_EXCEEDED = "UsageThresholdExceeded"
245
CREDIT_THRESHOLD_APPROACHING = "CreditThresholdApproaching"
246
CREDIT_THRESHOLD_REACHED = "CreditThresholdReached"
247
QUOTA_THRESHOLD_APPROACHING = "QuotaThresholdApproaching"
248
QUOTA_THRESHOLD_REACHED = "QuotaThresholdReached"
249
MULTI_CURRENCY = "MultiCurrency"
250
FORECAST_COST_THRESHOLD_EXCEEDED = "ForecastCostThresholdExceeded"
251
FORECAST_USAGE_THRESHOLD_EXCEEDED = "ForecastUsageThresholdExceeded"
252
INVOICE_DUE_DATE_APPROACHING = "InvoiceDueDateApproaching"
253
INVOICE_DUE_DATE_REACHED = "InvoiceDueDateReached"
254
CROSS_CLOUD_NEW_DATA_AVAILABLE = "CrossCloudNewDataAvailable"
255
CROSS_CLOUD_COLLECTION_ERROR = "CrossCloudCollectionError"
256
GENERAL = "General"
257
258
class AlertSource(str, Enum):
259
PRESET = "Preset"
260
USER = "User"
261
262
class AlertOperator(str, Enum):
263
NONE = "None"
264
EQUAL_TO = "EqualTo"
265
GREATER_THAN = "GreaterThan"
266
GREATER_THAN_OR_EQUAL_TO = "GreaterThanOrEqualTo"
267
LESS_THAN = "LessThan"
268
LESS_THAN_OR_EQUAL_TO = "LessThanOrEqualTo"
269
270
class AlertTimeGrainType(str, Enum):
271
NONE = "None"
272
MONTHLY = "Monthly"
273
QUARTERLY = "Quarterly"
274
ANNUALLY = "Annually"
275
BILLING_MONTH = "BillingMonth"
276
BILLING_QUARTER = "BillingQuarter"
277
BILLING_ANNUAL = "BillingAnnual"
278
```
279
280
This module provides comprehensive alert management capabilities for proactive cost monitoring and budget management across Azure and external cloud resources.