Skip to content

Commit

Permalink
Watch event log for disk errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdtrekkie committed Jan 5, 2025
1 parent 4c171b1 commit 187281d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XRFAgent")]
[assembly: AssemblyCopyright("Copyright © 2022-2024 Jacob Weisz")]
[assembly: AssemblyCopyright("Copyright © 2022-2025 Jacob Weisz")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.11")]
[assembly: AssemblyFileVersion("1.0.0.11")]
[assembly: AssemblyVersion("1.0.0.12")]
[assembly: AssemblyFileVersion("1.0.0.12")]
1 change: 1 addition & 0 deletions XRFAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected override void OnStart(string[] args)
modNetwork.Load();
modSync.Load();
modSystem.GetSystemDetails();
modSystem.AttachEventWatcher();

LoadTime.Stop();
modLogging.LogEvent("XRFAgent started in " + LoadTime.Elapsed.Milliseconds + " ms", EventLogEntryType.Information);
Expand Down
2 changes: 1 addition & 1 deletion XRFAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>11</ApplicationRevision>
<ApplicationRevision>12</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
4 changes: 3 additions & 1 deletion docs/ErrorCodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
6042 - Windows Update results (informational)

6051 - Detected new software installed (informational)
6052 - Truncated installed software inventory (informational)
6052 - Truncated installed software inventory (informational)

6061 - Detected disk error
15 changes: 15 additions & 0 deletions modSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.IO;
using System.Text.Json;
using Microsoft.VisualBasic.Devices;
Expand All @@ -20,6 +21,20 @@ public static void Load() { }
/// </summary>
public static void Unload() { }

public static void AttachEventWatcher()
{
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)]]");
EventLogWatcher logWatcher = new EventLogWatcher(logQuery);
logWatcher.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>(EventWritten);
logWatcher.Enabled = true;
}

private static void EventWritten(Object obj, EventRecordWrittenEventArgs arg)
{
modLogging.LogEvent("Detected disk issue", EventLogEntryType.Error, 6061);
modSync.SendSingleConfig("Alert_DiskFailure", "reported");
}

/// <summary>
/// Collects the list of installed applications, updates the local table, and sends to the server.
/// </summary>
Expand Down

0 comments on commit 187281d

Please sign in to comment.