示例#1
0
 /// <summary>
 /// Initializes a new instance of the PSEmailReceiver class.
 /// </summary>
 /// <param name="receiver">The receiver to wrap.</param>
 public PSEmailReceiver(EmailReceiver receiver)
 {
     this.Name                 = receiver.Name;
     this.EmailAddress         = receiver.EmailAddress;
     this.Status               = TransitionHelpers.ConvertNamespace(receiver.Status);
     this.UseCommonAlertSchema = receiver.UseCommonAlertSchema.HasValue ? receiver.UseCommonAlertSchema.Value : false;
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the Recurrence class.
 /// </summary>
 /// <param name="recurrence">The recurrence object</param>
 public Recurrence(Monitor.Models.Recurrence recurrence)
     : base()
 {
     if (recurrence != null)
     {
         this.Frequency = TransitionHelpers.ConvertNamespace(recurrence.Frequency);
         this.Schedule  = recurrence.Schedule != null ? new RecurrentSchedule(recurrence.Schedule) : null;
     }
 }
 /// <summary>
 /// Initializes a new instance of the RuleCondition class.
 /// </summary>
 /// <param name="ruleCondition">The RuleCondition object</param>
 public ThresholdRuleCondition(Monitor.Models.ThresholdRuleCondition ruleCondition)
     : base()
 {
     if (ruleCondition != null)
     {
         this.DataSource       = ruleCondition.DataSource != null ? new RuleDataSource(ruleCondition.DataSource) : null;
         this.OperatorProperty = TransitionHelpers.ConvertNamespace(ruleCondition.OperatorProperty);
         this.Threshold        = ruleCondition.Threshold;
         this.WindowSize       = ruleCondition.WindowSize;
         this.TimeAggregation  = TransitionHelpers.ConvertNamespace(ruleCondition.TimeAggregation);
     }
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the ScaleAction class.
 /// </summary>
 /// <param name="scaleAction">The ScaleAction object</param>
 public ScaleAction(Monitor.Models.ScaleAction scaleAction)
     : base()
 {
     if (scaleAction != null)
     {
         base.Cooldown  = scaleAction.Cooldown;
         base.Direction = scaleAction.Direction;
         base.Type      = scaleAction.Type;
         Value          = scaleAction.Value;
         this.Type      = TransitionHelpers.ConvertNamespace(scaleAction.Type);
         this.Direction = TransitionHelpers.ConvertNamespace(scaleAction.Direction);
     }
 }
示例#5
0
 private ThresholdRuleCondition CreateThresholdRuleCondition()
 {
     return(new ThresholdRuleCondition
     {
         DataSource = new RuleMetricDataSource
         {
             MetricName = this.MetricName,
             ResourceUri = this.TargetResourceId,
         },
         OperatorProperty = TransitionHelpers.ConvertNamespace(this.Operator),
         Threshold = this.Threshold,
         TimeAggregation = TransitionHelpers.ConvertNamespace(this.TimeAggregationOperator),
         WindowSize = this.WindowSize,
     });
 }
 /// <summary>
 /// Initializes a new instance of the MetricTrigger class.
 /// </summary>
 /// <param name="metricTrigger">The MetricTrigger object</param>
 public MetricTrigger(Monitor.Models.MetricTrigger metricTrigger)
     : base(
         metricName: metricTrigger?.MetricName,
         metricResourceUri: metricTrigger?.MetricResourceUri,
         timeGrain: metricTrigger == null ? default(System.TimeSpan) : metricTrigger.TimeGrain,
         operatorProperty: metricTrigger == null ? default(Monitor.Models.ComparisonOperationType) : metricTrigger.OperatorProperty,
         statistic: metricTrigger == null ? default(Monitor.Models.MetricStatisticType) : metricTrigger.Statistic,
         threshold: metricTrigger == null ? 0 : metricTrigger.Threshold,
         timeAggregation: metricTrigger == null ? default(Monitor.Models.TimeAggregationType) : metricTrigger.TimeAggregation,
         timeWindow: metricTrigger == null ? default(System.TimeSpan) : metricTrigger.TimeWindow)
 {
     if (metricTrigger != null)
     {
         this.OperatorProperty = TransitionHelpers.ConvertNamespace(metricTrigger.OperatorProperty);
         this.Statistic        = TransitionHelpers.ConvertNamespace(metricTrigger.Statistic);
         this.TimeAggregation  = TransitionHelpers.ConvertNamespace(metricTrigger.TimeAggregation);
     }
 }
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        protected override void ProcessRecordInternal()
        {
            if (ShouldProcess(
                    target: string.Format("Create/update an autoscale setting: {0} from resource group: {1}", this.Name, this.ResourceGroupName),
                    action: "Create/update an autoscale setting"))
            {
                AutoscaleSettingResource parameters = this.CreateAutoscaleSettingResource();

                // The result of this operation is operation (AutoscaleSettingResource) is being discarded for backwards compatibility
                var result   = this.MonitorManagementClient.AutoscaleSettings.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName: this.ResourceGroupName, autoscaleSettingName: this.Name, parameters: parameters).Result;
                var response = new PSAddAutoscaleSettingOperationResponse()
                {
                    RequestId   = result.RequestId,
                    StatusCode  = result.Response != null ? result.Response.StatusCode : HttpStatusCode.OK,
                    SettingSpec = TransitionHelpers.ConvertNamespace(result.Body)
                };

                WriteObject(response);
            }
        }
        /// <summary>
        /// Initializes a new instance of the AlertRuleResource class.
        /// </summary>
        /// <param name="alertRuleResource">The AlertRuleResource object</param>
        public AlertRuleResource(Monitor.Models.AlertRuleResource alertRuleResource)
            : base(
                location: alertRuleResource?.Location,
                id: alertRuleResource?.Id,
                name: alertRuleResource?.Name,
                type: alertRuleResource?.Type,
                tags: alertRuleResource?.Tags,
                alertRuleResourceName: alertRuleResource?.AlertRuleResourceName,
                description: alertRuleResource?.Description,
                actions: alertRuleResource?.Actions,
                isEnabled: alertRuleResource == null ? false : alertRuleResource.IsEnabled,
                lastUpdatedTime: alertRuleResource?.LastUpdatedTime,
                condition: alertRuleResource?.Condition)
        {
            if (alertRuleResource != null)
            {
                this.Condition = alertRuleResource.Condition != null?TransitionHelpers.ToMirrorNamespace(alertRuleResource.Condition) : null;

                this.Actions = alertRuleResource.Actions?.Select(TransitionHelpers.ToMirrorNamespace).ToList();
            }
        }
        /// <summary>
        /// Executes the cmdlet.
        /// </summary>
        protected override void ProcessRecordInternal()
        {
            if (
                ShouldProcess(
                    target: string.Format("Add/update action group: {0} from resource group: {1}", this.Name, this.ResourceGroupName),
                    action: "Add/update action group"))
            {
                if (ParameterSetName == ByInputObject)
                {
                    this.ResourceGroupName = this.InputObject.ResourceGroupName;
                    if (this.Name == null)
                    {
                        this.Name = this.InputObject.Name;
                    }
                    if (this.ShortName == null)
                    {
                        this.ShortName = this.InputObject.GroupShortName;
                    }
                    if (!this.DisableGroup.IsPresent)
                    {
                        this.DisableGroup = !this.InputObject.Enabled;
                    }
                    if (this.Tag == null)
                    {
                        this.Tag = this.InputObject.Tags;
                    }
                    this.Receiver = new List <PSActionGroupReceiverBase>();
                    this.Receiver.AddRange(this.InputObject.EmailReceivers);
                    this.Receiver.AddRange(this.InputObject.SmsReceivers);
                    this.Receiver.AddRange(this.InputObject.WebhookReceivers);
                    this.Receiver.AddRange(this.InputObject.ItsmReceivers);
                    this.Receiver.AddRange(this.InputObject.VoiceReceivers);
                    this.Receiver.AddRange(this.InputObject.ArmRoleReceivers);
                    this.Receiver.AddRange(this.InputObject.AzureFunctionReceivers);
                    this.Receiver.AddRange(this.InputObject.LogicAppReceivers);
                    this.Receiver.AddRange(this.InputObject.AutomationRunbookReceivers);
                    this.Receiver.AddRange(this.InputObject.AzureAppPushReceivers);
                }
                else if (ParameterSetName == ByResourceId)
                {
                    ResourceIdentifier resourceId = new ResourceIdentifier(this.ResourceId);
                    this.ResourceGroupName = resourceId.ResourceGroupName;
                    this.Name = resourceId.ResourceName;
                }

                IList <EmailReceiver> emailReceivers =
                    this.Receiver.OfType <PSEmailReceiver>().
                    Select(o => new EmailReceiver(name: o.Name, emailAddress: o.EmailAddress, status: TransitionHelpers.ConvertNamespace(o.Status), useCommonAlertSchema: o.UseCommonAlertSchema)).ToList();

                IList <SmsReceiver> smsReceivers =
                    this.Receiver.OfType <PSSmsReceiver>().
                    Select(o => new SmsReceiver(name: o.Name, countryCode: o.CountryCode, phoneNumber: o.PhoneNumber, status: TransitionHelpers.ConvertNamespace(o.Status))).ToList();

                IList <WebhookReceiver> webhookReceivers =
                    this.Receiver.OfType <PSWebhookReceiver>().
                    Select(o => new WebhookReceiver(
                               name: o.Name,
                               serviceUri: o.ServiceUri,
                               useCommonAlertSchema: o.UseCommonAlertSchema,
                               useAadAuth: o.UseAadAuth,
                               objectId: o.ObjectId,
                               identifierUri: o.IdentifierUri,
                               tenantId: o.TenantId)).ToList();

                IList <ItsmReceiver> itsmReceivers =
                    this.Receiver.OfType <PSItsmReceiver>().
                    Select(o => new ItsmReceiver(name: o.Name, workspaceId: o.WorkspaceId, connectionId: o.ConnectionId, ticketConfiguration: o.TicketConfiguration, region: o.Region)).ToList();

                IList <VoiceReceiver> voiceReceivers =
                    this.Receiver.OfType <PSVoiceReceiver>().
                    Select(o => new VoiceReceiver(name: o.Name, countryCode: o.CountryCode, phoneNumber: o.PhoneNumber)).ToList();

                IList <ArmRoleReceiver> armRoleReceivers =
                    this.Receiver.OfType <PSArmRoleReceiver>().
                    Select(o => new ArmRoleReceiver(name: o.Name, roleId: o.RoleId, useCommonAlertSchema: o.UseCommonAlertSchema)).ToList();

                IList <AzureFunctionReceiver> azureFunctionReceivers =
                    this.Receiver.OfType <PSAzureFunctionReceiver>().
                    Select(o => new AzureFunctionReceiver(
                               name: o.Name,
                               functionName: o.FunctionName,
                               functionAppResourceId: o.FunctionAppResourceId,
                               httpTriggerUrl: o.HttpTriggerUrl,
                               useCommonAlertSchema: o.UseCommonAlertSchema)).ToList();

                IList <LogicAppReceiver> logicAppReceivers =
                    this.Receiver.OfType <PSLogicAppReceiver>().
                    Select(o => new LogicAppReceiver(
                               name: o.Name,
                               resourceId: o.ResourceId,
                               callbackUrl: o.CallbackUrl,
                               useCommonAlertSchema: o.UseCommonAlertSchema
                               )).ToList();

                IList <AutomationRunbookReceiver> automationRunbookReceivers =
                    this.Receiver.OfType <PSAutomationRunbookReceiver>().
                    Select(o => new AutomationRunbookReceiver(
                               name: o.Name,
                               runbookName: o.RunbookName,
                               webhookResourceId: o.WebhookResourceId,
                               isGlobalRunbook: o.IsGlobalRunbook,
                               useCommonAlertSchema: o.UseCommonAlertSchema,
                               serviceUri: o.ServiceUri,
                               automationAccountId: o.AutomationAccountId
                               )).ToList();

                IList <AzureAppPushReceiver> azureAppPushReceivers =
                    this.Receiver.OfType <PSAzureAppPushReceiver>().
                    Select(o => new AzureAppPushReceiver(
                               name: o.Name,
                               emailAddress: o.EmailAddress
                               )).ToList();

                ActionGroupResource actionGroup = new ActionGroupResource
                {
                    Location                   = "Global",
                    GroupShortName             = this.ShortName,
                    Enabled                    = !this.DisableGroup.IsPresent || !this.DisableGroup,
                    Tags                       = this.Tag,
                    EmailReceivers             = emailReceivers,
                    SmsReceivers               = smsReceivers,
                    WebhookReceivers           = webhookReceivers,
                    ItsmReceivers              = itsmReceivers,
                    VoiceReceivers             = voiceReceivers,
                    ArmRoleReceivers           = armRoleReceivers,
                    AzureFunctionReceivers     = azureFunctionReceivers,
                    LogicAppReceivers          = logicAppReceivers,
                    AutomationRunbookReceivers = automationRunbookReceivers,
                    AzureAppPushReceivers      = azureAppPushReceivers
                };

                WriteObject(
                    new PSActionGroupResource(
                        this.MonitorManagementClient.ActionGroups.CreateOrUpdate(
                            resourceGroupName: this.ResourceGroupName,
                            actionGroupName: this.Name,
                            actionGroup: actionGroup)));
            }
        }
示例#10
0
        /// <summary>
        /// Executes the cmdlet.
        /// </summary>
        protected override void ProcessRecordInternal()
        {
            if (
                ShouldProcess(
                    target: string.Format("Add/update action group: {0} from resource group: {1}", this.Name, this.ResourceGroupName),
                    action: "Add/update action group"))
            {
                if (ParameterSetName == ByInputObject)
                {
                    this.ResourceGroupName = this.InputObject.ResourceGroupName;
                    if (this.ShortName == null)
                    {
                        this.ShortName = this.InputObject.GroupShortName;
                    }
                    if (!this.DisableGroup.IsPresent)
                    {
                        this.DisableGroup = !this.InputObject.Enabled;
                    }
                    if (this.Tag == null)
                    {
                        this.Tag = this.InputObject.Tags;
                    }
                    this.Receiver = new List <PSActionGroupReceiverBase>();
                    this.Receiver.AddRange(this.InputObject.EmailReceivers);
                    this.Receiver.AddRange(this.InputObject.SmsReceivers);
                    this.Receiver.AddRange(this.InputObject.WebhookReceivers);
                }
                else if (ParameterSetName == ByResourceId)
                {
                    ResourceIdentifier resourceId = new ResourceIdentifier(this.ResourceId);
                    this.ResourceGroupName = resourceId.ResourceGroupName;
                    this.Name = resourceId.ResourceName;
                }

                IList <EmailReceiver> emailReceivers =
                    this.Receiver.OfType <PSEmailReceiver>().
                    Select(o => new EmailReceiver(name: o.Name, emailAddress: o.EmailAddress, status: TransitionHelpers.ConvertNamespace(o.Status), useCommonAlertSchema: false)).ToList();
                IList <SmsReceiver> smsReceivers =
                    this.Receiver.OfType <PSSmsReceiver>().
                    Select(o => new SmsReceiver(name: o.Name, countryCode: o.CountryCode, phoneNumber: o.PhoneNumber, status: TransitionHelpers.ConvertNamespace(o.Status))).ToList();
                IList <WebhookReceiver> webhookReceivers =
                    this.Receiver.OfType <PSWebhookReceiver>().
                    Select(o => new WebhookReceiver(name: o.Name, serviceUri: o.ServiceUri, useCommonAlertSchema: false)).ToList();
                ActionGroupResource actionGroup = new ActionGroupResource
                {
                    Location         = "Global",
                    GroupShortName   = this.ShortName,
                    Enabled          = !this.DisableGroup.IsPresent || !this.DisableGroup,
                    Tags             = this.Tag,
                    EmailReceivers   = emailReceivers,
                    SmsReceivers     = smsReceivers,
                    WebhookReceivers = webhookReceivers
                };

                WriteObject(
                    new PSActionGroupResource(
                        this.MonitorManagementClient.ActionGroups.CreateOrUpdate(
                            resourceGroupName: this.ResourceGroupName,
                            actionGroupName: this.Name,
                            actionGroup: actionGroup)));
            }
        }
 /// <summary>
 /// Initializes a new instance of the PSEmailReceiver class.
 /// </summary>
 /// <param name="receiver">The receiver to wrap.</param>
 public PSEmailReceiver(EmailReceiver receiver)
 {
     this.Name         = receiver.Name;
     this.EmailAddress = receiver.EmailAddress;
     this.Status       = TransitionHelpers.ConvertNamespace(receiver.Status);
 }