Update Watchdog.cs

This commit is contained in:
Benjamin Höglinger-Stelzer 2023-07-12 15:40:13 +02:00
parent 2dc6c84a85
commit e998affd38

View File

@ -22,10 +22,21 @@ public partial class Watchdog : BackgroundService
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{ {
var workingDirectory = Path.GetDirectoryName(Environment.ProcessPath!)!; string workingDirectory = Path.GetDirectoryName(Environment.ProcessPath!)!;
string hpSsaCli = Path.Combine(workingDirectory, HpCliUtil); string hpSsaCli = Path.Combine(workingDirectory, HpCliUtil);
string pcBeeper = Path.Combine(workingDirectory, PcBeeperUtil); string pcBeeper = Path.Combine(workingDirectory, PcBeeperUtil);
// Ready beep sequence
await Cli.Wrap(pcBeeper)
.WithArguments(new[] { "-f", "1500", "-d", "100" })
.WithWorkingDirectory(workingDirectory)
.ExecuteAsync(stoppingToken);
await Task.Delay(TimeSpan.FromMilliseconds(10), stoppingToken);
await Cli.Wrap(pcBeeper)
.WithArguments(new[] { "-f", "2000", "-d", "100" })
.WithWorkingDirectory(workingDirectory)
.ExecuteAsync(stoppingToken);
while (!stoppingToken.IsCancellationRequested) while (!stoppingToken.IsCancellationRequested)
{ {
BufferedCommandResult hpSsaCliResult = await Cli.Wrap(hpSsaCli) BufferedCommandResult hpSsaCliResult = await Cli.Wrap(hpSsaCli)
@ -41,9 +52,26 @@ public partial class Watchdog : BackgroundService
} }
else else
{ {
foreach (Match match in matches) bool allHealthy = matches.All(m => m.Groups[1].Value.Equals("OK", StringComparison.OrdinalIgnoreCase));
if (!allHealthy)
{ {
Console.WriteLine(match.Groups[1].Value); _logger.LogError("One or more disks reported faulty status");
await Cli.Wrap(pcBeeper)
.WithArguments(new[] { "-f", "3000", "-d", "500" })
.WithWorkingDirectory(workingDirectory)
.ExecuteAsync(stoppingToken);
await Task.Delay(TimeSpan.FromMilliseconds(100), stoppingToken);
await Cli.Wrap(pcBeeper)
.WithArguments(new[] { "-f", "3000", "-d", "500" })
.WithWorkingDirectory(workingDirectory)
.ExecuteAsync(stoppingToken);
await Task.Delay(TimeSpan.FromMilliseconds(100), stoppingToken);
await Cli.Wrap(pcBeeper)
.WithArguments(new[] { "-f", "3000", "-d", "500" })
.WithWorkingDirectory(workingDirectory)
.ExecuteAsync(stoppingToken);
} }
} }