Skip to content

Commit 187281d

Browse files
committed
Watch event log for disk errors
1 parent 4c171b1 commit 187281d

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

Properties/AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
1212
[assembly: AssemblyProduct("XRFAgent")]
13-
[assembly: AssemblyCopyright("Copyright © 2022-2024 Jacob Weisz")]
13+
[assembly: AssemblyCopyright("Copyright © 2022-2025 Jacob Weisz")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.11")]
36-
[assembly: AssemblyFileVersion("1.0.0.11")]
35+
[assembly: AssemblyVersion("1.0.0.12")]
36+
[assembly: AssemblyFileVersion("1.0.0.12")]

XRFAgent.cs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected override void OnStart(string[] args)
3939
modNetwork.Load();
4040
modSync.Load();
4141
modSystem.GetSystemDetails();
42+
modSystem.AttachEventWatcher();
4243

4344
LoadTime.Stop();
4445
modLogging.LogEvent("XRFAgent started in " + LoadTime.Elapsed.Milliseconds + " ms", EventLogEntryType.Information);

XRFAgent.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<UpdatePeriodically>false</UpdatePeriodically>
2626
<UpdateRequired>false</UpdateRequired>
2727
<MapFileExtensions>true</MapFileExtensions>
28-
<ApplicationRevision>11</ApplicationRevision>
28+
<ApplicationRevision>12</ApplicationRevision>
2929
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
3030
<UseApplicationTrust>false</UseApplicationTrust>
3131
<BootstrapperEnabled>true</BootstrapperEnabled>

docs/ErrorCodes.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
6042 - Windows Update results (informational)
1919

2020
6051 - Detected new software installed (informational)
21-
6052 - Truncated installed software inventory (informational)
21+
6052 - Truncated installed software inventory (informational)
22+
23+
6061 - Detected disk error

modSystem.cs

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Diagnostics.Eventing.Reader;
45
using System.IO;
56
using System.Text.Json;
67
using Microsoft.VisualBasic.Devices;
@@ -20,6 +21,20 @@ public static void Load() { }
2021
/// </summary>
2122
public static void Unload() { }
2223

24+
public static void AttachEventWatcher()
25+
{
26+
EventLogQuery logQuery = new EventLogQuery("System", PathType.LogName, "*[System[Provider[@Name='disk'] and (EventID=7 or EventID=11 or EventID=25 or EventID=26 or EventID=51 or EventID=55)]]");
27+
EventLogWatcher logWatcher = new EventLogWatcher(logQuery);
28+
logWatcher.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>(EventWritten);
29+
logWatcher.Enabled = true;
30+
}
31+
32+
private static void EventWritten(Object obj, EventRecordWrittenEventArgs arg)
33+
{
34+
modLogging.LogEvent("Detected disk issue", EventLogEntryType.Error, 6061);
35+
modSync.SendSingleConfig("Alert_DiskFailure", "reported");
36+
}
37+
2338
/// <summary>
2439
/// Collects the list of installed applications, updates the local table, and sends to the server.
2540
/// </summary>

0 commit comments

Comments
 (0)