From a4a8143621cdbb2413a9f7b0a32daac9c0d87d65 Mon Sep 17 00:00:00 2001 From: Christopher Cook Date: Fri, 15 Nov 2024 16:17:26 +0800 Subject: [PATCH] Report managed instance os and client details --- .../CertifyManager.ManagementHub.cs | 10 ++++++++- src/Certify.Models/Hub/ManagedInstanceInfo.cs | 5 +++++ src/Certify.Models/Util/EnvironmentUtil.cs | 22 +++++++++++++++---- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Certify.Core/Management/CertifyManager/CertifyManager.ManagementHub.cs b/src/Certify.Core/Management/CertifyManager/CertifyManager.ManagementHub.cs index ce8f43856..7a3411249 100644 --- a/src/Certify.Core/Management/CertifyManager/CertifyManager.ManagementHub.cs +++ b/src/Certify.Core/Management/CertifyManager/CertifyManager.ManagementHub.cs @@ -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 { @@ -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) diff --git a/src/Certify.Models/Hub/ManagedInstanceInfo.cs b/src/Certify.Models/Hub/ManagedInstanceInfo.cs index 38d199f5e..96d068880 100644 --- a/src/Certify.Models/Hub/ManagedInstanceInfo.cs +++ b/src/Certify.Models/Hub/ManagedInstanceInfo.cs @@ -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 Tags { get; set; } = new List(); public DateTimeOffset LastReported { get; set; } } diff --git a/src/Certify.Models/Util/EnvironmentUtil.cs b/src/Certify.Models/Util/EnvironmentUtil.cs index bad3337fe..ae258c9e6 100644 --- a/src/Certify.Models/Util/EnvironmentUtil.cs +++ b/src/Certify.Models/Util/EnvironmentUtil.cs @@ -85,7 +85,7 @@ private static void CreateAndApplyRestrictedACL(string path) /// /// optional subfolder to include /// full app data with with optional subdirectory - public static string CreateAppDataPath(string? subDirectory = null, bool skipCreation=false) + public static string CreateAppDataPath(string? subDirectory = null, bool skipCreation = false) { var parts = new List() { @@ -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 @@ -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}"; } }