mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-24 20:53:06 +00:00
bugfix ntpserver null value
This commit is contained in:
@@ -437,7 +437,7 @@ namespace AutopilotMonitor.Agent.Core.Monitoring.Core
|
||||
{
|
||||
try
|
||||
{
|
||||
var ntpServer = _configuration.NtpServer ?? "time.windows.com";
|
||||
var ntpServer = string.IsNullOrEmpty(_configuration.NtpServer) ? "time.windows.com" : _configuration.NtpServer;
|
||||
var result = NtpTimeCheckService.CheckTime(ntpServer, _logger);
|
||||
|
||||
if (result.Success)
|
||||
|
||||
@@ -1 +1 @@
|
||||
737
|
||||
738
|
||||
|
||||
+1
-1
@@ -464,7 +464,7 @@ namespace AutopilotMonitor.Functions.DataAccess.TableStorage
|
||||
RebootDelaySeconds = entity.GetInt32("RebootDelaySeconds"),
|
||||
EnableGeoLocation = entity.GetBoolean("EnableGeoLocation"),
|
||||
EnableTimezoneAutoSet = entity.GetBoolean("EnableTimezoneAutoSet"),
|
||||
NtpServer = entity.GetString("NtpServer") ?? "time.windows.com",
|
||||
NtpServer = string.IsNullOrWhiteSpace(entity.GetString("NtpServer")) ? "time.windows.com" : entity.GetString("NtpServer"),
|
||||
EnableImeMatchLog = entity.GetBoolean("EnableImeMatchLog"),
|
||||
LogLevel = entity.GetString("LogLevel"),
|
||||
MaxBatchSize = entity.GetInt32("MaxBatchSize"),
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace AutopilotMonitor.Functions.Functions.Config
|
||||
EnableSoftwareInventoryAnalyzer = tenantConfig.EnableSoftwareInventoryAnalyzer ?? false
|
||||
},
|
||||
LatestAgentSha256 = adminConfig.LatestAgentSha256,
|
||||
NtpServer = tenantConfig.NtpServer ?? "time.windows.com",
|
||||
NtpServer = string.IsNullOrEmpty(tenantConfig.NtpServer) ? "time.windows.com" : tenantConfig.NtpServer,
|
||||
EnableTimezoneAutoSet = tenantConfig.EnableTimezoneAutoSet ?? false,
|
||||
SendTraceEvents = tenantConfig.SendTraceEvents,
|
||||
UnrestrictedMode = tenantConfig.UnrestrictedModeEnabled && tenantConfig.UnrestrictedMode,
|
||||
|
||||
@@ -155,6 +155,10 @@ namespace AutopilotMonitor.Functions.Services
|
||||
// Backfill OnboardedAt for tenants that don't have it yet
|
||||
// TODO: Remove once all tenants have been backfilled
|
||||
await BackfillTenantOnboardedAtAsync();
|
||||
|
||||
// Backfill NtpServer for tenants with null/empty value
|
||||
// TODO: Remove after 2026-06-01
|
||||
await BackfillNtpServerDefaultAsync();
|
||||
}
|
||||
|
||||
await RecomputePlatformStatsAsync();
|
||||
@@ -406,6 +410,51 @@ namespace AutopilotMonitor.Functions.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Backfills NtpServer for tenants that have null or empty value.
|
||||
/// Sets them to the default "time.windows.com".
|
||||
/// Self-healing: runs every manual maintenance cycle, no-ops once all tenants are backfilled.
|
||||
/// TODO: Remove after 2026-06-01
|
||||
/// </summary>
|
||||
private async Task BackfillNtpServerDefaultAsync()
|
||||
{
|
||||
_logger.LogInformation("Backfilling NtpServer for tenants with missing value...");
|
||||
|
||||
try
|
||||
{
|
||||
var allConfigs = await _tenantConfigService.GetAllConfigurationsAsync();
|
||||
var configsMissingNtp = allConfigs.Where(c => string.IsNullOrEmpty(c.NtpServer)).ToList();
|
||||
|
||||
if (configsMissingNtp.Count == 0)
|
||||
{
|
||||
_logger.LogInformation("All tenants already have NtpServer set");
|
||||
return;
|
||||
}
|
||||
|
||||
int backfilledCount = 0;
|
||||
|
||||
foreach (var config in configsMissingNtp)
|
||||
{
|
||||
try
|
||||
{
|
||||
config.NtpServer = "time.windows.com";
|
||||
await _tenantConfigService.SaveConfigurationAsync(config);
|
||||
backfilledCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to backfill NtpServer for tenant {TenantId}", config.TenantId);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("NtpServer backfill completed: {Count} tenants updated", backfilledCount);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to backfill NtpServer for tenants");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggregates metrics for any missed days in the last 7 days, plus yesterday.
|
||||
/// Checks the UsageMetrics table for existing snapshots to avoid re-aggregation.
|
||||
|
||||
@@ -545,7 +545,8 @@ namespace AutopilotMonitor.Shared.Models
|
||||
SelfDestructOnComplete = true,
|
||||
KeepLogFile = false,
|
||||
ShowScriptOutput = true,
|
||||
OnboardedAt = DateTime.UtcNow
|
||||
OnboardedAt = DateTime.UtcNow,
|
||||
NtpServer = "time.windows.com"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user