Skip to content

Commit

Permalink
Report managed instance os and client details
Browse files Browse the repository at this point in the history
  • Loading branch information
webprofusion-chrisc committed Nov 15, 2024
1 parent 8322a58 commit a4a8143
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Certify.Models;
using Certify.Models.Config;
using Certify.Shared.Core.Utils;
using System.Runtime.InteropServices;
using Certify.Locales;

namespace Certify.Management
{
Expand Down Expand Up @@ -46,10 +48,16 @@ private async Task StartManagementHubConnection(string hubUri)

_serviceLog.Debug("Attempting connection to management hub {hubUri}", hubUri);

var appVersion = Util.GetAppVersion().ToString();

var instanceInfo = new ManagedInstanceInfo
{
InstanceId = $"{this.InstanceId}",
Title = $"{Environment.MachineName} [{EnvironmentUtil.GetFriendlyOSName()}]",
Title = $"{Environment.MachineName}",
OS = EnvironmentUtil.GetFriendlyOSName(detailed: false),
OSVersion = EnvironmentUtil.GetFriendlyOSName(),
ClientVersion = appVersion,
ClientName = ConfigResources.AppName
};

if (_managementServerClient != null)
Expand Down
5 changes: 5 additions & 0 deletions src/Certify.Models/Hub/ManagedInstanceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public class ManagedInstanceInfo
{
public string InstanceId { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string OS { get; set; } = string.Empty;
public string OSVersion { get; set; } = string.Empty;
public string ClientName { get; set; } = string.Empty;
public string ClientVersion { get; set; } = string.Empty;

public List<string> Tags { get; set; } = new List<string>();
public DateTimeOffset LastReported { get; set; }
}
Expand Down
22 changes: 18 additions & 4 deletions src/Certify.Models/Util/EnvironmentUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static void CreateAndApplyRestrictedACL(string path)
/// </summary>
/// <param name="subDirectory">optional subfolder to include</param>
/// <returns>full app data with with optional subdirectory</returns>
public static string CreateAppDataPath(string? subDirectory = null, bool skipCreation=false)
public static string CreateAppDataPath(string? subDirectory = null, bool skipCreation = false)
{
var parts = new List<string>()
{
Expand Down Expand Up @@ -119,14 +119,19 @@ public static string CreateAppDataPath(string? subDirectory = null, bool skipCre
return path;
}

public static string GetFriendlyOSName()
public static string GetFriendlyOSName(bool detailed = true)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return $"{RuntimeInformation.OSDescription}";
return detailed ? $"{RuntimeInformation.OSDescription}" : "Windows";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (!detailed)
{
return "Linux";
}

var filePath = "/etc/os-release";

try
Expand All @@ -149,7 +154,16 @@ public static string GetFriendlyOSName()
return $"Linux - {RuntimeInformation.OSDescription}";
}
}

else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return detailed ? $"{RuntimeInformation.OSDescription}" : "macOS";
}
#if NET9_0_OR_GREATER
else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
{
return detailed ? $"{RuntimeInformation.OSDescription}" : "FreeBSD";
}
#endif
return $"{RuntimeInformation.OSDescription}";
}
}
Expand Down

0 comments on commit a4a8143

Please sign in to comment.