Fixed regex

This commit is contained in:
Benjamin Höglinger-Stelzer 2023-07-12 15:24:30 +02:00
parent fc73c19a20
commit 2dc6c84a85
3 changed files with 33 additions and 8 deletions

1
.gitignore vendored
View File

@ -398,3 +398,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
/.idea

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=physicaldrive/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -1,8 +1,11 @@
using System.Text.RegularExpressions;
using CliWrap;
using CliWrap.Buffered;
namespace RAIDAlert;
public class Watchdog : BackgroundService
public partial class Watchdog : BackgroundService
{
private const string HpCliUtil = "hpssacli.exe";
private const string PcBeeperUtil = "pc-beeper.exe";
@ -13,19 +16,38 @@ public class Watchdog : BackgroundService
_logger = logger;
}
[GeneratedRegex(@"physicaldrive \d*I:\d*:\d* \(port \d*I:box \d*:bay \d*, SATA, \d*(?:.\d*)? [GT]B, (.+)\)",
RegexOptions.Multiline)]
private partial Regex RegexArrayStatus();
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
string hpSsaCli = Path.Combine(Environment.ProcessPath!, HpCliUtil);
string pcBeeper = Path.Combine(Environment.ProcessPath!, PcBeeperUtil);
var workingDirectory = Path.GetDirectoryName(Environment.ProcessPath!)!;
string hpSsaCli = Path.Combine(workingDirectory, HpCliUtil);
string pcBeeper = Path.Combine(workingDirectory, PcBeeperUtil);
while (!stoppingToken.IsCancellationRequested)
{
var result = await Cli.Wrap("path/to/exe")
.WithArguments(new[] {"--foo", "bar"})
.WithWorkingDirectory("work/dir/path")
.ExecuteAsync();
BufferedCommandResult hpSsaCliResult = await Cli.Wrap(hpSsaCli)
.WithArguments(new[] { "controller", "slot=1", "physicaldrive", "all", "show" })
.WithWorkingDirectory(workingDirectory)
.ExecuteBufferedAsync(stoppingToken);
await Task.Delay(1000, stoppingToken);
MatchCollection matches = RegexArrayStatus().Matches(hpSsaCliResult.StandardOutput);
if (matches.Count == 0)
{
_logger.LogError("Checking for physical disk status yielded no results");
}
else
{
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1].Value);
}
}
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
}