Microsoft Azure Cost Management Client Library for Python providing comprehensive access to cost analysis, billing data, budgets, alerts, exports, and recommendations.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
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.
List and retrieve cost alerts for specific scopes including budget alerts, usage alerts, and system-generated anomaly alerts.
def list(scope: str) -> AlertsResult:
"""
List all alerts for the specified scope.
Args:
scope (str): The scope to list alerts for (subscription, resource group, etc.)
Returns:
AlertsResult: Collection of alerts with pagination support
"""
def get(scope: str, alert_id: str) -> Alert:
"""
Get a specific alert by ID.
Args:
scope (str): The scope containing the alert
alert_id (str): Unique identifier of the alert
Returns:
Alert: Alert details and properties
"""
def list_external(
external_cloud_provider_type: str,
external_cloud_provider_id: str
) -> AlertsResult:
"""
List alerts for external cloud providers like AWS.
Args:
external_cloud_provider_type (str): Provider type (e.g., "aws")
external_cloud_provider_id (str): Provider account identifier
Returns:
AlertsResult: Collection of external provider alerts
"""Manage alert states including dismissing active alerts and handling alert notifications.
def dismiss(scope: str, alert_id: str, parameters: DismissAlertPayload) -> Alert:
"""
Dismiss an active alert.
Args:
scope (str): The scope containing the alert
alert_id (str): Unique identifier of the alert to dismiss
parameters (DismissAlertPayload): Dismissal information and reason
Returns:
Alert: Updated alert with dismissed status
"""scope = "/subscriptions/{subscription-id}"
alerts_result = client.alerts.list(scope)
print(f"Found {len(alerts_result.value)} alerts")
for alert in alerts_result.value:
properties = alert.properties
print(f"Alert ID: {properties.alert_id}")
print(f"Type: {properties.type}")
print(f"Status: {properties.status}")
print(f"Source: {properties.source}")
print(f"Description: {properties.description}")
print(f"Created Time: {properties.creation_time}")
print("---")alert_id = "budget-alert-123"
alert = client.alerts.get(scope, alert_id)
properties = alert.properties
print(f"Alert Details:")
print(f" Category: {properties.category}")
print(f" Criteria: {properties.criteria}")
print(f" Status: {properties.status}")
print(f" Cost Entity ID: {properties.cost_entity_id}")
print(f" Creation Time: {properties.creation_time}")
print(f" Close Time: {properties.close_time}")
print(f" Modification Time: {properties.modification_time}")
# Check alert details if available
if properties.details:
details = properties.details
print(f" Current Spend: ${details.current_spend}")
print(f" Budget: ${details.budget}")
print(f" Unit: {details.unit}")
print(f" Threshold: {details.threshold_value}")from azure.mgmt.costmanagement.models import DismissAlertPayload
# Dismiss a budget alert
dismiss_payload = DismissAlertPayload(
definition=DismissAlertDefinition(
type="Budget",
category="Cost",
criteria="CostThresholdExceeded"
)
)
dismissed_alert = client.alerts.dismiss(scope, alert_id, dismiss_payload)
print(f"Alert {alert_id} dismissed. New status: {dismissed_alert.properties.status}")# Filter for budget alerts only
all_alerts = client.alerts.list(scope)
budget_alerts = [
alert for alert in all_alerts.value
if alert.properties.type == "Budget"
]
print(f"Budget Alerts ({len(budget_alerts)}):")
for alert in budget_alerts:
properties = alert.properties
if properties.details:
spend_percentage = (properties.details.current_spend / properties.details.budget) * 100
print(f" {properties.alert_id}: {spend_percentage:.1f}% of budget spent")
print(f" Current: ${properties.details.current_spend}")
print(f" Budget: ${properties.details.budget}")
print(f" Status: {properties.status}")# List AWS alerts
aws_alerts = client.alerts.list_external(
external_cloud_provider_type="aws",
external_cloud_provider_id="123456789012"
)
print(f"AWS Alerts: {len(aws_alerts.value)}")
for alert in aws_alerts.value:
print(f" AWS Alert: {alert.properties.alert_id}")
print(f" Status: {alert.properties.status}")
print(f" Description: {alert.properties.description}")class Alert:
id: str
name: str
type: str
properties: AlertPropertiesDetails
class AlertPropertiesDetails:
type: str
category: str
criteria: str
source: str
status: str
creation_time: str
close_time: str
modification_time: str
alert_id: str
description: str
cost_entity_id: str
details: AlertPropertiesDefinition
class AlertPropertiesDefinition:
type: str
category: str
criteria: str
current_spend: float
budget: float
unit: str
operator: str
threshold_value: float
time_grain: str
period_start_date: str
triggered_by: str
class AlertsResult:
value: List[Alert]
next_link: str
class DismissAlertPayload:
def __init__(self, definition: DismissAlertDefinition): ...
class DismissAlertDefinition:
def __init__(self, type: str, category: str, criteria: str): ...class AlertType(str, Enum):
BUDGET = "Budget"
INVOICE = "Invoice"
CREDIT = "Credit"
QUOTA = "Quota"
GENERAL = "General"
X_CLOUD = "xCloud"
class AlertCategory(str, Enum):
COST = "Cost"
USAGE = "Usage"
BILLING = "Billing"
SYSTEM = "System"
class AlertStatus(str, Enum):
NONE = "None"
ACTIVE = "Active"
OVERRIDDEN = "Overridden"
RESOLVED = "Resolved"
DISMISSED = "Dismissed"
class AlertCriteria(str, Enum):
COST_THRESHOLD_EXCEEDED = "CostThresholdExceeded"
USAGE_THRESHOLD_EXCEEDED = "UsageThresholdExceeded"
CREDIT_THRESHOLD_APPROACHING = "CreditThresholdApproaching"
CREDIT_THRESHOLD_REACHED = "CreditThresholdReached"
QUOTA_THRESHOLD_APPROACHING = "QuotaThresholdApproaching"
QUOTA_THRESHOLD_REACHED = "QuotaThresholdReached"
MULTI_CURRENCY = "MultiCurrency"
FORECAST_COST_THRESHOLD_EXCEEDED = "ForecastCostThresholdExceeded"
FORECAST_USAGE_THRESHOLD_EXCEEDED = "ForecastUsageThresholdExceeded"
INVOICE_DUE_DATE_APPROACHING = "InvoiceDueDateApproaching"
INVOICE_DUE_DATE_REACHED = "InvoiceDueDateReached"
CROSS_CLOUD_NEW_DATA_AVAILABLE = "CrossCloudNewDataAvailable"
CROSS_CLOUD_COLLECTION_ERROR = "CrossCloudCollectionError"
GENERAL = "General"
class AlertSource(str, Enum):
PRESET = "Preset"
USER = "User"
class AlertOperator(str, Enum):
NONE = "None"
EQUAL_TO = "EqualTo"
GREATER_THAN = "GreaterThan"
GREATER_THAN_OR_EQUAL_TO = "GreaterThanOrEqualTo"
LESS_THAN = "LessThan"
LESS_THAN_OR_EQUAL_TO = "LessThanOrEqualTo"
class AlertTimeGrainType(str, Enum):
NONE = "None"
MONTHLY = "Monthly"
QUARTERLY = "Quarterly"
ANNUALLY = "Annually"
BILLING_MONTH = "BillingMonth"
BILLING_QUARTER = "BillingQuarter"
BILLING_ANNUAL = "BillingAnnual"This module provides comprehensive alert management capabilities for proactive cost monitoring and budget management across Azure and external cloud resources.
Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-costmanagement