Exemplo n.º 1
0
 async def _create_alert_config_for_update(self, name):
     try:
         detection_config, data_feed = await self._create_data_feed_and_detection_config(name)
         alert_config_name = create_random_name(name)
         alert_config = await self.admin_client.create_alert_configuration(
             name=alert_config_name,
             cross_metrics_operator="AND",
             metric_alert_configurations=[
                 MetricAlertConfiguration(
                     detection_configuration_id=detection_config.id,
                     alert_scope=MetricAnomalyAlertScope(
                         scope_type="TopN",
                         top_n_group_in_scope=TopNGroupScope(
                             top=5,
                             period=10,
                             min_top_count=9
                         )
                     ),
                     alert_conditions=MetricAnomalyAlertConditions(
                         metric_boundary_condition=MetricBoundaryCondition(
                             direction="Both",
                             companion_metric_id=data_feed.metric_ids['cost'],
                             lower=1.0,
                             upper=5.0
                         )
                     )
                 ),
                 MetricAlertConfiguration(
                     detection_configuration_id=detection_config.id,
                     alert_scope=MetricAnomalyAlertScope(
                         scope_type="SeriesGroup",
                         series_group_in_scope={'city': 'Shenzhen'}
                     ),
                     alert_conditions=MetricAnomalyAlertConditions(
                         severity_condition=SeverityCondition(
                             min_alert_severity="Low",
                             max_alert_severity="High"
                         )
                     )
                 ),
                 MetricAlertConfiguration(
                     detection_configuration_id=detection_config.id,
                     alert_scope=MetricAnomalyAlertScope(
                         scope_type="WholeSeries"
                     ),
                     alert_conditions=MetricAnomalyAlertConditions(
                         severity_condition=SeverityCondition(
                             min_alert_severity="Low",
                             max_alert_severity="High"
                         )
                     )
                 )
             ],
             hook_ids=[]
         )
         return alert_config, data_feed, detection_config
     except Exception as e:
         self.admin_client.delete_data_feed(data_feed.id)
         raise e
 def create_alert_config(self, name):
     alert_config_name = self.create_random_name(name)
     if is_live():
         self.variables["alert_config_name"] = alert_config_name
     alert_config = self.client.create_alert_configuration(
         name=self.variables["alert_config_name"],
         cross_metrics_operator="AND",
         metric_alert_configurations=[
             MetricAlertConfiguration(
                 detection_configuration_id=self.variables["detection_config_id"],
                 alert_scope=MetricAnomalyAlertScope(
                     scope_type="TopN",
                     top_n_group_in_scope=TopNGroupScope(
                         top=5,
                         period=10,
                         min_top_count=9
                     )
                 ),
                 alert_conditions=MetricAnomalyAlertConditions(
                     metric_boundary_condition=MetricBoundaryCondition(
                         direction="Both",
                         companion_metric_id=self.variables["data_feed_metric_id"],
                         lower=1.0,
                         upper=5.0
                     )
                 )
             ),
             MetricAlertConfiguration(
                 detection_configuration_id=self.variables["detection_config_id"],
                 alert_scope=MetricAnomalyAlertScope(
                     scope_type="SeriesGroup",
                     series_group_in_scope={'region': 'Beijing'}
                 ),
                 alert_conditions=MetricAnomalyAlertConditions(
                     severity_condition=SeverityCondition(
                         min_alert_severity="Low",
                         max_alert_severity="High"
                     )
                 )
             ),
             MetricAlertConfiguration(
                 detection_configuration_id=self.variables["detection_config_id"],
                 alert_scope=MetricAnomalyAlertScope(
                     scope_type="WholeSeries"
                 ),
                 alert_conditions=MetricAnomalyAlertConditions(
                     severity_condition=SeverityCondition(
                         min_alert_severity="Low",
                         max_alert_severity="High"
                     )
                 )
             )
         ],
         hook_ids=[]
     )
     if is_live():
         self.variables["alert_config_id"] = alert_config.id
     return alert_config
Exemplo n.º 3
0
async def sample_create_alert_config_async():
    # [START create_alert_config_async]
    from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
    from azure.ai.metricsadvisor.aio import MetricsAdvisorAdministrationClient
    from azure.ai.metricsadvisor.models import (
        MetricAlertConfiguration,
        MetricAnomalyAlertScope,
        TopNGroupScope,
        MetricAnomalyAlertConditions,
        SeverityCondition,
        MetricBoundaryCondition,
        MetricAnomalyAlertSnoozeCondition,
    )
    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")
    hook_id = os.getenv("METRICS_ADVISOR_HOOK_ID")

    client = MetricsAdvisorAdministrationClient(
        service_endpoint, MetricsAdvisorKeyCredential(subscription_key,
                                                      api_key))

    async with client:
        alert_config = await client.create_alert_configuration(
            name="my alert config",
            description="alert config description",
            cross_metrics_operator="AND",
            metric_alert_configurations=[
                MetricAlertConfiguration(
                    detection_configuration_id=detection_configuration_id,
                    alert_scope=MetricAnomalyAlertScope(
                        scope_type="WholeSeries"),
                    alert_conditions=MetricAnomalyAlertConditions(
                        severity_condition=SeverityCondition(
                            min_alert_severity="Low",
                            max_alert_severity="High"))),
                MetricAlertConfiguration(
                    detection_configuration_id=detection_configuration_id,
                    alert_scope=MetricAnomalyAlertScope(
                        scope_type="TopN",
                        top_n_group_in_scope=TopNGroupScope(top=10,
                                                            period=5,
                                                            min_top_count=5)),
                    alert_conditions=MetricAnomalyAlertConditions(
                        metric_boundary_condition=MetricBoundaryCondition(
                            direction="Up", upper=50)),
                    alert_snooze_condition=MetricAnomalyAlertSnoozeCondition(
                        auto_snooze=2,
                        snooze_scope="Metric",
                        only_for_successive=True)),
            ],
            hook_ids=[hook_id])

        return alert_config
Exemplo n.º 4
0
async def sample_update_alert_config_async(alert_config):
    # [START update_anomaly_alert_config_async]
    from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
    from azure.ai.metricsadvisor.aio import MetricsAdvisorAdministrationClient
    from azure.ai.metricsadvisor.models import (
        MetricAlertConfiguration,
        MetricAnomalyAlertScope,
        MetricAnomalyAlertConditions,
        MetricBoundaryCondition
    )
    service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
    subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
    api_key = os.getenv("METRICS_ADVISOR_API_KEY")
    anomaly_detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")

    client = MetricsAdvisorAdministrationClient(service_endpoint,
                                  MetricsAdvisorKeyCredential(subscription_key, api_key))

    alert_config.name = "updated config name"
    additional_alert = MetricAlertConfiguration(
        detection_configuration_id=anomaly_detection_configuration_id,
        alert_scope=MetricAnomalyAlertScope(
            scope_type="SeriesGroup",
            series_group_in_scope={'city': 'Shenzhen'}
        ),
        alert_conditions=MetricAnomalyAlertConditions(
            metric_boundary_condition=MetricBoundaryCondition(
                direction="Down",
                lower=5
            )
        )
    )
    alert_config.metric_alert_configurations.append(additional_alert)

    async with client:
        updated = await client.update_anomaly_alert_configuration(
            alert_config,
            cross_metrics_operator="OR",
            description="updated alert config"
        )

        print("Updated alert name: {}".format(updated.name))
        print("Updated alert description: {}".format(updated.description))
        print("Updated cross metrics operator: {}".format(updated.cross_metrics_operator))
        print("Updated alert condition configuration scope type: {}".format(
            updated.metric_alert_configurations[2].alert_scope.scope_type
        ))