Пример #1
0
        /// <summary>
        /// Removes any existing suppression for the specified alarm.
        /// For important limits information, see [Limits on Monitoring](https://docs.cloud.oracle.com/iaas/Content/Monitoring/Concepts/monitoringoverview.htm#Limits).
        /// &lt;br/&gt;
        /// This call is subject to a Monitoring limit that applies to the total number of requests across all alarm operations.
        /// Monitoring might throttle this call to reject an otherwise valid request when the total rate of alarm operations exceeds 10 requests,
        /// or transactions, per second (TPS) for a given tenancy.
        ///
        /// </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/monitoring/RemoveAlarmSuppression.cs.html">here</a> to see an example of how to use RemoveAlarmSuppression API.</example>
        public async Task <RemoveAlarmSuppressionResponse> RemoveAlarmSuppression(RemoveAlarmSuppressionRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called removeAlarmSuppression");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/alarms/{alarmId}/actions/removeSuppression".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 <RemoveAlarmSuppressionResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"RemoveAlarmSuppression failed with error: {e.Message}");
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Removes any existing suppression for the specified alarm. For important limits information, see Limits on Monitoring.
        /// Transactions Per Second (TPS) per-tenancy limit for this operation: 1.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task <RemoveAlarmSuppressionResponse> RemoveAlarmSuppression(RemoveAlarmSuppressionRequest param)
        {
            var uri = new Uri($"{GetEndPoint(MonitoringServices.Alarms, this.Region)}/{param.AlarmId}/actions/removeSuppression");

            var httpRequestHeaderParam = new HttpRequestHeaderParam()
            {
                IfMatch      = param.IfMatch,
                OpcRequestId = param.OpcRequestId
            };

            using (var webResponse = await this.RestClientAsync.Post(uri, null, httpRequestHeaderParam))
                using (var stream = webResponse.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        var response = await reader.ReadToEndAsync();

                        return(new RemoveAlarmSuppressionResponse()
                        {
                            OpcRequestId = webResponse.Headers.Get("opc-request-id")
                        });
                    }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            RemoveAlarmSuppressionRequest request;

            try
            {
                request = new RemoveAlarmSuppressionRequest
                {
                    AlarmId      = AlarmId,
                    IfMatch      = IfMatch,
                    OpcRequestId = OpcRequestId
                };

                response = client.RemoveAlarmSuppression(request).GetAwaiter().GetResult();
                WriteOutput(response);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Пример #4
0
        public static async Task MainMonitoring()
        {
            logger.Info("Starting example");

            var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");

            var compartmentId       = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");
            var metricCompartmentId = Environment.GetEnvironmentVariable("METRIC_COMPARTMENT_ID");
            var destinations        = Environment.GetEnvironmentVariable("DESTINATION");

            var monitoringClient = new MonitoringClient(provider);

            string alarmId           = null;
            var    alarmDestinations = new List <string>(destinations.Split(','));

            try
            {
                // Create a new alarm
                var createAlarmDetails = new CreateAlarmDetails
                {
                    DisplayName         = displayName,
                    CompartmentId       = compartmentId,
                    MetricCompartmentId = metricCompartmentId,
                    Namespace           = ociNamespace,
                    Query                      = metricQuery,
                    Resolution                 = resolution,
                    PendingDuration            = pendingDuration,
                    Severity                   = alertSeverity,
                    Body                       = body,
                    Destinations               = alarmDestinations,
                    RepeatNotificationDuration = repeatDuration,
                    IsEnabled                  = true
                };

                CreateAlarmRequest createAlarmRequest = new CreateAlarmRequest
                {
                    CreateAlarmDetails = createAlarmDetails
                };
                var createAlarmResponse = await monitoringClient.CreateAlarm(createAlarmRequest);

                logger.Info($"Created alarm: {displayName}");

                alarmId = createAlarmResponse.Alarm.Id;

                Suppression suppression = new Suppression
                {
                    Description       = "suppress the alarm",
                    TimeSuppressFrom  = suppressFrom,
                    TimeSuppressUntil = suppressUntil
                };

                // Update the new alarm.
                UpdateAlarmDetails updateAlarmDetails = new UpdateAlarmDetails
                {
                    Suppression = suppression
                };
                UpdateAlarmRequest updateAlarmRequest = new UpdateAlarmRequest
                {
                    AlarmId            = alarmId,
                    UpdateAlarmDetails = updateAlarmDetails
                };
                UpdateAlarmResponse updateAlarmResponse = await monitoringClient.UpdateAlarm(updateAlarmRequest);

                logger.Info("Updated alarm");

                RemoveAlarmSuppressionRequest removeAlarmSuppressionRequest = new RemoveAlarmSuppressionRequest
                {
                    AlarmId = alarmId
                };
                RemoveAlarmSuppressionResponse removeAlarmSuppressionResponse = await monitoringClient.RemoveAlarmSuppression(removeAlarmSuppressionRequest);

                logger.Info("removed suppression for the alarm");

                // Get the new alarm
                GetAlarmRequest getAlarmRequest = new GetAlarmRequest
                {
                    AlarmId = alarmId
                };
                GetAlarmResponse getAlarmResponse = await monitoringClient.GetAlarm(getAlarmRequest);

                logger.Info($"Retrieved alarm for id: {getAlarmResponse.Alarm.Id}");

                // Get alarm history
                GetAlarmHistoryRequest getAlarmHistoryRequest = new GetAlarmHistoryRequest
                {
                    AlarmId = alarmId
                };
                GetAlarmHistoryResponse getAlarmHistoryResponse = await monitoringClient.GetAlarmHistory(getAlarmHistoryRequest);

                logger.Info($"Alarm history for id: {alarmId}");
                foreach (var alarmHistoryEntry in getAlarmHistoryResponse.AlarmHistoryCollection.Entries)
                {
                    logger.Info($"summary: {alarmHistoryEntry.Summary}");
                }

                // List alarms
                ListAlarmsRequest listAlarmsRequest = new ListAlarmsRequest
                {
                    CompartmentId = compartmentId,
                    DisplayName   = displayName
                };
                ListAlarmsResponse listAlarmsResponse = await monitoringClient.ListAlarms(listAlarmsRequest);

                logger.Info("Retrieved alarms");
                logger.Info("=================");
                foreach (var alarmSummary in listAlarmsResponse.Items)
                {
                    logger.Info($"Alarm: {alarmSummary.DisplayName}");
                }

                // List alarm status
                ListAlarmsStatusRequest listAlarmsStatusRequest = new ListAlarmsStatusRequest
                {
                    DisplayName   = displayName,
                    CompartmentId = compartmentId
                };
                ListAlarmsStatusResponse listAlarmsStatusResponse = await monitoringClient.ListAlarmsStatus(listAlarmsStatusRequest);

                logger.Info("Retrieved alarms status");
                logger.Info("=======================");
                foreach (var alarmsStatus in listAlarmsStatusResponse.Items)
                {
                    logger.Info($"Status of the alarm: {alarmsStatus.DisplayName} is {alarmsStatus.Status}");
                }
            }
            catch (Exception e)
            {
                logger.Error($"Exception: {e}");
            }
            finally
            {
                if (alarmId != null)
                {
                    DeleteAlarmRequest deleteAlarmRequest = new DeleteAlarmRequest
                    {
                        AlarmId = alarmId
                    };
                    DeleteAlarmResponse deleteAlarmResponse = await monitoringClient.DeleteAlarm(deleteAlarmRequest);

                    logger.Info($"Deleted alam: {displayName}");
                }
                monitoringClient.Dispose();
            }

            logger.Info("End example");
        }