CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-mgmt-costmanagement

Microsoft Azure Cost Management Client Library for Python providing comprehensive access to cost analysis, billing data, budgets, alerts, exports, and recommendations.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

alerts.mddocs/

Alerts Management

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.

Capabilities

Alert Listing and Retrieval

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
    """

Alert Management

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
    """

Usage Examples

List All Alerts for a Subscription

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("---")

Get Specific Alert Details

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}")

Dismiss Active Alerts

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}")

Monitor Budget Alerts

# 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}")

Handle External Cloud Provider Alerts

# 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}")

Data Models

Alert Models

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): ...

Alert Enumerations

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

docs

alerts.md

benefits.md

dimensions.md

exports.md

index.md

price-sheet.md

query-forecast.md

reports.md

scheduled-actions.md

views.md

tile.json