using System; using System.Net.Http; using System.Net.Http.Json; using System.Threading.Tasks; using System.Text.Json; using DotNetEnv; namespace Inventory.Core { public class SlurpitClient { private readonly IHttpClientFactory _httpClientFactory; private readonly SystemInfoCollector _collector; private readonly HealthMonitor _healthMonitor; public SlurpitClient(IHttpClientFactory httpClientFactory, SystemInfoCollector collector, HealthMonitor healthMonitor) { _httpClientFactory = httpClientFactory; _collector = collector; _healthMonitor = healthMonitor; } public async Task SendDeviceData() { var slurpitUrl = Env.GetString("SLURPIT_URL"); var slurpitApiKey = Env.GetString("SLURPIT_API_KEY"); if (string.IsNullOrWhiteSpace(slurpitUrl) || string.IsNullOrWhiteSpace(slurpitApiKey)) { // Don't send if not configured return; } var healthReport = _healthMonitor.CollectHealthMetrics(); var deviceData = new { ComputerName = _collector.GetComputerName(), DeviceType = _collector.GetDeviceType(), SerialNumber = _collector.GetSystemSerialNumber(), MotherboardSerialNumber = _collector.GetMotherboardSerialNumber(), SystemUUID = _collector.GetSystemUUID(), Processor = _collector.GetProcessor(), RAM = _collector.GetTotalRAM(), GPUs = _collector.GetGPUs(), // Send as a proper array HasOpticalDrive = _collector.HasOpticalDrive(), OSVersion = _collector.GetOSVersion(), OsInstallDate = _collector.GetOSInstallDate(), OSLicenseKey = _collector.GetOSLicenseKey(), NetworkInfo = _collector.GetNetworkInfo(), Monitors = _collector.GetMonitors(), Printers = _collector.GetPrinters(), StorageDevices = _collector.GetStorage(), LocalAdmins = _collector.GetLocalAdmins(), HealthReport = healthReport // Send the whole report }; var client = _httpClientFactory.CreateClient(); client.DefaultRequestHeaders.Add("Authorization", $"ApiKey {slurpitApiKey}"); await client.PostAsJsonAsync(slurpitUrl, deviceData); } } }