def sample_get_alert_config(alert_config_id): # [START get_anomaly_alert_config] from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential, MetricsAdvisorAdministrationClient service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT") subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY") api_key = os.getenv("METRICS_ADVISOR_API_KEY") client = MetricsAdvisorAdministrationClient( service_endpoint, MetricsAdvisorKeyCredential(subscription_key, api_key)) config = client.get_anomaly_alert_configuration(alert_config_id) print("Alert config ID: {}".format(config.id)) print("Alert config name: {}".format(config.name)) print("Description: {}".format(config.description)) print("Ids of hooks associated with alert: {}".format(config.hook_ids)) print("Use {} operator for multiple alert conditions\n".format( config.cross_metrics_operator)) print("Alert uses detection configuration ID: {}".format( config.metric_alert_configurations[0].detection_configuration_id)) print("Alert scope type: {}".format( config.metric_alert_configurations[0].alert_scope.scope_type)) print("Alert severity condition: min- {}, max- {}".format( config.metric_alert_configurations[0].alert_conditions. severity_condition.min_alert_severity, config.metric_alert_configurations[0].alert_conditions. severity_condition.max_alert_severity, )) print("\nAlert uses detection configuration ID: {}".format( config.metric_alert_configurations[1].detection_configuration_id)) print("Alert scope type: {}".format( config.metric_alert_configurations[1].alert_scope.scope_type)) print("Top N: {}".format(config.metric_alert_configurations[1].alert_scope. top_n_group_in_scope.top)) print("Point count used to look back: {}".format( config.metric_alert_configurations[1].alert_scope.top_n_group_in_scope. period)) print("Min top count: {}".format( config.metric_alert_configurations[1].alert_scope.top_n_group_in_scope. min_top_count)) print("Alert metric boundary condition direction: {}, upper bound: {}". format( config.metric_alert_configurations[1].alert_conditions. metric_boundary_condition.direction, config.metric_alert_configurations[1].alert_conditions. metric_boundary_condition.upper, )) print("Alert snooze condition, snooze point count: {}".format( config.metric_alert_configurations[1].alert_snooze_condition. auto_snooze, )) print("Alert snooze scope: {}".format( config.metric_alert_configurations[1].alert_snooze_condition. snooze_scope, )) print("Snooze only for successive anomalies?: {}".format( config.metric_alert_configurations[1].alert_snooze_condition. only_for_successive, ))
def sample_delete_alert_config(alert_config_id): # [START delete_anomaly_alert_config] from azure.core.exceptions import ResourceNotFoundError from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential, MetricsAdvisorAdministrationClient service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT") subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY") api_key = os.getenv("METRICS_ADVISOR_API_KEY") client = MetricsAdvisorAdministrationClient( service_endpoint, MetricsAdvisorKeyCredential(subscription_key, api_key)) client.delete_anomaly_alert_configuration(alert_config_id) try: client.get_anomaly_alert_configuration(alert_config_id) except ResourceNotFoundError: print("Alert configuration successfully deleted.")