Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

refactor: fix lint issues in internal/ai package

rcourtman31c704c7a713
diff --git a/internal/ai/intelligence.go b/internal/ai/intelligence.go
index 1f380a740b..75e9f95d61 100644
--- a/internal/ai/intelligence.go
+++ b/internal/ai/intelligence.go
@@ -926,7 +926,7 @@ func (i *Intelligence) formatAnomaliesForContext(anomalies []AnomalyReport) stri
return strings.Join(lines, "\n")
}
-func (i *Intelligence) formatAnomalyDescription(metric string, value float64, bl *baseline.MetricBaseline, zScore float64) string {
+func (i *Intelligence) formatAnomalyDescription(_ string, value float64, bl *baseline.MetricBaseline, zScore float64) string {
direction := "above"
if zScore < 0 {
direction = "below"
diff --git a/internal/ai/intelligence_test.go b/internal/ai/intelligence_test.go
index aacc232a27..0f69d597da 100644
--- a/internal/ai/intelligence_test.go
+++ b/internal/ai/intelligence_test.go
@@ -494,7 +494,7 @@ func TestIntelligence_GetResourceIntelligence_WithBaselines(t *testing.T) {
resourceIntel := intel.GetResourceIntelligence("vm-with-baseline")
// Should have baselines
- if resourceIntel.Baselines == nil || len(resourceIntel.Baselines) == 0 {
+ if len(resourceIntel.Baselines) == 0 {
t.Error("Expected baselines to be populated")
}
diff --git a/internal/ai/patrol.go b/internal/ai/patrol.go
index 13886f977d..6c94259a31 100644
--- a/internal/ai/patrol.go
+++ b/internal/ai/patrol.go
@@ -2205,9 +2205,10 @@ func (p *PatrolService) analyzeKubernetesCluster(cluster models.KubernetesCluste
for _, pod := range cluster.Pods {
phase := strings.ToLower(strings.TrimSpace(pod.Phase))
- if phase == "failed" {
+ switch phase {
+ case "failed":
failedPods++
- } else if phase == "pending" {
+ case "pending":
pendingPods++
}
@@ -2681,9 +2682,10 @@ func (p *PatrolService) buildInfrastructureSummary(state models.StateSnapshot) s
problemPods := 0
for _, pod := range cluster.Pods {
phase := strings.ToLower(strings.TrimSpace(pod.Phase))
- if phase == "running" {
+ switch phase {
+ case "running":
runningPods++
- } else if phase == "failed" || phase == "pending" {
+ case "failed", "pending":
problemPods++
}
}
@@ -3119,11 +3121,12 @@ func (p *PatrolService) checkAnomalies(resourceID, resourceName, resourceType st
})
// Record this as an event for correlation if it's a spike
- if metric == "cpu" {
+ switch metric {
+ case "cpu":
p.recordEvent(resourceID, resourceName, resourceType, CorrelationEventHighCPU, value)
- } else if metric == "memory" {
+ case "memory":
p.recordEvent(resourceID, resourceName, resourceType, CorrelationEventHighMem, value)
- } else if metric == "disk" {
+ case "disk":
p.recordEvent(resourceID, resourceName, resourceType, CorrelationEventDiskFull, value)
}
}
diff --git a/internal/ai/patrol_test.go b/internal/ai/patrol_test.go
index 2eb92cf20d..01670f21ff 100644
--- a/internal/ai/patrol_test.go
+++ b/internal/ai/patrol_test.go
@@ -514,9 +514,30 @@ func TestPatrolRunRecord(t *testing.T) {
if record.ID != "test-run-1" {
t.Errorf("Expected ID 'test-run-1', got '%s'", record.ID)
}
+ if record.CompletedAt != now.Add(5*time.Second) {
+ t.Error("Expected CompletedAt to match now + 5s")
+ }
+ if record.Duration != 5*time.Second {
+ t.Errorf("Expected duration 5s, got %v", record.Duration)
+ }
if record.ResourcesChecked != 10 {
t.Errorf("Expected 10 resources checked, got %d", record.ResourcesChecked)
}
+ if record.StartedAt != now {
+ t.Error("Expected StartedAt to match now")
+ }
+ if record.Type != "patrol" {
+ t.Errorf("Expected type 'patrol', got '%s'", record.Type)
+ }
+ if record.NodesChecked != 2 {
+ t.Errorf("Expected 2 nodes checked, got %d", record.NodesChecked)
+ }
+ if record.GuestsChecked != 5 {
+ t.Errorf("Expected 5 guests checked, got %d", record.GuestsChecked)
+ }
+ if record.NewFindings != 1 {
+ t.Errorf("Expected 1 new finding, got %d", record.NewFindings)
+ }
if record.Status != "issues_found" {
t.Errorf("Expected status 'issues_found', got '%s'", record.Status)
}
@@ -542,12 +563,33 @@ func TestPatrolStatus_Fields(t *testing.T) {
if !status.Running {
t.Error("Expected running to be true")
}
+ if !status.Enabled {
+ t.Error("Expected enabled to be true")
+ }
if status.FindingsCount != 3 {
t.Errorf("Expected 3 findings, got %d", status.FindingsCount)
}
if status.LastPatrolAt == nil {
t.Error("Expected LastPatrolAt to be set")
}
+ if *status.NextPatrolAt != next {
+ t.Error("NextPatrolAt value mismatch")
+ }
+ if status.LastDuration != 5*time.Second {
+ t.Errorf("Expected last duration 5s, got %v", status.LastDuration)
+ }
+ if status.ResourcesChecked != 25 {
+ t.Errorf("Expected 25 resources checked, got %d", status.ResourcesChecked)
+ }
+ if status.FindingsCount != 3 {
+ t.Errorf("Expected 3 findings, got %d", status.FindingsCount)
+ }
+ if status.ErrorCount != 0 {
+ t.Errorf("Expected 0 errors, got %d", status.ErrorCount)
+ }
+ if status.Healthy {
+ t.Error("Expected Healthy to be false")
+ }
if status.IntervalMs != 900000 {
t.Errorf("Expected interval 900000ms, got %d", status.IntervalMs)
}
diff --git a/internal/ai/resource_context.go b/internal/ai/resource_context.go
index 5b7ebc61ed..32bab3b09d 100644
--- a/internal/ai/resource_context.go
+++ b/internal/ai/resource_context.go
@@ -181,11 +181,12 @@ func (s *Service) buildUnifiedResourceContext() string {
sections = append(sections, fmt.Sprintf("\n**On %s:**", parentName))
for _, w := range children {
typeLabel := string(w.Type)
- if w.Type == resources.ResourceTypeVM {
+ switch w.Type {
+ case resources.ResourceTypeVM:
typeLabel = "VM"
- } else if w.Type == resources.ResourceTypeContainer {
+ case resources.ResourceTypeContainer:
typeLabel = "LXC"
- } else if w.Type == resources.ResourceTypeDockerContainer {
+ case resources.ResourceTypeDockerContainer:
typeLabel = "Docker"
}
diff --git a/internal/ai/service.go b/internal/ai/service.go
index 1e36833716..170d138d3a 100644
--- a/internal/ai/service.go
+++ b/internal/ai/service.go
@@ -1895,7 +1895,7 @@ func isActionableCommand(cmd string) bool {
// generateRemediationSummary creates a human-readable summary of what a command achieved
// This is used to display meaningful descriptions in the Pulse AI Impact section
-func generateRemediationSummary(command string, targetType string, context map[string]interface{}) string {
+func generateRemediationSummary(command string, _ string, context map[string]interface{}) string {
cmd := strings.TrimSpace(command)
// Extract target name from context
@@ -3604,7 +3604,7 @@ func truncateString(s string, maxLen int) string {
// - Trend analysis ("memory growing 5%/day")
// - Predictions ("disk full in 12 days")
// - Recent changes ("config changed 2 hours ago")
-func (s *Service) buildEnrichedResourceContext(resourceID, resourceType string, currentMetrics map[string]interface{}) string {
+func (s *Service) buildEnrichedResourceContext(resourceID, _ string, currentMetrics map[string]interface{}) string {
s.mu.RLock()
patrol := s.patrolService
s.mu.RUnlock()
diff --git a/internal/ai/service_extended_test.go b/internal/ai/service_extended_test.go
index 5c5efbba90..781dba1195 100644
--- a/internal/ai/service_extended_test.go
+++ b/internal/ai/service_extended_test.go
@@ -2665,7 +2665,7 @@ func TestService_EnrichRequestFromFinding(t *testing.T) {
Prompt: "Just a question",
}
svc.enrichRequestFromFinding(&req3)
- if req3.Context != nil && len(req3.Context) > 0 {
+ if len(req3.Context) > 0 {
t.Error("Should not add context when no FindingID")
}
@@ -2675,7 +2675,7 @@ func TestService_EnrichRequestFromFinding(t *testing.T) {
Prompt: "Help",
}
svc.enrichRequestFromFinding(&req4)
- if req4.Context != nil && len(req4.Context) > 0 {
+ if len(req4.Context) > 0 {
t.Error("Should not add context when finding not found")
}
}