/// <summary> /// Execute the cmdlet /// </summary> public override void ExecuteCmdlet() { Utilities.ValidateUri(this.ServiceUri, "ServiceUri"); var dictionary = this.Property == null ? new Dictionary <string, string>() : this.Property.Keys.Cast <object>().ToDictionary(key => (string)key, key => (string)this.Property[key]); var action = new Management.Monitor.Management.Models.RuleWebhookAction { ServiceUri = this.ServiceUri, Properties = dictionary }; WriteObject(action); }
public void AddAzureRmMetricAlertRuleCommandParametersProcessing() { // Test null actions cmdlet.Name = Utilities.Name; cmdlet.Location = "East US"; cmdlet.ResourceGroupName = Utilities.ResourceGroup; cmdlet.Operator = Management.Monitor.Management.Models.ConditionOperator.GreaterThan; cmdlet.Threshold = 1; cmdlet.TargetResourceId = "/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo"; cmdlet.MetricName = "Requests"; cmdlet.TimeAggregationOperator = Management.Monitor.Management.Models.TimeAggregationOperator.Total; cmdlet.Action = null; cmdlet.WindowSize = TimeSpan.FromMinutes(10); cmdlet.ExecuteCmdlet(); this.AssertResult( location: "East US", tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo", isEnabled: true, actionsNull: true, actionsCount: 0, threshold: 1, conditionOperator: ConditionOperator.GreaterThan, totalMinutes: 10, timeAggregationOperator: TimeAggregationOperator.Total, metricName: "Requests", resourceUri: "/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo"); // Test null actions and disabled cmdlet.DisableRule = true; cmdlet.ExecuteCmdlet(); this.AssertResult( location: "East US", tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo", isEnabled: false, actionsNull: true, actionsCount: 0, threshold: 1, conditionOperator: ConditionOperator.GreaterThan, totalMinutes: 10, timeAggregationOperator: TimeAggregationOperator.Total, metricName: "Requests", resourceUri: "/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo"); // Test empty actions cmdlet.DisableRule = false; cmdlet.Action = new List <Management.Monitor.Management.Models.RuleAction>(); cmdlet.ExecuteCmdlet(); this.AssertResult( location: "East US", tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo", isEnabled: true, actionsNull: false, actionsCount: 0, threshold: 1, conditionOperator: ConditionOperator.GreaterThan, totalMinutes: 10, timeAggregationOperator: TimeAggregationOperator.Total, metricName: "Requests", resourceUri: "/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo"); // Test non-empty actions (one action) List <string> eMails = new List <string>(); eMails.Add("*****@*****.**"); Management.Monitor.Management.Models.RuleAction ruleAction = new Management.Monitor.Management.Models.RuleEmailAction { SendToServiceOwners = true, CustomEmails = eMails }; cmdlet.Action.Add(ruleAction); cmdlet.ExecuteCmdlet(); this.AssertResult( location: "East US", tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo", isEnabled: true, actionsNull: false, actionsCount: 1, threshold: 1, conditionOperator: ConditionOperator.GreaterThan, totalMinutes: 10, timeAggregationOperator: TimeAggregationOperator.Total, metricName: "Requests", resourceUri: "/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo"); // Test non-empty actions (two actions) var properties = new Dictionary <string, string>(); properties.Add("hello", "goodbye"); ruleAction = new Management.Monitor.Management.Models.RuleWebhookAction { ServiceUri = "http://bueno.net", Properties = properties }; cmdlet.Action.Add(ruleAction); cmdlet.ExecuteCmdlet(); this.AssertResult( location: "East US", tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo", isEnabled: true, actionsNull: false, actionsCount: 2, threshold: 1, conditionOperator: ConditionOperator.GreaterThan, totalMinutes: 10, timeAggregationOperator: TimeAggregationOperator.Total, metricName: "Requests", resourceUri: "/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo"); // Test non-empty actions (two actions) and non-default window size cmdlet.WindowSize = TimeSpan.FromMinutes(300); cmdlet.ExecuteCmdlet(); this.AssertResult( location: "East US", tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo", isEnabled: true, actionsNull: false, actionsCount: 2, threshold: 1, conditionOperator: ConditionOperator.GreaterThan, totalMinutes: 300, timeAggregationOperator: TimeAggregationOperator.Total, metricName: "Requests", resourceUri: "/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo"); }
public void AddAzureRmWebtestAlertRuleCommandParametersProcessing() { // Test null actions cmdlet.Name = Utilities.Name; cmdlet.Location = "East US"; cmdlet.ResourceGroupName = Utilities.ResourceGroup; cmdlet.FailedLocationCount = 10; cmdlet.Action = null; cmdlet.WindowSize = TimeSpan.FromMinutes(15); cmdlet.ExecuteCmdlet(); this.AssertResults( location: "East US", tagsKey: "hidden-link:", isEnabled: true, actionsNull: true, actionsCount: 0, failedLocationCount: 10, totalMinutes: 15); // Test null actions and disabled cmdlet.DisableRule = true; cmdlet.ExecuteCmdlet(); this.AssertResults( location: "East US", tagsKey: "hidden-link:", isEnabled: false, actionsNull: true, actionsCount: 0, failedLocationCount: 10, totalMinutes: 15); // Test empty actions cmdlet.DisableRule = false; cmdlet.Action = new List <Management.Monitor.Management.Models.RuleAction>(); cmdlet.ExecuteCmdlet(); this.AssertResults( location: "East US", tagsKey: "hidden-link:", isEnabled: true, actionsNull: false, actionsCount: 0, failedLocationCount: 10, totalMinutes: 15); // Test non-empty actions (one action) List <string> eMails = new List <string>(); eMails.Add("*****@*****.**"); Management.Monitor.Management.Models.RuleAction ruleAction = new Management.Monitor.Management.Models.RuleEmailAction { SendToServiceOwners = true, CustomEmails = eMails }; cmdlet.Action.Add(ruleAction); cmdlet.ExecuteCmdlet(); this.AssertResults( location: "East US", tagsKey: "hidden-link:", isEnabled: true, actionsNull: false, actionsCount: 1, failedLocationCount: 10, totalMinutes: 15); // Test non-empty actions (two actions) var properties = new Dictionary <string, string>(); properties.Add("hello", "goodbye"); ruleAction = new Management.Monitor.Management.Models.RuleWebhookAction { ServiceUri = "http://bueno.net", Properties = properties }; cmdlet.Action.Add(ruleAction); cmdlet.ExecuteCmdlet(); this.AssertResults( location: "East US", tagsKey: "hidden-link:", isEnabled: true, actionsNull: false, actionsCount: 2, failedLocationCount: 10, totalMinutes: 15); // Test non-empty actions (two actions) and non-default window size cmdlet.WindowSize = TimeSpan.FromMinutes(300); cmdlet.ExecuteCmdlet(); this.AssertResults( location: "East US", tagsKey: "hidden-link:", isEnabled: true, actionsNull: false, actionsCount: 2, failedLocationCount: 10, totalMinutes: 300); }