Exemplo n.º 1
0
        public async Task CreateAndDeleteAnomalyAlertConfigurationAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential);

            string hookId = HookId;
            string anomalyDetectionConfigurationId = DetectionConfigurationId;

            #region Snippet:CreateAnomalyAlertConfigurationAsync
            //@@ string hookId = "<hookId>";
            //@@ string anomalyDetectionConfigurationId = "<anomalyDetectionConfigurationId>";

            string configurationName = "Sample anomaly alert configuration";
            var    idsOfHooksToAlert = new List <string>()
            {
                hookId
            };

            var scope = MetricAnomalyAlertScope.GetScopeForWholeSeries();
            var metricAlertConfigurations = new List <MetricAnomalyAlertConfiguration>()
            {
                new MetricAnomalyAlertConfiguration(anomalyDetectionConfigurationId, scope)
            };

            AnomalyAlertConfiguration alertConfiguration = new AnomalyAlertConfiguration(configurationName, idsOfHooksToAlert, metricAlertConfigurations);

            Response <AnomalyAlertConfiguration> response = await adminClient.CreateAnomalyAlertConfigurationAsync(alertConfiguration);

            alertConfiguration = response.Value;

            Console.WriteLine($"Alert configuration ID: {alertConfiguration.Id}");
            #endregion

            // Delete the anomaly alert configuration to clean up the Metrics Advisor resource. Do not
            // perform this step if you intend to keep using the configuration.

            await adminClient.DeleteAnomalyAlertConfigurationAsync(alertConfiguration.Id);
        }