public async Task UpdateEmailNotificationHookWithMinimumSetupAndNewInstance()
        {
            // Create a hook.

            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            string hookName = Recording.GenerateAlphaNumericId("hook");

            var hookToCreate = new EmailNotificationHook()
            {
                Name          = hookName,
                EmailsToAlert = { "*****@*****.**", "*****@*****.**" }
            };

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            // Update the created hook.

            var hookToUpdate = new EmailNotificationHook();

            hookToUpdate.EmailsToAlert.Add("*****@*****.**");

            var updatedEmailHook = (await adminClient.UpdateHookAsync(hookToUpdate)).Value as EmailNotificationHook;

            // Check if updates are in place.

            Assert.That(updatedEmailHook.Id, Is.EqualTo(hookToUpdate.Id));
            Assert.That(updatedEmailHook.Name, Is.EqualTo(hookName));
            Assert.That(updatedEmailHook.Description, Is.Empty);
            Assert.That(updatedEmailHook.ExternalLink, Is.Null);
            Assert.That(updatedEmailHook.AdministratorsEmails, Is.Not.Null);
            Assert.That(updatedEmailHook.AdministratorsEmails.Single(), Is.Not.Null.And.Not.Empty);
            Assert.That(updatedEmailHook.EmailsToAlert.Single(), Is.EqualTo("*****@*****.**"));
        }
        public async Task CreateAndDeleteHookAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

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

            #region Snippet:CreateHookAsync
            string hookName = "Sample hook";

            var emailHook = new EmailNotificationHook()
            {
                Name = hookName
            };

            emailHook.EmailsToAlert.Add("*****@*****.**");
            emailHook.EmailsToAlert.Add("*****@*****.**");

            Response <NotificationHook> response = await adminClient.CreateHookAsync(emailHook);

            NotificationHook createdHook = response.Value;

            Console.WriteLine($"Hook ID: {createdHook.Id}");
            #endregion

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

            await adminClient.DeleteHookAsync(createdHook.Id);
        }
        public async Task CreateAndGetEmailNotificationHookWithMinimumSetup(bool useTokenCredential)
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential);

            string hookName = Recording.GenerateAlphaNumericId("hook");

            var hookToCreate = new EmailNotificationHook()
            {
                Name          = hookName,
                EmailsToAlert = { "*****@*****.**", "*****@*****.**" }
            };

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            NotificationHook createdHook = disposableHook.Hook;

            Assert.That(createdHook.Id, Is.Not.Null.And.Not.Empty);
            Assert.That(createdHook.Name, Is.EqualTo(hookName));
            Assert.That(createdHook.Description, Is.Empty);
            Assert.That(createdHook.ExternalLink, Is.Null);
            Assert.That(createdHook.AdministratorsEmails, Is.Not.Null);
            Assert.That(createdHook.AdministratorsEmails.Single(), Is.Not.Null.And.Not.Empty);

            var createdEmailHook = createdHook as EmailNotificationHook;

            Assert.That(createdEmailHook, Is.Not.Null);
            Assert.That(createdEmailHook.EmailsToAlert.Count, Is.EqualTo(2));
            Assert.That(createdEmailHook.EmailsToAlert.Contains("*****@*****.**"));
            Assert.That(createdEmailHook.EmailsToAlert.Contains("*****@*****.**"));
        }
        public async Task CreateAndGetEmailNotificationHookWithMinimumSetup()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            string hookName      = Recording.GenerateAlphaNumericId("hook");
            var    emailsToAlert = new List <string>()
            {
                "*****@*****.**", "*****@*****.**"
            };

            var hookToCreate = new EmailNotificationHook(hookName, emailsToAlert);

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            NotificationHook createdHook = await adminClient.GetHookAsync(disposableHook.Id);

            Assert.That(createdHook.Id, Is.EqualTo(disposableHook.Id));
            Assert.That(createdHook.Name, Is.EqualTo(hookName));
            Assert.That(createdHook.Description, Is.Empty);
            Assert.That(createdHook.ExternalLink, Is.Empty);
            Assert.That(createdHook.Administrators, Is.Not.Null);
            Assert.That(createdHook.Administrators.Single(), Is.Not.Null.And.Not.Empty);

            var createdEmailHook = createdHook as EmailNotificationHook;

            Assert.That(createdEmailHook, Is.Not.Null);
            Assert.That(createdEmailHook.EmailsToAlert, Is.EquivalentTo(emailsToAlert));
        }
        public async Task CreateAndGetEmailNotificationHookWithOptionalMembers()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            string hookName    = Recording.GenerateAlphaNumericId("hook");
            var    description = "This hook was created to test the .NET client.";

            var hookToCreate = new EmailNotificationHook()
            {
                Name          = hookName,
                EmailsToAlert = { "*****@*****.**", "*****@*****.**" },
                Description   = description,
                ExternalLink  = new Uri("http://fake.endpoint.com/")
            };

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            NotificationHook createdHook = disposableHook.Hook;

            Assert.That(createdHook.Id, Is.Not.Null.And.Not.Empty);
            Assert.That(createdHook.Name, Is.EqualTo(hookName));
            Assert.That(createdHook.Description, Is.EqualTo(description));
            Assert.That(createdHook.ExternalLink.AbsoluteUri, Is.EqualTo("http://fake.endpoint.com/"));
            Assert.That(createdHook.AdministratorsEmails, Is.Not.Null);
            Assert.That(createdHook.AdministratorsEmails.Single(), Is.Not.Null.And.Not.Empty);

            var createdEmailHook = createdHook as EmailNotificationHook;

            Assert.That(createdEmailHook, Is.Not.Null);
            Assert.That(createdEmailHook.EmailsToAlert.Count, Is.EqualTo(2));
            Assert.That(createdEmailHook.EmailsToAlert.Contains("*****@*****.**"));
            Assert.That(createdEmailHook.EmailsToAlert.Contains("*****@*****.**"));
        }
        public async Task DeleteNotificationHook(bool useTokenCredential)
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential);

            string hookName     = Recording.GenerateAlphaNumericId("hook");
            var    hookToCreate = new EmailNotificationHook()
            {
                Name = hookName, EmailsToAlert = { "*****@*****.**" }
            };

            string hookId = null;

            try
            {
                NotificationHook createdHook = await adminClient.CreateHookAsync(hookToCreate);

                hookId = createdHook.Id;

                Assert.That(hookId, Is.Not.Null.And.Not.Empty);
            }
            finally
            {
                if (hookId != null)
                {
                    await adminClient.DeleteHookAsync(hookId);

                    var errorCause = "hookId is invalid";
                    Assert.That(async() => await adminClient.GetHookAsync(hookId), Throws.InstanceOf <RequestFailedException>().With.Message.Contains(errorCause));
                }
            }
        }
Beispiel #7
0
        public async Task HookOperations()
        {
            var adminClient = GetMetricsAdvisorAdministrationClient();

            NotificationHook createdEmailHook = await adminClient.CreateHookAsync(new EmailNotificationHook(Recording.GenerateAlphaNumericId("test"), new List <string> {
                "*****@*****.**"
            }) { Description = $"{nameof(EmailNotificationHook)} description" }).ConfigureAwait(false);

            EmailNotificationHook getEmailHook = (await adminClient.GetHookAsync(createdEmailHook.Id).ConfigureAwait(false)).Value as EmailNotificationHook;

            getEmailHook.Description = "updated description";
            getEmailHook.EmailsToAlert.Add($"{Recording.GenerateAlphaNumericId("user")}@contoso.com");

            await adminClient.UpdateHookAsync(getEmailHook.Id, getEmailHook).ConfigureAwait(false);

            NotificationHook createdWebHook = await adminClient.CreateHookAsync(new WebNotificationHook(Recording.GenerateAlphaNumericId("test"), "http://contoso.com") { Description = $"{nameof(WebNotificationHook)} description" }).ConfigureAwait(false);

            createdWebHook.Description = "updated description";

            await adminClient.UpdateHookAsync(createdEmailHook.Id, createdEmailHook).ConfigureAwait(false);

            WebNotificationHook getWebHook = (await adminClient.GetHookAsync(createdWebHook.Id).ConfigureAwait(false)).Value as WebNotificationHook;

            getWebHook.Description    = "updated description";
            getWebHook.CertificateKey = Recording.GenerateAlphaNumericId("key");

            List <NotificationHook> hooks = await adminClient.GetHooksAsync(new GetHooksOptions { HookNameFilter = getWebHook.Name }).ToEnumerableAsync().ConfigureAwait(false);

            Assert.That(getEmailHook.Id, Is.EqualTo(createdEmailHook.Id));
            Assert.That(getEmailHook.Name, Is.EqualTo(createdEmailHook.Name));
            Assert.That(hooks, Is.Not.Empty);
            Assert.That(hooks.Any(h => h.Name == getWebHook.Name), $"hooks should contain name {createdEmailHook.Name}, but contained names: {string.Join(",", hooks.Select(h => h.Name))}");

            await adminClient.DeleteHookAsync(createdEmailHook.Id).ConfigureAwait(false);
        }
        public void CreateHookValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var name     = "hookName";
            var endpoint = new Uri("http://fakeendpoint.com");

            var emailHook = new EmailNotificationHook(name)
            {
                Name = null, EmailsToAlert = { "*****@*****.**" }
            };
            var webHook = new WebNotificationHook(name, endpoint)
            {
                Name = null
            };

            Assert.That(() => adminClient.CreateHookAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateHook(null), Throws.InstanceOf <ArgumentNullException>());

            Assert.That(() => adminClient.CreateHookAsync(emailHook), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateHook(emailHook), Throws.InstanceOf <ArgumentNullException>());

            emailHook.Name = "";
            Assert.That(() => adminClient.CreateHookAsync(emailHook), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.CreateHook(emailHook), Throws.InstanceOf <ArgumentException>());

            Assert.That(() => adminClient.CreateHookAsync(webHook), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateHook(webHook), Throws.InstanceOf <ArgumentNullException>());

            webHook.Name = "";
            Assert.That(() => adminClient.CreateHookAsync(webHook), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.CreateHook(webHook), Throws.InstanceOf <ArgumentException>());
        }
        public async Task GetHooksWithOptionalNameFilter()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            string hookName       = Recording.GenerateAlphaNumericId("hook");
            string hookNameFilter = hookName.Substring(1, hookName.Length - 3);
            var    hookToCreate   = new EmailNotificationHook()
            {
                Name = hookName, EmailsToAlert = { "*****@*****.**" }
            };

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            var options = new GetHooksOptions()
            {
                HookNameFilter = hookNameFilter
            };

            var hookCount = 0;

            await foreach (NotificationHook hook in adminClient.GetHooksAsync(options))
            {
                Assert.That(hook.Id, Is.Not.Null.And.Not.Empty);
                Assert.That(hook.Name, Is.Not.Null.And.Not.Empty);
                Assert.That(hook.Name.Contains(hookNameFilter));
                Assert.That(hook.AdministratorsEmails, Is.Not.Null.And.Not.Empty);
                Assert.That(hook.AdministratorsEmails.Any(admin => admin == null || admin == string.Empty), Is.False);
                Assert.That(hook.Description, Is.Not.Null);

                if (hook is EmailNotificationHook)
                {
                    var emailHook = hook as EmailNotificationHook;

                    Assert.That(emailHook.EmailsToAlert, Is.Not.Null);
                }
                else
                {
                    var webHook = hook as WebNotificationHook;

                    Assert.That(webHook, Is.Not.Null);
                    Assert.That(webHook.CertificateKey, Is.Not.Null);
                    Assert.That(webHook.CertificatePassword, Is.Not.Null);
                    Assert.That(webHook.Username, Is.Not.Null);
                    Assert.That(webHook.Password, Is.Not.Null);
                    Assert.That(webHook.Headers, Is.Not.Null);
                    Assert.That(webHook.Headers.Values.Any(value => value == null), Is.False);
                }

                if (++hookCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(hookCount, Is.GreaterThan(0));
        }
Beispiel #10
0
        public void UpdateHookValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            Assert.That(() => adminClient.UpdateHookAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.UpdateHook(null), Throws.InstanceOf <ArgumentNullException>());

            var hookWithNullId = new EmailNotificationHook("hookName");

            Assert.That(() => adminClient.UpdateHookAsync(hookWithNullId), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.UpdateHook(hookWithNullId), Throws.InstanceOf <ArgumentNullException>());
        }
Beispiel #11
0
        public void UpdateHookRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var hook = new EmailNotificationHook();

            using var cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            Assert.That(() => adminClient.UpdateHookAsync(FakeGuid, hook, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.UpdateHook(FakeGuid, hook, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
Beispiel #12
0
        public void CreateHookRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var hook = new EmailNotificationHook("hookName")
            {
                EmailsToAlert = { "*****@*****.**" }
            };

            using var cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            Assert.That(() => adminClient.CreateHookAsync(hook, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.CreateHook(hook, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
Beispiel #13
0
        public void UpdateHookValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var hook = new EmailNotificationHook();

            Assert.That(() => adminClient.UpdateHookAsync(null, hook), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.UpdateHookAsync("", hook), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.UpdateHookAsync("hookId", hook), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
            Assert.That(() => adminClient.UpdateHookAsync(FakeGuid, null), Throws.InstanceOf <ArgumentNullException>());

            Assert.That(() => adminClient.UpdateHook(null, hook), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.UpdateHook("", hook), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.UpdateHook("hookId", hook), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
            Assert.That(() => adminClient.UpdateHook(FakeGuid, null), Throws.InstanceOf <ArgumentNullException>());
        }
        public async Task UpdateEmailNotificationHookWithEveryMemberAndNewInstance()
        {
            // Create a hook.

            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            string hookName      = Recording.GenerateAlphaNumericId("hook");
            var    emailsToAlert = new List <string>()
            {
                "*****@*****.**", "*****@*****.**"
            };
            var description = "This hook was created to test the .NET client.";

            var hookToCreate = new EmailNotificationHook(hookName, emailsToAlert);

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            // Update the created hook.

            var hookToUpdate = new EmailNotificationHook(hookName, emailsToAlert);

            hookToUpdate.Description  = description;
            hookToUpdate.ExternalLink = "http://fake.endpoint.com";
            hookToUpdate.EmailsToAlert.Add("*****@*****.**");

            await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);

            // Get the hook and check if updates are in place.

            var updatedEmailHook = (await adminClient.GetHookAsync(disposableHook.Id)).Value as EmailNotificationHook;

            Assert.That(updatedEmailHook.Id, Is.EqualTo(disposableHook.Id));
            Assert.That(updatedEmailHook.Name, Is.EqualTo(hookName));
            Assert.That(updatedEmailHook.Description, Is.EqualTo(description));
            Assert.That(updatedEmailHook.ExternalLink, Is.EqualTo("http://fake.endpoint.com"));
            Assert.That(updatedEmailHook.Administrators, Is.Not.Null);
            Assert.That(updatedEmailHook.Administrators.Single(), Is.Not.Null.And.Not.Empty);

            var expectedEmailsToAlert = new List <string>()
            {
                "*****@*****.**", "*****@*****.**", "*****@*****.**"
            };

            Assert.That(updatedEmailHook.EmailsToAlert, Is.EquivalentTo(expectedEmailsToAlert));
        }
Beispiel #15
0
        public async Task GetHooksWithMinimumSetup(bool useTokenCredential)
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential);

            string hookName     = Recording.GenerateAlphaNumericId("hook");
            var    hookToCreate = new EmailNotificationHook(hookName)
            {
                EmailsToAlert = { "*****@*****.**" }
            };

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            var hookCount = 0;

            await foreach (NotificationHook hook in adminClient.GetHooksAsync())
            {
                Assert.That(hook.Id, Is.Not.Null.And.Not.Empty);
                Assert.That(hook.Name, Is.Not.Null.And.Not.Empty);
                Assert.That(hook.Administrators, Is.Not.Null.And.Not.Empty);
                Assert.That(hook.Administrators.Any(admin => admin == null || admin == string.Empty), Is.False);
                Assert.That(hook.Description, Is.Not.Null);

                if (hook is EmailNotificationHook)
                {
                    var emailHook = hook as EmailNotificationHook;

                    Assert.That(emailHook.EmailsToAlert, Is.Not.Null);
                }
                else
                {
                    var webHook = hook as WebNotificationHook;

                    Assert.That(webHook, Is.Not.Null);
                    Assert.That(webHook.Headers, Is.Not.Null);
                    Assert.That(webHook.Headers.Values.Any(value => value == null), Is.False);
                }

                if (++hookCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(hookCount, Is.GreaterThan(0));
        }
Beispiel #16
0
        public async Task UpdateEmailNotificationHookWithMinimumSetupAndGetInstance(bool useTokenCredential)
        {
            // Create a hook.

            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential);

            string hookName      = Recording.GenerateAlphaNumericId("hook");
            var    emailsToAlert = new List <string>()
            {
                "*****@*****.**", "*****@*****.**"
            };

            var hookToCreate = new EmailNotificationHook(hookName, emailsToAlert);

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            // Update the created hook.

            var hookToUpdate = (await adminClient.GetHookAsync(disposableHook.Id)).Value as EmailNotificationHook;

            hookToUpdate.EmailsToAlert.Add("*****@*****.**");

            await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);

            // Get the hook and check if updates are in place.

            var updatedEmailHook = (await adminClient.GetHookAsync(disposableHook.Id)).Value as EmailNotificationHook;

            Assert.That(updatedEmailHook.Id, Is.EqualTo(disposableHook.Id));
            Assert.That(updatedEmailHook.Name, Is.EqualTo(hookName));
            Assert.That(updatedEmailHook.Description, Is.Empty);
            Assert.That(updatedEmailHook.ExternalLink, Is.Empty);
            Assert.That(updatedEmailHook.Administrators, Is.Not.Null);
            Assert.That(updatedEmailHook.Administrators.Single(), Is.Not.Null.And.Not.Empty);

            var expectedEmailsToAlert = new List <string>()
            {
                "*****@*****.**", "*****@*****.**", "*****@*****.**"
            };

            Assert.That(updatedEmailHook.EmailsToAlert, Is.EquivalentTo(expectedEmailsToAlert));
        }
Beispiel #17
0
        public async Task GetHookAsync()
        {
            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;

            Response <NotificationHook> response = await adminClient.GetHookAsync(hookId);

            NotificationHook hook = response.Value;

            Console.WriteLine($"Hook name: {hook.Name}");
            Console.WriteLine($"Hook description: {hook.Description}");

            Console.WriteLine($"Hook administrators emails:");
            foreach (string admin in hook.AdministratorsEmails)
            {
                Console.WriteLine($" - {admin}");
            }

            if (hook.HookType == HookType.Email)
            {
                EmailNotificationHook emailHook = hook as EmailNotificationHook;

                Console.WriteLine("Emails to alert:");
                foreach (string email in emailHook.EmailsToAlert)
                {
                    Console.WriteLine($" - {email}");
                }
            }
            else if (hook.HookType == HookType.Webhook)
            {
                WebNotificationHook webHook = hook as WebNotificationHook;

                Console.WriteLine($"Username: {webHook.Username}");
            }
        }
        public async Task UpdateEmailNotificationHookWithEveryMemberAndNewInstance()
        {
            // Create a hook.

            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            string hookName    = Recording.GenerateAlphaNumericId("hook");
            var    description = "This hook was created to test the .NET client.";

            var hookToCreate = new EmailNotificationHook()
            {
                Name          = hookName,
                EmailsToAlert = { "*****@*****.**", "*****@*****.**" }
            };

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            // Update the created hook.

            var hookToUpdate = new EmailNotificationHook()
            {
                Description  = description,
                ExternalLink = new Uri("http://fake.endpoint.com/")
            };

            hookToUpdate.EmailsToAlert.Add("*****@*****.**");

            var updatedEmailHook = (await adminClient.UpdateHookAsync(hookToUpdate)).Value as EmailNotificationHook;

            // Check if updates are in place.

            Assert.That(updatedEmailHook.Id, Is.EqualTo(hookToUpdate.Id));
            Assert.That(updatedEmailHook.Name, Is.EqualTo(hookName));
            Assert.That(updatedEmailHook.Description, Is.EqualTo(description));
            Assert.That(updatedEmailHook.ExternalLink.AbsoluteUri, Is.EqualTo("http://fake.endpoint.com/"));
            Assert.That(updatedEmailHook.AdministratorsEmails, Is.Not.Null);
            Assert.That(updatedEmailHook.AdministratorsEmails.Single(), Is.Not.Null.And.Not.Empty);
            Assert.That(updatedEmailHook.EmailsToAlert.Single(), Is.EqualTo("*****@*****.**"));
        }
Beispiel #19
0
        public async Task CreateAndGetAlertConfigurationWithOptionalSingleMetricConfigurationMembers()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient);

            string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName];

            await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId);

            string hookName0 = Recording.GenerateAlphaNumericId("hook");
            string hookName1 = Recording.GenerateAlphaNumericId("hook");

            var hookToCreate0 = new EmailNotificationHook(hookName0);
            var hookToCreate1 = new EmailNotificationHook(hookName1);

            hookToCreate0.EmailsToAlert.Add("*****@*****.**");
            hookToCreate1.EmailsToAlert.Add("*****@*****.**");

            await using var disposableHook0 = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate0);

            await using var disposableHook1 = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate1);

            var detectionConfigId = disposableDetectionConfig.Configuration.Id;
            var scope             = MetricAnomalyAlertScope.GetScopeForWholeSeries();
            var metricAlertConfig = new MetricAnomalyAlertConfiguration(detectionConfigId, scope)
            {
                AlertSnoozeCondition = new MetricAnomalyAlertSnoozeCondition(12, SnoozeScope.Series, true),
                AlertConditions      = new MetricAnomalyAlertConditions()
                {
                    MetricBoundaryCondition = new MetricBoundaryCondition(BoundaryDirection.Both)
                    {
                        UpperBound                    = 20.0,
                        LowerBound                    = 10.0,
                        CompanionMetricId             = metricId,
                        ShouldAlertIfDataPointMissing = true
                    },
                    SeverityCondition = new SeverityCondition(AnomalySeverity.Low, AnomalySeverity.Medium)
                }
            };

            string configName  = Recording.GenerateAlphaNumericId("config");
            var    description = "This hook was created to test the .NET client.";

            var configToCreate = new AnomalyAlertConfiguration()
            {
                Name = configName,
                IdsOfHooksToAlert         = { disposableHook0.Hook.Id, disposableHook1.Hook.Id },
                MetricAlertConfigurations = { metricAlertConfig },
                Description = description
            };

            await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate);

            AnomalyAlertConfiguration createdConfig = disposableConfig.Configuration;

            Assert.That(createdConfig.Id, Is.Not.Null.And.Not.Empty);
            Assert.That(createdConfig.Name, Is.EqualTo(configName));
            Assert.That(createdConfig.Description, Is.EqualTo(description));
            Assert.That(createdConfig.CrossMetricsOperator, Is.Null);
            Assert.That(createdConfig.IdsOfHooksToAlert.Count, Is.EqualTo(2));
            Assert.That(createdConfig.IdsOfHooksToAlert.Contains(disposableHook0.Hook.Id));
            Assert.That(createdConfig.IdsOfHooksToAlert.Contains(disposableHook1.Hook.Id));
            Assert.That(createdConfig.MetricAlertConfigurations, Is.Not.Null);

            MetricAnomalyAlertConfiguration createdMetricAlertConfig = createdConfig.MetricAlertConfigurations.Single();

            Assert.That(createdMetricAlertConfig.DetectionConfigurationId, Is.EqualTo(detectionConfigId));

            Assert.That(createdMetricAlertConfig.AlertScope, Is.Not.Null);
            Assert.That(createdMetricAlertConfig.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries));
            Assert.That(createdMetricAlertConfig.AlertScope.SeriesGroupInScope, Is.Null);
            Assert.That(createdMetricAlertConfig.AlertScope.TopNGroupInScope, Is.Null);

            Assert.That(createdMetricAlertConfig.AlertConditions, Is.Not.Null);
            Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition, Is.Not.Null);
            Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.Direction, Is.EqualTo(BoundaryDirection.Both));
            Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.UpperBound, Is.EqualTo(20.0));
            Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.LowerBound, Is.EqualTo(10.0));
            Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.CompanionMetricId, Is.EqualTo(metricId));
            Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing, Is.True);
            Assert.That(createdMetricAlertConfig.AlertConditions.SeverityCondition, Is.Not.Null);
            Assert.That(createdMetricAlertConfig.AlertConditions.SeverityCondition.MinimumAlertSeverity, Is.EqualTo(AnomalySeverity.Low));
            Assert.That(createdMetricAlertConfig.AlertConditions.SeverityCondition.MaximumAlertSeverity, Is.EqualTo(AnomalySeverity.Medium));

            Assert.That(createdMetricAlertConfig.AlertSnoozeCondition, Is.Not.Null);
            Assert.That(createdMetricAlertConfig.AlertSnoozeCondition.AutoSnooze, Is.EqualTo(12));
            Assert.That(createdMetricAlertConfig.AlertSnoozeCondition.SnoozeScope, Is.EqualTo(SnoozeScope.Series));
            Assert.That(createdMetricAlertConfig.AlertSnoozeCondition.IsOnlyForSuccessive, Is.True);

            Assert.That(createdMetricAlertConfig.UseDetectionResultToFilterAnomalies, Is.False);
        }
Beispiel #20
0
        public async Task UpdateAlertConfigurationWithMinimumSetup(bool useTokenCrendential)
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCrendential);

            await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient);

            string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName];

            await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId);

            // Configure the Metric Anomaly Alert Configurations to be used.

            string hookName     = Recording.GenerateAlphaNumericId("hook");
            var    hookToCreate = new EmailNotificationHook(hookName)
            {
                EmailsToAlert = { "*****@*****.**" }
            };

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            var detectionConfigId  = disposableDetectionConfig.Configuration.Id;
            var scope              = MetricAnomalyAlertScope.GetScopeForWholeSeries();
            var metricAlertConfig0 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope)
            {
                AlertSnoozeCondition = new MetricAnomalyAlertSnoozeCondition(12, SnoozeScope.Series, true),
                AlertConditions      = new MetricAnomalyAlertConditions()
                {
                    MetricBoundaryCondition = new MetricBoundaryCondition(BoundaryDirection.Both)
                    {
                        UpperBound                    = 20.0,
                        LowerBound                    = 10.0,
                        CompanionMetricId             = metricId,
                        ShouldAlertIfDataPointMissing = true
                    },
                    SeverityCondition = new SeverityCondition(AnomalySeverity.Low, AnomalySeverity.Medium)
                }
            };
            var metricAlertConfig1 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope)
            {
                UseDetectionResultToFilterAnomalies = true
            };

            // Create the Anomaly Alert Configuration.

            string configName = Recording.GenerateAlphaNumericId("config");
            var    hookIds    = new List <string>()
            {
                disposableHook.Hook.Id
            };

            var configToCreate = new AnomalyAlertConfiguration()
            {
                Name = configName,
                IdsOfHooksToAlert         = { disposableHook.Hook.Id },
                MetricAlertConfigurations = { metricAlertConfig0, metricAlertConfig1 },
                CrossMetricsOperator      = MetricAnomalyAlertConfigurationsOperator.Xor
            };

            await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate);

            // Update the created configuration.

            AnomalyAlertConfiguration configToUpdate = disposableConfig.Configuration;

            configToUpdate.CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.Or;

            AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate);

            // Validate top-level members.

            Assert.That(updatedConfig.Id, Is.EqualTo(configToUpdate.Id));
            Assert.That(updatedConfig.Name, Is.EqualTo(configName));
            Assert.That(updatedConfig.Description, Is.Empty);
            Assert.That(updatedConfig.CrossMetricsOperator, Is.EqualTo(MetricAnomalyAlertConfigurationsOperator.Or));
            Assert.That(updatedConfig.IdsOfHooksToAlert, Is.EqualTo(hookIds));
            Assert.That(updatedConfig.MetricAlertConfigurations, Is.Not.Null);
            Assert.That(updatedConfig.MetricAlertConfigurations.Count, Is.EqualTo(2));

            // Validate the first Metric Anomaly Alert Configuration.

            MetricAnomalyAlertConfiguration updatedMetricAlertConfig0 = updatedConfig.MetricAlertConfigurations[0];

            Assert.That(updatedMetricAlertConfig0.DetectionConfigurationId, Is.EqualTo(detectionConfigId));

            Assert.That(updatedMetricAlertConfig0.AlertScope, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries));
            Assert.That(updatedMetricAlertConfig0.AlertScope.SeriesGroupInScope, Is.Null);
            Assert.That(updatedMetricAlertConfig0.AlertScope.TopNGroupInScope, Is.Null);

            Assert.That(updatedMetricAlertConfig0.AlertConditions, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.Direction, Is.EqualTo(BoundaryDirection.Both));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.UpperBound, Is.EqualTo(20.0));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.LowerBound, Is.EqualTo(10.0));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.CompanionMetricId, Is.EqualTo(metricId));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing, Is.True);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition.MinimumAlertSeverity, Is.EqualTo(AnomalySeverity.Low));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition.MaximumAlertSeverity, Is.EqualTo(AnomalySeverity.Medium));

            Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition.AutoSnooze, Is.EqualTo(12));
            Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition.SnoozeScope, Is.EqualTo(SnoozeScope.Series));
            Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition.IsOnlyForSuccessive, Is.True);

            Assert.That(updatedMetricAlertConfig0.UseDetectionResultToFilterAnomalies, Is.False);

            // Validate the second Metric Anomaly Alert Configuration.

            MetricAnomalyAlertConfiguration updatedMetricAlertConfig1 = updatedConfig.MetricAlertConfigurations[1];

            Assert.That(updatedMetricAlertConfig1.DetectionConfigurationId, Is.EqualTo(detectionConfigId));

            Assert.That(updatedMetricAlertConfig1.AlertScope, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig1.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries));
            Assert.That(updatedMetricAlertConfig1.AlertScope.SeriesGroupInScope, Is.Null);
            Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope, Is.Null);

            Assert.That(updatedMetricAlertConfig1.AlertConditions, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig1.AlertConditions.MetricBoundaryCondition, Is.Null);
            Assert.That(updatedMetricAlertConfig1.AlertConditions.SeverityCondition, Is.Null);
            Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition, Is.Null);
            Assert.That(updatedMetricAlertConfig1.UseDetectionResultToFilterAnomalies, Is.True);
        }
Beispiel #21
0
        public async Task UpdateAlertConfigurationWithEveryMember()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient);

            string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName];

            await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId);

            // Configure the Metric Anomaly Alert Configurations to be used.

            string hookName     = Recording.GenerateAlphaNumericId("hook");
            var    hookToCreate = new EmailNotificationHook(hookName)
            {
                EmailsToAlert = { "*****@*****.**" }
            };

            await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate);

            var detectionConfigId  = disposableDetectionConfig.Configuration.Id;
            var scope              = MetricAnomalyAlertScope.GetScopeForWholeSeries();
            var metricAlertConfig0 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope)
            {
                AlertSnoozeCondition = new MetricAnomalyAlertSnoozeCondition(12, SnoozeScope.Series, true),
                AlertConditions      = new MetricAnomalyAlertConditions()
                {
                    MetricBoundaryCondition = new MetricBoundaryCondition(BoundaryDirection.Both)
                    {
                        UpperBound                    = 20.0,
                        LowerBound                    = 10.0,
                        CompanionMetricId             = metricId,
                        ShouldAlertIfDataPointMissing = true
                    },
                    SeverityCondition = new SeverityCondition(AnomalySeverity.Low, AnomalySeverity.Medium)
                }
            };
            var metricAlertConfig1 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope)
            {
                UseDetectionResultToFilterAnomalies = true
            };

            // Create the Anomaly Alert Configuration.

            string configName  = Recording.GenerateAlphaNumericId("config");
            var    description = "This hook was created to test the .NET client.";
            var    hookIds     = new List <string>()
            {
                disposableHook.Hook.Id
            };
            var metricAlertConfigs = new List <MetricAnomalyAlertConfiguration>()
            {
                metricAlertConfig0, metricAlertConfig1
            };

            var configToCreate = new AnomalyAlertConfiguration()
            {
                Name = configName,
                IdsOfHooksToAlert         = { disposableHook.Hook.Id },
                MetricAlertConfigurations = { metricAlertConfig0, metricAlertConfig1 },
                CrossMetricsOperator      = MetricAnomalyAlertConfigurationsOperator.Xor
            };

            await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate);

            // Update the created configuration.

            AnomalyAlertConfiguration configToUpdate = disposableConfig.Configuration;

            configToUpdate.Description = description;
            configToUpdate.IdsOfHooksToAlert.Clear();
            configToUpdate.CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.And;
            configToUpdate.MetricAlertConfigurations.RemoveAt(1);

            var newScope             = MetricAnomalyAlertScope.GetScopeForTopNGroup(new TopNGroupScope(50, 40, 30));
            var newMetricAlertConfig = new MetricAnomalyAlertConfiguration(detectionConfigId, newScope)
            {
                AlertSnoozeCondition = new MetricAnomalyAlertSnoozeCondition(4, SnoozeScope.Metric, true),
                UseDetectionResultToFilterAnomalies = true
            };

            configToUpdate.MetricAlertConfigurations.Add(newMetricAlertConfig);

            MetricAnomalyAlertConfiguration metricAlertConfigToUpdate = configToUpdate.MetricAlertConfigurations[0];

            metricAlertConfigToUpdate.AlertConditions.MetricBoundaryCondition.UpperBound                    = 15.0;
            metricAlertConfigToUpdate.AlertConditions.MetricBoundaryCondition.LowerBound                    = 5.0;
            metricAlertConfigToUpdate.AlertConditions.MetricBoundaryCondition.CompanionMetricId             = null;
            metricAlertConfigToUpdate.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing = false;

            metricAlertConfigToUpdate.AlertConditions.SeverityCondition = new SeverityCondition(AnomalySeverity.Medium, AnomalySeverity.High);

            metricAlertConfigToUpdate.AlertSnoozeCondition = null;

            AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate);

            // Validate top-level members.

            Assert.That(updatedConfig.Id, Is.EqualTo(configToUpdate.Id));
            Assert.That(updatedConfig.Name, Is.EqualTo(configName));
            Assert.That(updatedConfig.Description, Is.EqualTo(description));
            Assert.That(updatedConfig.CrossMetricsOperator, Is.EqualTo(MetricAnomalyAlertConfigurationsOperator.And));
            Assert.That(updatedConfig.IdsOfHooksToAlert, Is.Not.Null.And.Empty);
            Assert.That(updatedConfig.MetricAlertConfigurations, Is.Not.Null);

            // Validate the first Metric Anomaly Alert Configuration.

            MetricAnomalyAlertConfiguration updatedMetricAlertConfig0 = updatedConfig.MetricAlertConfigurations[0];

            Assert.That(updatedMetricAlertConfig0.DetectionConfigurationId, Is.EqualTo(detectionConfigId));

            Assert.That(updatedMetricAlertConfig0.AlertScope, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries));
            Assert.That(updatedMetricAlertConfig0.AlertScope.SeriesGroupInScope, Is.Null);
            Assert.That(updatedMetricAlertConfig0.AlertScope.TopNGroupInScope, Is.Null);

            Assert.That(updatedMetricAlertConfig0.AlertConditions, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.Direction, Is.EqualTo(BoundaryDirection.Both));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.UpperBound, Is.EqualTo(15.0));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.LowerBound, Is.EqualTo(5.0));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.CompanionMetricId, Is.Null);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing, Is.False);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition.MinimumAlertSeverity, Is.EqualTo(AnomalySeverity.Medium));
            Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition.MaximumAlertSeverity, Is.EqualTo(AnomalySeverity.High));

            Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition, Is.Null);
            Assert.That(updatedMetricAlertConfig0.UseDetectionResultToFilterAnomalies, Is.False);

            // Validate the second Metric Anomaly Alert Configuration.

            MetricAnomalyAlertConfiguration updatedMetricAlertConfig1 = updatedConfig.MetricAlertConfigurations[1];

            Assert.That(updatedMetricAlertConfig1.DetectionConfigurationId, Is.EqualTo(detectionConfigId));

            Assert.That(updatedMetricAlertConfig1.AlertScope, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig1.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.TopN));
            Assert.That(updatedMetricAlertConfig1.AlertScope.SeriesGroupInScope, Is.Null);
            Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope.Top, Is.EqualTo(50));
            Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope.Period, Is.EqualTo(40));
            Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope.MinimumTopCount, Is.EqualTo(30));

            Assert.That(updatedMetricAlertConfig1.AlertConditions, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig1.AlertConditions.MetricBoundaryCondition, Is.Null);
            Assert.That(updatedMetricAlertConfig1.AlertConditions.SeverityCondition, Is.Null);

            Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition, Is.Not.Null);
            Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition.AutoSnooze, Is.EqualTo(4));
            Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition.SnoozeScope, Is.EqualTo(SnoozeScope.Metric));
            Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition.IsOnlyForSuccessive, Is.True);

            Assert.That(updatedMetricAlertConfig1.UseDetectionResultToFilterAnomalies, Is.True);
        }