Ejemplo n.º 1
0
 void OnChangeFallback(PatchObject change)
 {
     // Debug.Log ("OnChangeFallback");
     // Debug.Log (change.operation);
     // Debug.Log (change.path);
     // Debug.Log (change.value);
 }
Ejemplo n.º 2
0
        public static TValue GetValue <TEntity, TValue>(this PatchObject <TEntity> patch, Expression <Func <TEntity, TValue> > propertyGetter)
            where TEntity : class
        {
            var propName = ExpressionHelper.ExtractPropertyName(propertyGetter);

            return((TValue)patch[propName]);
        }
Ejemplo n.º 3
0
        public void CreateAndUpdateActionRule()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var alertsManagementClient = GetAlertsManagementClient(context, handler);

                string resourceGroupName = "ActionRules-Powershell-Test";
                string actionRuleName    = "ScenarioTest-ActionRule";

                // Create Action Rule
                ActionRule actionRule = new ActionRule(
                    location: "Global",
                    tags: new Dictionary <string, string>(),
                    properties: new ActionGroup(
                        scope: new Scope(
                            scopeType: ScopeType.ResourceGroup,
                            values: new List <string>
                {
                    "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/alertslab",
                    "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/Test-VMs"
                }
                            ),
                        conditions: new Conditions(
                            severity: new Condition(
                                operatorProperty: "Equals",
                                values: new List <string>
                {
                    "Sev2"
                })
                            ),
                        actionGroupId: "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/actionrules-powershell-test/providers/microsoft.insights/actionGroups/powershell-test-ag",
                        description: "Test Supression Rule",
                        status: "Enabled"
                        )
                    );

                var createdActionRule = alertsManagementClient.ActionRules.CreateUpdate(resourceGroupName: resourceGroupName, actionRuleName: actionRuleName, actionRule: actionRule);

                // Update Action Rule
                PatchObject patchObject = new PatchObject(
                    status: "Disabled"
                    );
                var updatePatch = alertsManagementClient.ActionRules.Update(resourceGroupName: resourceGroupName, actionRuleName: actionRuleName, actionRulePatch: patchObject);

                // Get again to verify update
                var fetchedActionRule = alertsManagementClient.ActionRules.GetByName(resourceGroupName: resourceGroupName, actionRuleName: actionRuleName);

                if (!this.IsRecording)
                {
                    Assert.Equal("Disabled", fetchedActionRule.Properties.Status);
                }
            }
        }
        public IActionResult Patch(PatchObject <WeatherForecast> patch)
        {
            var model = new WeatherForecast
            {
                Date         = DateTime.Now,
                TemperatureC = 12,
                Summary      = "summary",
                Ignored      = "I was already here"
            };

            patch.ApplyTo(model);
            var newModel = patch.CreateNewEntity();

            return(Ok(new WeatherForecast[] { newModel, model }));
        }
        public IEnumerable <WeatherForecast> Patch([FromBody] PatchObject <WeatherForecast> patch)
        {
            var model = new WeatherForecast
            {
                Date         = DateTime.Now,
                TemperatureC = 12,
                Summary      = "summary",
                Ignored      = "I was already here"
            };

            patch.ApplyTo(model);
            var newModel = patch.CreateNewEntity();

            return(new WeatherForecast[] { newModel, model });
        }
        public void CreateAndUpdateAlertProcessingRule()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var alertsManagementClient = GetAlertsManagementClient(context, handler);

                string resourceGroupName       = "ActionRules-Powershell-Test";
                string alertProcessingRuleName = "ScenarioTest-AlertProcessingRule";

                // Create Alert processing Rule
                AlertProcessingRule alertProcessingRule = new AlertProcessingRule(
                    location: "Global",
                    tags: new Dictionary <string, string>(),
                    properties: new AlertProcessingRuleProperties(
                        scopes: new List <string>
                {
                    "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/alertslab",
                    "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/Test-VMs"
                },
                        conditions: new List <Condition>
                {
                    new Condition(
                        field: "Severity",
                        operatorProperty: "Equals",
                        values: new List <string>
                    {
                        "Sev2"
                    })
                },
                        schedule: new Schedule(
                            effectiveFrom: "2019-12-22T11:00:00",
                            effectiveUntil: "2020-09-24T11:00:00",
                            timeZone: "Pacific Standard Time",
                            recurrences: new List <Recurrence>
                {
                    new DailyRecurrence(startTime: "06:00:00", endTime: "14:00:00")
                }
                            ),
                        actions: new List <Action>
                {
                    new AddActionGroups(new List <string>
                    {
                        "/subscriptions/dd91de05-d791-4ceb-b6dc-988682dc7d72/resourceGroups/actionrules-powershell-test/providers/microsoft.insights/actionGroups/powershell-test-ag"
                    })
                },
                        description: "Test Add Action Group Rule",
                        enabled: true
                        )
                    );

                var createdAlertProcessingRule = alertsManagementClient.AlertProcessingRules.CreateOrUpdate(resourceGroupName: resourceGroupName, alertProcessingRuleName: alertProcessingRuleName, alertProcessingRule: alertProcessingRule);

                // Update Alert processing Rule
                PatchObject patchObject = new PatchObject(
                    enabled: false
                    );
                var updatePatch = alertsManagementClient.AlertProcessingRules.Update(resourceGroupName: resourceGroupName, alertProcessingRuleName: alertProcessingRuleName, alertProcessingRulePatch: patchObject);

                // Get again to verify update
                var fetchedAlertProcessingRule = alertsManagementClient.AlertProcessingRules.GetByName(resourceGroupName: resourceGroupName, alertProcessingRuleName: alertProcessingRuleName);

                if (!this.IsRecording)
                {
                    Assert.False(fetchedAlertProcessingRule.Properties.Enabled);
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Enable, disable, or update tags for an alert processing rule.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Resource group name where the resource is created.
 /// </param>
 /// <param name='alertProcessingRuleName'>
 /// The name that needs to be updated.
 /// </param>
 /// <param name='alertProcessingRulePatch'>
 /// Parameters supplied to the operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <AlertProcessingRule> UpdateAsync(this IAlertProcessingRulesOperations operations, string resourceGroupName, string alertProcessingRuleName, PatchObject alertProcessingRulePatch, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, alertProcessingRuleName, alertProcessingRulePatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Enable, disable, or update tags for an alert processing rule.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Resource group name where the resource is created.
 /// </param>
 /// <param name='alertProcessingRuleName'>
 /// The name that needs to be updated.
 /// </param>
 /// <param name='alertProcessingRulePatch'>
 /// Parameters supplied to the operation.
 /// </param>
 public static AlertProcessingRule Update(this IAlertProcessingRulesOperations operations, string resourceGroupName, string alertProcessingRuleName, PatchObject alertProcessingRulePatch)
 {
     return(operations.UpdateAsync(resourceGroupName, alertProcessingRuleName, alertProcessingRulePatch).GetAwaiter().GetResult());
 }