public async Task <Alarm> GetAlarmAsync(GetAlarmRequest request, DateTime?deadline) { if (request is null) { throw new ArgumentNullException(nameof(request)); } PlcFrame response = await this.InvokeAsync( PlcFrame.Create(PlcMessageType.GetAlarmRequest, ByteString.Empty), deadline) .ConfigureAwait(false); if (response.FrameHeader.MessageType != PlcMessageType.GetAlarmResponse) { throw new InvalidDataException( "Response message type mismatch: " + response.FrameHeader.MessageType); } using var reader = new BinaryReader(new MemoryStream(response.FrameBody.ToByteArray())); return(new Alarm { CreateTime = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow), LowFlowRate = reader.ReadByte() != 0, HighHeaterPressure = reader.ReadByte() != 0, LowHeaterPressure = reader.ReadByte() != 0, NoPower = reader.ReadByte() != 0, HeaterOverloadedBroken = reader.ReadByte() != 0, ElectricalHeaterBroken = reader.ReadByte() != 0, NoWater = reader.ReadByte() == 0, HighVoltage = reader.ReadByte() == 0, LowVoltage = reader.ReadByte() == 0, EmergencyStopped = reader.ReadByte() == 0, }); }
/// <summary> /// Gets the specified alarm. /// For important limits information, see [Limits on Monitoring](https://docs.cloud.oracle.com/iaas/Content/Monitoring/Concepts/monitoringoverview.htm#Limits). /// <br/> /// 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/GetAlarm.cs.html">here</a> to see an example of how to use GetAlarm API.</example> public async Task <GetAlarmResponse> GetAlarm(GetAlarmRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called getAlarm"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/alarms/{alarmId}".Trim('/'))); HttpMethod method = new HttpMethod("GET"); 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 <GetAlarmResponse>(responseMessage)); } catch (Exception e) { logger.Error($"GetAlarm failed with error: {e.Message}"); throw; } }
public override Task <GrpcAlarm> GetAlarm(GetAlarmRequest request, ServerCallContext context) { return(this.Invoke( (client, request, deadline) => client.GetAlarmAsync(request, deadline), request.DeviceId, request, context)); }
/// <summary> /// Creates a waiter using the provided configuration. /// </summary> /// <param name="request">Request to send.</param> /// <param name="config">Wait Configuration</param> /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param> /// <returns>a new Oci.common.Waiter instance</returns> public Waiter <GetAlarmRequest, GetAlarmResponse> ForAlarm(GetAlarmRequest request, WaiterConfiguration config, params Alarm.LifecycleStateEnum[] targetStates) { var agent = new WaiterAgent <GetAlarmRequest, GetAlarmResponse>( request, request => client.GetAlarm(request), response => targetStates.Contains(response.Alarm.LifecycleState.Value), targetStates.Contains(Alarm.LifecycleStateEnum.Deleted) ); return(new Waiter <GetAlarmRequest, GetAlarmResponse>(config, agent)); }
/// <summary> /// Gets 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 <GetAlarmResponse> GetAlarm(GetAlarmRequest param) { var uri = new Uri($"{GetEndPoint(MonitoringServices.Alarms, this.Region)}/{param.AlarmId}"); using (var webResponse = await this.RestClientAsync.Get(uri, new HttpRequestHeaderParam() { OpcRequestId = param.OpcRequestId })) using (var stream = webResponse.GetResponseStream()) using (var reader = new StreamReader(stream)) { var response = await reader.ReadToEndAsync(); return(new GetAlarmResponse() { AlarmModel = JsonSerializer.Deserialize <AlarmModel>(response), OpcRequestId = webResponse.Headers.Get("opc-request-id") }); } }
private void HandleOutput(GetAlarmRequest request) { var waiterConfig = new WaiterConfiguration { MaxAttempts = MaxWaitAttempts, GetNextDelayInSeconds = (_) => WaitIntervalSeconds }; switch (ParameterSetName) { case LifecycleStateParamSet: response = client.Waiters.ForAlarm(request, waiterConfig, WaitForLifecycleState).Execute(); break; case Default: response = client.GetAlarm(request).GetAwaiter().GetResult(); break; } WriteOutput(response, response.Alarm); }
protected override void ProcessRecord() { base.ProcessRecord(); GetAlarmRequest request; try { request = new GetAlarmRequest { AlarmId = AlarmId, OpcRequestId = OpcRequestId }; HandleOutput(request); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/// <summary> /// Creates a waiter using default wait configuration. /// </summary> /// <param name="request">Request to send.</param> /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param> /// <returns>a new Oci.common.Waiter instance</returns> public Waiter <GetAlarmRequest, GetAlarmResponse> ForAlarm(GetAlarmRequest request, params Alarm.LifecycleStateEnum[] targetStates) { return(this.ForAlarm(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates)); }
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"); }