- agent-linux/: Kompletter Linux/Proxmox RMM Agent - Collectors: CPU, Memory, Disk, Network, Services, Updates, Proxmox (VMs, Container, Storage, ZFS), Backups - Backup Collector: Jobs nach Node gefiltert (Cluster-aware) - WebSocket: Tunnel-Support, writeMux fuer stabile Verbindungen - Systemd Service Template - updater/: Plattform-unabhaengiger Updater (FreeBSD + Linux) - runtime.GOOS erkennt Plattform automatisch - FreeBSD: /usr/local/rmm/, service rmm_agent - Linux: /usr/local/bin/, /etc/rmm/, systemctl rmm-agent - Firmware-Download mit ?platform= Parameter - frontend/: Proxmox-Bereich - ProxmoxServers.jsx: Eigene Seite fuer PVE Server mit VM/CT Counts - ProxmoxPanel.jsx: Detail-Panel mit Uebersicht, VMs, Container, Storage, ZFS, Tunnel, Dienste, Updates, Backups - Agents.jsx: Filtert Linux-Agents raus (nur OPNsense) - Sidebar: Proxmox Navigationspunkt - Installationsanleitung mit rmm-agent-linux + rmm-updater-linux - backend: Platform-Feld fuer Agents, Firmware multi-platform
94 lines
2.0 KiB
Go
94 lines
2.0 KiB
Go
package collector
|
|
|
|
import (
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
type ServiceInfo struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func CollectServices() []ServiceInfo {
|
|
var services []ServiceInfo
|
|
|
|
// systemctl list-units --type=service --all --no-pager --no-legend
|
|
output, err := exec.Command("/usr/bin/systemctl", "list-units", "--type=service", "--all", "--no-pager", "--no-legend").CombinedOutput()
|
|
if err != nil {
|
|
return services
|
|
}
|
|
|
|
lines := strings.Split(string(output), "\n")
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
continue
|
|
}
|
|
|
|
// Format: UNIT LOAD ACTIVE SUB DESCRIPTION
|
|
fields := strings.Fields(line)
|
|
if len(fields) < 4 {
|
|
continue
|
|
}
|
|
|
|
serviceName := fields[0]
|
|
load := fields[1]
|
|
active := fields[2]
|
|
sub := fields[3]
|
|
|
|
// Beschreibung ist der Rest ab Feld 4
|
|
description := ""
|
|
if len(fields) > 4 {
|
|
description = strings.Join(fields[4:], " ")
|
|
}
|
|
|
|
// Status bestimmen
|
|
status := determineServiceStatus(load, active, sub)
|
|
|
|
// .service suffix entfernen für bessere Lesbarkeit
|
|
displayName := strings.TrimSuffix(serviceName, ".service")
|
|
|
|
services = append(services, ServiceInfo{
|
|
Name: displayName,
|
|
Description: description,
|
|
Status: status,
|
|
})
|
|
}
|
|
|
|
return services
|
|
}
|
|
|
|
// Bestimmt den Service-Status basierend auf systemctl Ausgabe
|
|
func determineServiceStatus(load, active, sub string) string {
|
|
// Priorität auf active state
|
|
switch active {
|
|
case "active":
|
|
// Wenn active, schaue auf sub-state
|
|
switch sub {
|
|
case "running":
|
|
return "running"
|
|
case "exited":
|
|
return "stopped" // one-shot service, beendet
|
|
default:
|
|
return "active"
|
|
}
|
|
case "inactive":
|
|
return "stopped"
|
|
case "failed":
|
|
return "error"
|
|
case "activating":
|
|
return "starting"
|
|
case "deactivating":
|
|
return "stopping"
|
|
default:
|
|
// Falls load state problematisch ist
|
|
if load == "not-found" {
|
|
return "not-found"
|
|
} else if load == "error" {
|
|
return "error"
|
|
}
|
|
return "unknown"
|
|
}
|
|
} |