Exemple #1
0
        public async Task<Response<LogSearchRuleData>> CreateOrUpdateAsync(string subscriptionId, string resourceGroupName, string ruleName, LogSearchRuleData data, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId));
            Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName));
            Argument.AssertNotNullOrEmpty(ruleName, nameof(ruleName));
            Argument.AssertNotNull(data, nameof(data));

            using var message = CreateCreateOrUpdateRequest(subscriptionId, resourceGroupName, ruleName, data);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
            switch (message.Response.Status)
            {
                case 200:
                case 201:
                    {
                        LogSearchRuleData value = default;
                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
                        value = LogSearchRuleData.DeserializeLogSearchRuleData(document.RootElement);
                        return Response.FromValue(value, message.Response);
                    }
Exemple #2
0
        public virtual async Task <ArmOperation <LogSearchRuleResource> > CreateOrUpdateAsync(WaitUntil waitUntil, string ruleName, LogSearchRuleData data, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(ruleName, nameof(ruleName));
            Argument.AssertNotNull(data, nameof(data));

            using var scope = _logSearchRuleScheduledQueryRulesClientDiagnostics.CreateScope("LogSearchRuleCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _logSearchRuleScheduledQueryRulesRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, ruleName, data, cancellationToken).ConfigureAwait(false);

                var operation = new MonitorArmOperation <LogSearchRuleResource>(Response.FromValue(new LogSearchRuleResource(Client, response), response.GetRawResponse()));
                if (waitUntil == WaitUntil.Completed)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemple #3
0
 internal HttpMessage CreateCreateOrUpdateRequest(string subscriptionId, string resourceGroupName, string ruleName, LogSearchRuleData data)
 {
     var message = _pipeline.CreateMessage();
     var request = message.Request;
     request.Method = RequestMethod.Put;
     var uri = new RawRequestUriBuilder();
     uri.Reset(_endpoint);
     uri.AppendPath("/subscriptions/", false);
     uri.AppendPath(subscriptionId, true);
     uri.AppendPath("/resourcegroups/", false);
     uri.AppendPath(resourceGroupName, true);
     uri.AppendPath("/providers/Microsoft.Insights/scheduledQueryRules/", false);
     uri.AppendPath(ruleName, true);
     uri.AppendQuery("api-version", _apiVersion, true);
     request.Uri = uri;
     request.Headers.Add("Accept", "application/json");
     request.Headers.Add("Content-Type", "application/json");
     var content = new Utf8JsonRequestContent();
     content.JsonWriter.WriteObjectValue(data);
     request.Content = content;
     _userAgent.Apply(message);
     return message;
 }
 internal LogSearchRuleResource(ArmClient client, LogSearchRuleData data) : this(client, data.Id)
 {
     HasData = true;
     _data   = data;
 }