Example #1
0
        public UpdateScheduledQueryRuleTests(Xunit.Abstractions.ITestOutputHelper output)
        {
            ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagement.Common.Models.XunitTracingInterceptor(output));
            TestExecutionHelpers.SetUpSessionAndProfile();
            sqrOperationsMock           = new Mock <IScheduledQueryRulesOperations>();
            monitorManagementClientMock = new Mock <MonitorManagementClient>()
            {
                CallBase = true
            };
            commandRuntimeMock = new Mock <ICommandRuntime>();

            //testing update of "enabled" field
            cmdlet = new UpdateScheduledQueryRuleCommand
            {
                CommandRuntime          = commandRuntimeMock.Object,
                MonitorManagementClient = monitorManagementClientMock.Object,
                Enabled = true
            };

            response = new AzureOperationResponse <LogSearchRuleResource>()
            {
                Body = new LogSearchRuleResource()
            };

            sqrOperationsMock.Setup(f => f.GetWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Microsoft.Rest.Azure.AzureOperationResponse <LogSearchRuleResource> >(response))
            .Callback((string resourceGrp, string name, Dictionary <string, List <string> > customHeaders, CancellationToken cancellationToken) =>
            {
                this.resourceGroup = resourceGrp;
                this.ruleName      = name;
                this.updatePrms    = response.Body;
            });

            sqrOperationsMock.Setup(f => f.UpdateWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <LogSearchRuleResourcePatch>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Microsoft.Rest.Azure.AzureOperationResponse <LogSearchRuleResource> >(response))
            .Callback((string resourceGrp, string name, LogSearchRuleResourcePatch patchPrms, Dictionary <string, List <string> > headers, CancellationToken t) =>
            {
                this.resourceGroup = resourceGrp;
                this.ruleName      = name;
                this.patchPrms     = patchPrms;
                this.updatePrms    = response.Body;
            });

            monitorManagementClientMock.SetupGet(f => f.ScheduledQueryRules).Returns(this.sqrOperationsMock.Object);

            // Setup Confirmation
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldContinue(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
        }
        protected override void ProcessRecordInternal()
        {
            ResourceIdentifier         resourceIdentifier = null;
            ScheduledQueryRuleResource resource           = null;

            // ByInputObject parameter set
            if (this.IsParameterBound(c => c.InputObject) || this.InputObject != null)
            {
                resourceIdentifier     = new ResourceIdentifier(InputObject.Id);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }
            else if (this.IsParameterBound(c => c.ResourceId) || !string.IsNullOrWhiteSpace(this.ResourceId))
            {
                resourceIdentifier     = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

            try
            {
                resource = new ScheduledQueryRuleResource(
                    this.MonitorManagementClient.ScheduledQueryRules.GetWithHttpMessagesAsync(this.ResourceGroupName, this.Name).Result.Body);
            }
            catch (Exception ex)
            {
                throw new Exception("Error in getting Log Alert Rule", ex);
            }

            // Update of only Enabled field is supported
            LogSearchRuleResourcePatch parameters = new LogSearchRuleResourcePatch(resource.Tags, this.Enabled ? "true" : "false");

            if (ShouldProcess(this.Name,
                              string.Format("Updating Log Alert Rule '{0}' in resource group '{1}'.", this.Name,
                                            this.ResourceGroupName)))
            {
                try
                {
                    WriteObject(new PSScheduledQueryRuleResource(
                                    this.MonitorManagementClient.ScheduledQueryRules.UpdateWithHttpMessagesAsync(this.ResourceGroupName,
                                                                                                                 this.Name,
                                                                                                                 parameters).Result.Body));
                }
                catch (Exception ex)
                {
                    throw new Exception("Error in updating Log Alert Rule", ex);
                }
            }
        }
 public virtual Response <LogSearchRuleResource> Update(string resourceGroupName, string ruleName, LogSearchRuleResourcePatch parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ScheduledQueryRulesOperations.Update");
     scope.Start();
     try
     {
         return(RestClient.Update(resourceGroupName, ruleName, parameters, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Example #4
0
 /// <summary>
 /// Update log search Rule.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group. The name is case insensitive.
 /// </param>
 /// <param name='ruleName'>
 /// The name of the rule.
 /// </param>
 /// <param name='parameters'>
 /// The parameters of the rule to update.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <LogSearchRuleResource> UpdateAsync(this IScheduledQueryRulesOperations operations, string resourceGroupName, string ruleName, LogSearchRuleResourcePatch parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, ruleName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Example #5
0
 /// <summary>
 /// Update log search Rule.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group. The name is case insensitive.
 /// </param>
 /// <param name='ruleName'>
 /// The name of the rule.
 /// </param>
 /// <param name='parameters'>
 /// The parameters of the rule to update.
 /// </param>
 public static LogSearchRuleResource Update(this IScheduledQueryRulesOperations operations, string resourceGroupName, string ruleName, LogSearchRuleResourcePatch parameters)
 {
     return(operations.UpdateAsync(resourceGroupName, ruleName, parameters).GetAwaiter().GetResult());
 }