private async Task TimeUntilNextLightShowAsync() { FalconFppdStatusDto fppStatus = await _fppClient.GetFppdStatusAsync(_appSettings.FppHosts[0]); if (fppStatus.IsNull()) { _logger.LogError("FPP did not provide a status"); return; } if (fppStatus.Next_Playlist.Playlist.ContainsOfflineTestOrNull() || fppStatus.Next_Playlist.Playlist == AppConstants.NoPlaylistScheduled) { return; } string nextPlaylistDateTime = fppStatus.Next_Playlist.Start_Time .Substring(0, fppStatus.Next_Playlist.Start_Time.IndexOf(" - ")) .Replace(" @ ", "T"); if (DateTime.TryParse(nextPlaylistDateTime, out DateTime showStartDateTime) == false) { _logger.LogError("Invalid date time or did not match expected format"); return; } await _twitterService.PostTweetAsync( $"{CalculateTimeBetween(DateTime.Now, showStartDateTime)} until the next Light Show. "); }
private async Task CheckCpuTemperatureAsync(FalconFppdStatusDto status) { if (status.IsNull()) { return; } foreach (var sensor in status.Sensors) { string alarmMessage = string.Empty; if (sensor.ValueType.ToLower() == SensorValueType.Temperature) { string celsius = sensor.Value.ToDoubleString(); string fahrenheit = ConvertCelsiusToFahrenheit(sensor.Value).ToDoubleString(); string limitC = _appSettings.Monitoring.MaxCpuTemperatureC.ToDoubleString(); string limitF = ConvertCelsiusToFahrenheit(_appSettings.Monitoring.MaxCpuTemperatureC).ToDoubleString(); _logger.LogInformation($"Temperature {celsius}C, {fahrenheit}F"); if (sensor.Value >= _appSettings.Monitoring.MaxCpuTemperatureC) { alarmMessage = $"Temperature warning! Temperature: {celsius}C, {fahrenheit}F; limit: {limitC}C, {limitF}F"; } } await _twitterService.PostTweetAlarmAsync(alarmMessage); } // end foreach }
public async Task ExecuteVitalsWorkerAsync(CancellationToken stoppingToken) { string previousSecondsPlayed = string.Empty; string previousSecondsRemaining = string.Empty; while (stoppingToken.IsCancellationRequested == false) { ResetAlarmCount(); try { FalconFppdMultiSyncSystemsDto syncStatus = await _fppClient.GetMultiSyncStatusAsync(_appSettings.FppHosts[0]); foreach (var fppInstance in syncStatus.Systems) { _logger.LogInformation($"Checking vitals for {fppInstance.Hostname} ({fppInstance.Address})"); FalconFppdStatusDto falconFppdStatus = await _fppClient.GetFppdStatusAsync(fppInstance.Address); if (falconFppdStatus.IsNull()) { _logger.LogError(ExceptionMessage.FppOffline); continue; } await CheckCpuTemperatureAsync(falconFppdStatus); await CheckStuckSongAsync(falconFppdStatus, previousSecondsPlayed, previousSecondsRemaining); if (falconFppdStatus.Mode_Name.IsRemoteInstance() == false) { previousSecondsPlayed = falconFppdStatus.Seconds_Played; previousSecondsRemaining = falconFppdStatus.Seconds_Remaining; } } } catch (TwitterException ex) { _logger.LogError(ex, ex.Message); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } await Task.Delay(TimeSpan.FromSeconds(DelaySeconds.Long), stoppingToken); } }