private static void AssertPoliciesEqual(AlertPolicy policy, MockAlertPolicy mock) { Assert.AreEqual(policy.Id, mock.id); Assert.AreEqual(policy.Name, mock.name); AssertMockActionsEqual(policy.Actions, mock.actions); AssertMockTriggersEqual(policy.Triggers, mock.triggers); }
private void When_I_Update_My_Policy() { _policyDefinition = new AlertPolicyDefniition { Name = "updated name", Actions = new List <AlertAction> { new AlertAction { Action = AlertActionType.Email, Settings = new AlertActionSettings { Recipients = new List <string> { "*****@*****.**" } } } }, Triggers = new List <AlertTrigger> { new AlertTrigger { Duration = TimeSpan.FromSeconds(30), Metric = AlertTriggerMetric.Cpu, Threshold = 5 } } }; var existingId = CurrentUser.AlertPolicies.First().Key; _policyResult = ServiceFactory.CreateAlertPolicyService().Update(existingId, _policyDefinition, CancellationToken.None).Result; }
/// <summary>Snippet for GetAlertPolicy</summary> public void GetAlertPolicy() { // Snippet: GetAlertPolicy(string, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) string name = "projects/[PROJECT]/alertPolicies/[ALERT_POLICY]"; // Make the request AlertPolicy response = alertPolicyServiceClient.GetAlertPolicy(name); // End snippet }
public void Create_ReturnsExpectedResult() { var expectedResult = new AlertPolicy(); _client.Setup(x => x.PostAsync <AlertPolicy>(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(expectedResult)); var actualResult = _testObject.Create(new AlertPolicyDefniition(), CancellationToken.None).Result; Assert.AreSame(expectedResult, actualResult); }
/// <summary>Snippet for GetAlertPolicy</summary> public void GetAlertPolicyResourceNames2() { // Snippet: GetAlertPolicy(IResourceName, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) IResourceName name = new UnparsedResourceName("a/wildcard/resource"); // Make the request AlertPolicy response = alertPolicyServiceClient.GetAlertPolicy(name); // End snippet }
/// <summary>Snippet for GetAlertPolicy</summary> public void GetAlertPolicyResourceNames1() { // Snippet: GetAlertPolicy(AlertPolicyName, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) AlertPolicyName name = AlertPolicyName.FromProjectAlertPolicy("[PROJECT]", "[ALERT_POLICY]"); // Make the request AlertPolicy response = alertPolicyServiceClient.GetAlertPolicy(name); // End snippet }
public void GetById_ReturnsExpectedResult() { var expectedResult = new AlertPolicy(); _client.Setup(x => x.GetAsync <AlertPolicy>(It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(expectedResult)); var actualResult = _testObject.Get(PolicyId, CancellationToken.None).Result; Assert.AreSame(expectedResult, actualResult); }
/// <summary>Snippet for UpdateAlertPolicy</summary> public void UpdateAlertPolicy() { // Snippet: UpdateAlertPolicy(FieldMask, AlertPolicy, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) FieldMask updateMask = new FieldMask(); AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = alertPolicyServiceClient.UpdateAlertPolicy(updateMask, alertPolicy); // End snippet }
/// <summary>Snippet for CreateAlertPolicy</summary> public void CreateAlertPolicy() { // Snippet: CreateAlertPolicy(string, AlertPolicy, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) string name = "projects/[PROJECT]"; AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = alertPolicyServiceClient.CreateAlertPolicy(name, alertPolicy); // End snippet }
/// <summary>Snippet for CreateAlertPolicy</summary> public void CreateAlertPolicyResourceNames1() { // Snippet: CreateAlertPolicy(ProjectName, AlertPolicy, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) ProjectName name = ProjectName.FromProject("[PROJECT]"); AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = alertPolicyServiceClient.CreateAlertPolicy(name, alertPolicy); // End snippet }
/// <summary>Snippet for CreateAlertPolicy</summary> public void CreateAlertPolicyResourceNames2() { // Snippet: CreateAlertPolicy(OrganizationName, AlertPolicy, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) OrganizationName name = OrganizationName.FromOrganization("[ORGANIZATION]"); AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = alertPolicyServiceClient.CreateAlertPolicy(name, alertPolicy); // End snippet }
/// <summary>Snippet for CreateAlertPolicy</summary> public void CreateAlertPolicyResourceNames3() { // Snippet: CreateAlertPolicy(FolderName, AlertPolicy, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) FolderName name = FolderName.FromFolder("[FOLDER]"); AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = alertPolicyServiceClient.CreateAlertPolicy(name, alertPolicy); // End snippet }
private Alert GenerateAlert(AlertPolicy alertPolicy, AlertTrigger trigger, ServerStatistic statistic, string serverId, string message) { var alert = new Alert() { AlertPolicyId = alertPolicy.Id, ServerId = serverId, Metric = trigger.Metric, Message = message, GeneratedOn = statistic.Timestamp }; return(alert); }
public void RecurringAlerts_ShouldBeTriggeredEveryXSeconds() { var testChannel = new TestChannel(); AlertPolicy.Create("Test", MockApi.Object, 0) .ForLogs("testlogid") .When(m => m.Any()) .ToChannels(testChannel) .WithIntervalSeconds(1); WaitForTrigger(testChannel, 3); Assert.AreEqual(3, testChannel.AlertCount); }
public void FrequentErrors_ShouldSordDescending() { var testChannel = new TestChannel(); AlertPolicy.Create("Test", MockApi.Object, 0) .ForLogs("testlogid") .When(m => m.Any()) .ToChannels(testChannel) .WithIntervalSeconds(10); WaitForTrigger(testChannel); Assert.AreEqual(1, testChannel.AlertCount); }
public void NonMatchingFilter_ShouldNotTriggerAlert() { var testChannel = new TestChannel(); AlertPolicy.Create("Test", MockApi.Object) .ForLogs("testlogid") .When(m => m.Count(p => p.StatusCode == 500) > 4) .ToChannels(testChannel) .WithIntervalSeconds(10); WaitForTrigger(testChannel); Assert.AreEqual(0, testChannel.AlertCount); }
/// <summary>Snippet for GetAlertPolicyAsync</summary> public async Task GetAlertPolicyResourceNames1Async() { // Snippet: GetAlertPolicyAsync(AlertPolicyName, CallSettings) // Additional: GetAlertPolicyAsync(AlertPolicyName, CancellationToken) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) AlertPolicyName name = AlertPolicyName.FromProjectAlertPolicy("[PROJECT]", "[ALERT_POLICY]"); // Make the request AlertPolicy response = await alertPolicyServiceClient.GetAlertPolicyAsync(name); // End snippet }
/// <summary>Snippet for UpdateAlertPolicy</summary> public void UpdateAlertPolicy_RequestObject() { // Snippet: UpdateAlertPolicy(UpdateAlertPolicyRequest,CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) UpdateAlertPolicyRequest request = new UpdateAlertPolicyRequest { AlertPolicy = new AlertPolicy(), }; // Make the request AlertPolicy response = alertPolicyServiceClient.UpdateAlertPolicy(request); // End snippet }
/// <summary>Snippet for GetAlertPolicyAsync</summary> public async Task GetAlertPolicyResourceNames2Async() { // Snippet: GetAlertPolicyAsync(IResourceName, CallSettings) // Additional: GetAlertPolicyAsync(IResourceName, CancellationToken) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) IResourceName name = new UnparsedResourceName("a/wildcard/resource"); // Make the request AlertPolicy response = await alertPolicyServiceClient.GetAlertPolicyAsync(name); // End snippet }
/// <summary>Snippet for GetAlertPolicy</summary> public void GetAlertPolicyRequestObject() { // Snippet: GetAlertPolicy(GetAlertPolicyRequest, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) GetAlertPolicyRequest request = new GetAlertPolicyRequest { AlertPolicyName = AlertPolicyName.FromProjectAlertPolicy("[PROJECT]", "[ALERT_POLICY]"), }; // Make the request AlertPolicy response = alertPolicyServiceClient.GetAlertPolicy(request); // End snippet }
/// <summary>Snippet for GetAlertPolicyAsync</summary> public async Task GetAlertPolicyAsync() { // Snippet: GetAlertPolicyAsync(string, CallSettings) // Additional: GetAlertPolicyAsync(string, CancellationToken) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) string name = "projects/[PROJECT]/alertPolicies/[ALERT_POLICY]"; // Make the request AlertPolicy response = await alertPolicyServiceClient.GetAlertPolicyAsync(name); // End snippet }
/// <summary>Snippet for CreateAlertPolicyAsync</summary> public async Task CreateAlertPolicyResourceNames3Async() { // Snippet: CreateAlertPolicyAsync(FolderName, AlertPolicy, CallSettings) // Additional: CreateAlertPolicyAsync(FolderName, AlertPolicy, CancellationToken) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) FolderName name = FolderName.FromFolder("[FOLDER]"); AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = await alertPolicyServiceClient.CreateAlertPolicyAsync(name, alertPolicy); // End snippet }
/// <summary>Snippet for CreateAlertPolicyAsync</summary> public async Task CreateAlertPolicyResourceNames2Async() { // Snippet: CreateAlertPolicyAsync(OrganizationName, AlertPolicy, CallSettings) // Additional: CreateAlertPolicyAsync(OrganizationName, AlertPolicy, CancellationToken) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) OrganizationName name = OrganizationName.FromOrganization("[ORGANIZATION]"); AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = await alertPolicyServiceClient.CreateAlertPolicyAsync(name, alertPolicy); // End snippet }
/// <summary>Snippet for CreateAlertPolicyAsync</summary> public async Task CreateAlertPolicyAsync() { // Snippet: CreateAlertPolicyAsync(string, AlertPolicy, CallSettings) // Additional: CreateAlertPolicyAsync(string, AlertPolicy, CancellationToken) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) string name = "projects/[PROJECT]"; AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = await alertPolicyServiceClient.CreateAlertPolicyAsync(name, alertPolicy); // End snippet }
/// <summary>Snippet for CreateAlertPolicy</summary> public void CreateAlertPolicyRequestObject() { // Snippet: CreateAlertPolicy(CreateAlertPolicyRequest, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) CreateAlertPolicyRequest request = new CreateAlertPolicyRequest { AlertPolicy = new AlertPolicy(), ProjectName = ProjectName.FromProject("[PROJECT]"), }; // Make the request AlertPolicy response = alertPolicyServiceClient.CreateAlertPolicy(request); // End snippet }
/// <summary>Snippet for UpdateAlertPolicyAsync</summary> public async Task UpdateAlertPolicyAsync() { // Snippet: UpdateAlertPolicyAsync(FieldMask, AlertPolicy, CallSettings) // Additional: UpdateAlertPolicyAsync(FieldMask, AlertPolicy, CancellationToken) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) FieldMask updateMask = new FieldMask(); AlertPolicy alertPolicy = new AlertPolicy(); // Make the request AlertPolicy response = await alertPolicyServiceClient.UpdateAlertPolicyAsync(updateMask, alertPolicy); // End snippet }
/// <summary>Snippet for GetAlertPolicyAsync</summary> public async Task GetAlertPolicyAsync_RequestObject() { // Snippet: GetAlertPolicyAsync(GetAlertPolicyRequest,CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) GetAlertPolicyRequest request = new GetAlertPolicyRequest { AlertPolicyName = new AlertPolicyName("[PROJECT]", "[ALERT_POLICY]"), }; // Make the request AlertPolicy response = await alertPolicyServiceClient.GetAlertPolicyAsync(request); // End snippet }
/// <summary>Snippet for UpdateAlertPolicyAsync</summary> public async Task UpdateAlertPolicyAsync_RequestObject() { // Snippet: UpdateAlertPolicyAsync(UpdateAlertPolicyRequest,CallSettings) // Additional: UpdateAlertPolicyAsync(UpdateAlertPolicyRequest,CancellationToken) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) UpdateAlertPolicyRequest request = new UpdateAlertPolicyRequest { AlertPolicy = new AlertPolicy(), }; // Make the request AlertPolicy response = await alertPolicyServiceClient.UpdateAlertPolicyAsync(request); // End snippet }
/// <summary>Snippet for CreateAlertPolicyAsync</summary> public async Task CreateAlertPolicyAsync_RequestObject() { // Snippet: CreateAlertPolicyAsync(CreateAlertPolicyRequest,CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) CreateAlertPolicyRequest request = new CreateAlertPolicyRequest { ProjectName = new ProjectName("[PROJECT]"), AlertPolicy = new AlertPolicy(), }; // Make the request AlertPolicy response = await alertPolicyServiceClient.CreateAlertPolicyAsync(request); // End snippet }
public void ScheduledAlert_ShouldBeTriggeredAtSpecificTime() { var nextMinute = DateTime.Now.AddMinutes(1); var testChannel = new TestChannel(); AlertPolicy.Create("Test", MockApi.Object, 0) .ForLogs("testlogid") .When(m => m.Any()) .ToChannels(testChannel) .RunDailyAt(nextMinute.Hour, nextMinute.Minute); while (DateTime.Now.Minute != nextMinute.Minute) { //This test can take up to a monute to run due to that I can't schedule down to the second. } WaitForTrigger(testChannel); Assert.AreEqual(1, testChannel.AlertCount); }