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.

Fix: discovery routing, host identification, and UX feedback

rcourtmanc2ed6067f173
diff --git a/frontend-modern/src/components/Discovery/DiscoveryTab.tsx b/frontend-modern/src/components/Discovery/DiscoveryTab.tsx
index 7e5a414f28..42bfa5f27e 100644
--- a/frontend-modern/src/components/Discovery/DiscoveryTab.tsx
+++ b/frontend-modern/src/components/Discovery/DiscoveryTab.tsx
@@ -71,7 +71,9 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {
};
const [notesText, setNotesText] = createSignal('');
const [saveError, setSaveError] = createSignal<string | null>(null);
+ const [scanError, setScanError] = createSignal<string | null>(null);
const [scanProgress, setScanProgress] = createSignal<DiscoveryProgress | null>(null);
+ const [scanSuccess, setScanSuccess] = createSignal(false);
// Fetch discovery data
const [discovery, { refetch, mutate }] = createResource(
@@ -89,18 +91,32 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {
const handleTriggerDiscovery = async (force = false) => {
setIsScanning(true);
setScanProgress(null);
+ setScanError(null);
+ setScanSuccess(false);
try {
- // triggerDiscovery returns the discovery data directly
- const result = await triggerDiscovery(props.resourceType, props.hostId, props.resourceId, {
+ // triggerDiscovery runs the discovery and returns the result
+ await triggerDiscovery(props.resourceType, props.hostId, props.resourceId, {
force,
hostname: props.hostname,
});
- // Use mutate to directly update the resource with the returned data
- // This provides immediate UI feedback without needing a refetch
- mutate(result);
+ // Scan complete - hide progress bar
+ setIsScanning(false);
+ // Refetch to get the saved discovery data (shows brief loading state)
+ await refetch();
+ // Now show success - data is already visible
+ setScanSuccess(true);
+ // Clear success after user has seen it
+ setTimeout(() => setScanSuccess(false), 2000);
} catch (err) {
console.error('Discovery failed:', err);
- } finally {
+ // Extract error message for display
+ const message = err instanceof Error ? err.message : 'Discovery scan failed';
+ // Provide helpful message if it's a connection issue
+ if (message.includes('no connected agent')) {
+ setScanError('No agent available. Enable "Pulse Commands" in Settings → Unified Agents for this host.');
+ } else {
+ setScanError(message);
+ }
setIsScanning(false);
setScanProgress(null);
}
@@ -163,10 +179,33 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {
const confidenceInfo = () => {
const d = discovery();
- if (!d) return null;
+ if (!d || d.confidence === undefined || d.confidence === null) return null;
return getConfidenceLevel(d.confidence);
};
+ // Check if discovery has meaningful data (not empty/unknown results)
+ const hasValidDiscovery = () => {
+ const d = discovery();
+ if (!d) return false;
+ // Consider valid if:
+ // - Has a service name that's not empty and not "unknown" (case-insensitive)
+ // - OR has a confidence value above 0
+ // - OR has any discovered ports, facts, paths, etc.
+ const hasServiceName = d.service_name && d.service_name.toLowerCase() !== 'unknown';
+ const hasConfidence = typeof d.confidence === 'number' && d.confidence > 0;
+ const hasPorts = d.ports && d.ports.length > 0;
+ const hasFacts = d.facts && d.facts.length > 0;
+ const hasPaths = (d.config_paths && d.config_paths.length > 0) ||
+ (d.data_paths && d.data_paths.length > 0) ||
+ (d.log_paths && d.log_paths.length > 0);
+ const hasCliAccess = !!d.cli_access;
+
+ return hasServiceName || hasConfidence || hasPorts || hasFacts || hasPaths || hasCliAccess;
+ };
+
+ // Accessor that returns discovery only when valid (for use with Show component)
+ const validDiscovery = () => hasValidDiscovery() ? discovery() : null;
+
return (
<div class="space-y-4">
{/* Loading state */}
@@ -210,6 +249,41 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {
</div>
</Show>
+ {/* Scan Success */}
+ <Show when={scanSuccess()}>
+ <div class="mb-4 rounded-lg border border-green-200 bg-green-50 p-4 dark:border-green-800 dark:bg-green-900/20">
+ <div class="flex items-center gap-2">
+ <svg class="w-5 h-5 text-green-500 dark:text-green-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
+ </svg>
+ <p class="text-sm font-medium text-green-800 dark:text-green-200">Discovery complete!</p>
+ </div>
+ </div>
+ </Show>
+
+ {/* Scan Error */}
+ <Show when={scanError()}>
+ <div class="mb-4 rounded-lg border border-red-200 bg-red-50 p-4 dark:border-red-800 dark:bg-red-900/20">
+ <div class="flex items-start gap-3">
+ <svg class="w-5 h-5 text-red-500 dark:text-red-400 flex-shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
+ </svg>
+ <div>
+ <p class="text-sm font-medium text-red-800 dark:text-red-200">Discovery Failed</p>
+ <p class="text-sm text-red-700 dark:text-red-300 mt-1">{scanError()}</p>
+ </div>
+ <button
+ onClick={() => setScanError(null)}
+ class="ml-auto text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300"
+ >
+ <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
+ </svg>
+ </button>
+ </div>
+ </div>
+ </Show>
+
{/* No discovery yet */}
<Show when={!discovery.loading && !discovery()}>
<div class="text-center py-8">
@@ -239,8 +313,42 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {
</div>
</Show>
- {/* Discovery data */}
- <Show when={discovery()}>
+ {/* Discovery exists but has no meaningful data - show re-scan option */}
+ <Show when={!discovery.loading && discovery() && !hasValidDiscovery()}>
+ <div class="text-center py-8">
+ <div class="text-gray-500 dark:text-gray-400 mb-4">
+ <svg class="w-12 h-12 mx-auto mb-2 opacity-50" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
+ </svg>
+ <p class="text-sm">Unknown Service</p>
+ <p class="text-xs text-gray-400 dark:text-gray-500 mt-1">
+ Discovery completed but couldn't identify a known service.
+ </p>
+ <Show when={discovery()?.updated_at}>
+ <p class="text-xs text-gray-400 dark:text-gray-500 mt-2">
+ Last scanned: {formatDiscoveryAge(discovery()!.updated_at)}
+ </p>
+ </Show>
+ </div>
+ <button
+ onClick={() => handleTriggerDiscovery(true)}
+ disabled={isScanning()}
+ class="px-4 py-2 bg-blue-600 text-white text-sm rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
+ >
+ {isScanning() ? (
+ <span class="flex items-center justify-center">
+ <span class="animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full mr-2"></span>
+ Scanning...
+ </span>
+ ) : (
+ 'Re-scan Discovery'
+ )}
+ </button>
+ </div>
+ </Show>
+
+ {/* Discovery data with valid results */}
+ <Show when={validDiscovery()}>
{(d) => (
<div class="space-y-4">
{/* Service Header */}
@@ -265,7 +373,7 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {
<Show when={confidenceInfo()}>
<p class={`text-xs mt-2 ${confidenceInfo()!.color}`}>
- {confidenceInfo()!.label} ({Math.round(d().confidence * 100)}%)
+ {confidenceInfo()!.label} ({Math.round((d().confidence || 0) * 100)}%)
</p>
</Show>
</div>
diff --git a/internal/api/router.go b/internal/api/router.go
index 67905725bf..2c2a25110e 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -1506,7 +1506,59 @@ func (r *Router) setupRoutes() {
r.mux.HandleFunc("/api/discovery/status", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.discoveryHandlers.HandleGetStatus)))
r.mux.HandleFunc("/api/discovery/settings", RequireAuth(r.config, RequireScope(config.ScopeSettingsWrite, r.discoveryHandlers.HandleUpdateSettings)))
r.mux.HandleFunc("/api/discovery/type/", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.discoveryHandlers.HandleListByType)))
- r.mux.HandleFunc("/api/discovery/host/", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.discoveryHandlers.HandleListByHost)))
+ r.mux.HandleFunc("/api/discovery/host/", RequireAuth(r.config, func(w http.ResponseWriter, req *http.Request) {
+ // Route based on method and path depth:
+ // GET /api/discovery/host/{hostId} → list discoveries for host
+ // GET /api/discovery/host/{hostId}/{resourceId} → get specific discovery
+ // GET /api/discovery/host/{hostId}/{resourceId}/progress → get scan progress
+ // POST /api/discovery/host/{hostId}/{resourceId} → trigger discovery
+ // PUT /api/discovery/host/{hostId}/{resourceId}/notes → update notes
+ // DELETE /api/discovery/host/{hostId}/{resourceId} → delete discovery
+ path := strings.TrimPrefix(req.URL.Path, "/api/discovery/host/")
+ pathParts := strings.Split(strings.TrimSuffix(path, "/"), "/")
+
+ switch req.Method {
+ case http.MethodGet:
+ if !ensureScope(w, req, config.ScopeMonitoringRead) {
+ return
+ }
+ if len(pathParts) == 1 && pathParts[0] != "" {
+ // GET /api/discovery/host/{hostId} → list by host
+ r.discoveryHandlers.HandleListByHost(w, req)
+ } else if len(pathParts) >= 2 {
+ if strings.HasSuffix(req.URL.Path, "/progress") {
+ r.discoveryHandlers.HandleGetProgress(w, req)
+ } else {
+ // GET /api/discovery/host/{hostId}/{resourceId} → get specific discovery
+ r.discoveryHandlers.HandleGetDiscovery(w, req)
+ }
+ } else {
+ http.Error(w, "Invalid path", http.StatusBadRequest)
+ }
+ case http.MethodPost:
+ if !ensureScope(w, req, config.ScopeMonitoringWrite) {
+ return
+ }
+ // POST /api/discovery/host/{hostId}/{resourceId} → trigger discovery
+ r.discoveryHandlers.HandleTriggerDiscovery(w, req)
+ case http.MethodPut:
+ if !ensureScope(w, req, config.ScopeMonitoringWrite) {
+ return
+ }
+ if strings.HasSuffix(req.URL.Path, "/notes") {
+ r.discoveryHandlers.HandleUpdateNotes(w, req)
+ } else {
+ http.Error(w, "Not found", http.StatusNotFound)
+ }
+ case http.MethodDelete:
+ if !ensureScope(w, req, config.ScopeMonitoringWrite) {
+ return
+ }
+ r.discoveryHandlers.HandleDeleteDiscovery(w, req)
+ default:
+ http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
+ }
+ }))
r.mux.HandleFunc("/api/discovery/", RequireAuth(r.config, func(w http.ResponseWriter, req *http.Request) {
path := req.URL.Path
switch req.Method {
@@ -5469,6 +5521,15 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
return nil
}
+ findHost := func(id string) *models.Host {
+ for i := range state.Hosts {
+ if state.Hosts[i].ID == id {
+ return &state.Hosts[i]
+ }
+ }
+ return nil
+ }
+
findDockerContainer := func(id string) *models.DockerContainer {
for i := range state.DockerHosts {
host := &state.DockerHosts[i]
@@ -5548,6 +5609,26 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
diskPercent = host.Disks[0].Usage
}
points["disk"] = monitoring.MetricPoint{Timestamp: now, Value: diskPercent}
+ case "host":
+ host := findHost(resourceID)
+ if host == nil {
+ return points
+ }
+ points["cpu"] = monitoring.MetricPoint{Timestamp: now, Value: host.CPUUsage}
+ points["memory"] = monitoring.MetricPoint{Timestamp: now, Value: host.Memory.Usage}
+ diskPercent := float64(0)
+ if len(host.Disks) > 0 {
+ diskPercent = host.Disks[0].Usage
+ }
+ points["disk"] = monitoring.MetricPoint{Timestamp: now, Value: diskPercent}
+ // Sum network I/O across all interfaces
+ var totalRX, totalTX uint64
+ for _, nic := range host.NetworkInterfaces {
+ totalRX += nic.RXBytes
+ totalTX += nic.TXBytes
+ }
+ points["netin"] = monitoring.MetricPoint{Timestamp: now, Value: float64(totalRX)}
+ points["netout"] = monitoring.MetricPoint{Timestamp: now, Value: float64(totalTX)}
case "docker", "dockerContainer":
container := findDockerContainer(resourceID)
if container == nil {
@@ -5595,6 +5676,17 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
return nil, "", false
}
return buildHistoryPoints(points, stepSecs), historySourceMemory, true
+ case "host":
+ metrics := monitor.GetGuestMetrics(fmt.Sprintf("host:%s", resourceID), duration)
+ points := metrics[metricType]
+ if len(points) == 0 {
+ livePoints := liveMetricPoints(resourceType, resourceID)
+ if live, ok := livePoints[metricType]; ok {
+ return buildHistoryPoints([]monitoring.MetricPoint{live}, 0), historySourceLive, true
+ }
+ return nil, "", false
+ }
+ return buildHistoryPoints(points, stepSecs), historySourceMemory, true
case "docker", "dockerContainer":
metrics := monitor.GetGuestMetrics(fmt.Sprintf("docker:%s", resourceID), duration)
points := metrics[metricType]
@@ -5647,6 +5739,8 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
metrics = monitor.GetGuestMetrics(resourceID, duration)
case "dockerHost":
metrics = monitor.GetGuestMetrics(fmt.Sprintf("dockerHost:%s", resourceID), duration)
+ case "host":
+ metrics = monitor.GetGuestMetrics(fmt.Sprintf("host:%s", resourceID), duration)
case "docker", "dockerContainer":
metrics = monitor.GetGuestMetrics(fmt.Sprintf("docker:%s", resourceID), duration)
case "storage":
diff --git a/internal/servicediscovery/service.go b/internal/servicediscovery/service.go
index 872019626d..08093a787a 100644
--- a/internal/servicediscovery/service.go
+++ b/internal/servicediscovery/service.go
@@ -1338,6 +1338,49 @@ Host: %s (%s)`, req.ResourceType, req.ResourceID, req.Hostname, req.HostID))
}
}
+ // Use different prompts for HOST vs other resource types
+ if req.ResourceType == ResourceTypeHost {
+ return fmt.Sprintf(`Analyze this HOST system and provide detailed discovery information.
+
+%s
+
+IMPORTANT: This is a HOST discovery. Focus on identifying the HOST OPERATING SYSTEM and its primary role/purpose, NOT individual services or containers running on it.
+
+Based on all available information, determine:
+1. What is the host operating system? (e.g., Unraid, Proxmox, Ubuntu Server, Debian, TrueNAS)
+2. What is the OS version?
+3. What is the primary role/purpose of this host? (e.g., NAS, hypervisor, media server, backup server)
+4. What are the key system paths?
+5. What storage is available?
+6. What services are running? (list as facts, not as the primary identification)
+
+Respond in this exact JSON format:
+{
+ "service_type": "lowercase_os_type (e.g., unraid, proxmox, ubuntu, debian, truenas)",
+ "service_name": "Human Readable OS Name and Role (e.g., Unraid NAS Server, Proxmox VE Hypervisor)",
+ "service_version": "OS version number",
+ "category": "storage|virtualizer|container|network|unknown",
+ "cli_access": "ssh user@hostname",
+ "facts": [
+ {"category": "version|config|service|port|hardware|network|storage|dependency|security", "key": "fact_name", "value": "fact_value", "source": "command_name", "confidence": 0.9}
+ ],
+ "config_paths": ["/etc/", "/boot/config/"],
+ "data_paths": ["/mnt/data", "/storage"],
+ "log_paths": ["/var/log/"],
+ "ports": [{"port": 22, "protocol": "tcp", "process": "sshd", "address": "0.0.0.0"}],
+ "confidence": 0.0-1.0,
+ "reasoning": "Explanation of host identification"
+}
+
+Important:
+- The service_type and service_name MUST reflect the HOST OS, not services running on it
+- List Docker containers, VMs, or other services as facts with category "service"
+- Include storage information (disks, pools, arrays) as facts with category "storage"
+- Include hardware info (CPU, RAM) as facts with category "hardware"
+
+Respond with ONLY valid JSON.`, strings.Join(sections, "\n\n"))
+ }
+
return fmt.Sprintf(`Analyze this infrastructure resource and provide detailed discovery information.
%s