/// <summary> /// Creates a new Alert Rule. /// /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/budget/CreateAlertRule.cs.html">here</a> to see an example of how to use CreateAlertRule API.</example> public async Task <CreateAlertRuleResponse> CreateAlertRule(CreateAlertRuleRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called createAlertRule"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/budgets/{budgetId}/alertRules".Trim('/'))); HttpMethod method = new HttpMethod("POST"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false); } else { responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false); } this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage); return(Converter.FromHttpResponseMessage <CreateAlertRuleResponse>(responseMessage)); } catch (Exception e) { logger.Error($"CreateAlertRule failed with error: {e.Message}"); throw; } }
/// <summary> /// Creates a new Alert Rule. /// </summary> /// <param name="request"></param> /// <returns></returns> public CreateAlertRuleResponse CreateAlertRule(CreateAlertRuleRequest request) { var uri = new Uri($"{GetEndPoint(BudgetsServices.Budgets, this.Region, "oci.oraclecloud.com")}/{request.BudgetId}/alertRules"); var httpRequestHeaderParam = new HttpRequestHeaderParam() { OpcRetryToken = request.OpcRetryToken, OpcRequestId = request.OpcRequestId }; using (var webResponse = this.RestClient.Post(uri, request.CreateAlertRuleDetails, httpRequestHeaderParam)) using (var stream = webResponse.GetResponseStream()) using (var reader = new StreamReader(stream)) { var response = reader.ReadToEnd(); return(new CreateAlertRuleResponse() { AlertRule = JsonSerializer.Deserialize <AlertRule>(response), OpcRequestId = webResponse.Headers.Get("opc-request-id"), Etag = webResponse.Headers.Get("etag") }); } }
protected override void ProcessRecord() { base.ProcessRecord(); CreateAlertRuleRequest request; try { request = new CreateAlertRuleRequest { BudgetId = BudgetId, CreateAlertRuleDetails = CreateAlertRuleDetails, OpcRetryToken = OpcRetryToken, OpcRequestId = OpcRequestId }; response = client.CreateAlertRule(request).GetAwaiter().GetResult(); WriteOutput(response, response.AlertRule); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }