diff --git a/Watchdog.cs b/Watchdog.cs index 6a6e7d0..aa18b51 100644 --- a/Watchdog.cs +++ b/Watchdog.cs @@ -22,10 +22,21 @@ public partial class Watchdog : BackgroundService 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 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) { BufferedCommandResult hpSsaCliResult = await Cli.Wrap(hpSsaCli) @@ -41,9 +52,26 @@ public partial class Watchdog : BackgroundService } 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); } }