- 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
162 lines
4.2 KiB
Go
162 lines
4.2 KiB
Go
package collector
|
|
|
|
import (
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
type UpdateInfo struct {
|
|
UpdateAvailable bool `json:"update_available"`
|
|
PendingCount int `json:"pending_count"`
|
|
Updates []PendingUpdateInfo `json:"updates"`
|
|
}
|
|
|
|
type PendingUpdateInfo struct {
|
|
Package string `json:"package"`
|
|
CurrentVer string `json:"current_version"`
|
|
NewVer string `json:"new_version"`
|
|
}
|
|
|
|
func CollectUpdates() *UpdateInfo {
|
|
updates := &UpdateInfo{
|
|
UpdateAvailable: false,
|
|
PendingCount: 0,
|
|
Updates: []PendingUpdateInfo{},
|
|
}
|
|
|
|
// apt list --upgradable 2>/dev/null
|
|
cmd := exec.Command("/usr/bin/apt", "list", "--upgradable")
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
// Fallback: apt-check falls verfügbar
|
|
return collectUpdatesAptCheck()
|
|
}
|
|
|
|
lines := strings.Split(string(output), "\n")
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" || strings.HasPrefix(line, "WARNING:") || strings.HasPrefix(line, "Listing...") {
|
|
continue
|
|
}
|
|
|
|
// Format: package/suite version [upgradable from: old-version]
|
|
// Beispiel: curl/focal-updates 7.68.0-1ubuntu2.7 amd64 [upgradable from: 7.68.0-1ubuntu2.6]
|
|
|
|
if !strings.Contains(line, "[upgradable from:") {
|
|
continue
|
|
}
|
|
|
|
// Package-Name extrahieren (bis zum ersten /)
|
|
parts := strings.SplitN(line, "/", 2)
|
|
if len(parts) < 2 {
|
|
continue
|
|
}
|
|
packageName := parts[0]
|
|
|
|
// Neue Version extrahieren (zwischen / und [upgradable from:)
|
|
remaining := parts[1]
|
|
beforeUpgradable := strings.Split(remaining, " [upgradable from:")
|
|
if len(beforeUpgradable) < 2 {
|
|
continue
|
|
}
|
|
|
|
// Neue Version ist im ersten Teil, aber wir müssen die Architektur entfernen
|
|
versionParts := strings.Fields(beforeUpgradable[0])
|
|
if len(versionParts) < 1 {
|
|
continue
|
|
}
|
|
newVersion := versionParts[0]
|
|
|
|
// Alte Version extrahieren (zwischen "from:" und "]")
|
|
oldVersionPart := beforeUpgradable[1]
|
|
oldVersion := strings.TrimSuffix(strings.TrimSpace(oldVersionPart), "]")
|
|
|
|
updates.Updates = append(updates.Updates, PendingUpdateInfo{
|
|
Package: packageName,
|
|
CurrentVer: oldVersion,
|
|
NewVer: newVersion,
|
|
})
|
|
}
|
|
|
|
updates.PendingCount = len(updates.Updates)
|
|
updates.UpdateAvailable = updates.PendingCount > 0
|
|
|
|
return updates
|
|
}
|
|
|
|
// Fallback-Methode mit apt-check (Ubuntu/Debian)
|
|
func collectUpdatesAptCheck() *UpdateInfo {
|
|
updates := &UpdateInfo{
|
|
UpdateAvailable: false,
|
|
PendingCount: 0,
|
|
Updates: []PendingUpdateInfo{},
|
|
}
|
|
|
|
// /usr/lib/update-notifier/apt-check
|
|
cmd := exec.Command("/usr/lib/update-notifier/apt-check")
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
// Noch ein Fallback: apt-get -s upgrade
|
|
return collectUpdatesAptGetSimulate()
|
|
}
|
|
|
|
// apt-check gibt "updates;security-updates" auf stderr aus
|
|
result := strings.TrimSpace(string(output))
|
|
parts := strings.SplitN(result, ";", 2)
|
|
|
|
if len(parts) >= 1 && parts[0] != "0" {
|
|
// Packages verfügbar, aber keine Details ohne apt list
|
|
updates.UpdateAvailable = true
|
|
updates.PendingCount = 1 // Platzhalter
|
|
updates.Updates = []PendingUpdateInfo{
|
|
{
|
|
Package: "system-updates",
|
|
CurrentVer: "various",
|
|
NewVer: "available",
|
|
},
|
|
}
|
|
}
|
|
|
|
return updates
|
|
}
|
|
|
|
// Letzter Fallback mit apt-get simulate
|
|
func collectUpdatesAptGetSimulate() *UpdateInfo {
|
|
updates := &UpdateInfo{
|
|
UpdateAvailable: false,
|
|
PendingCount: 0,
|
|
Updates: []PendingUpdateInfo{},
|
|
}
|
|
|
|
// apt-get -s upgrade (simulate)
|
|
cmd := exec.Command("/usr/bin/apt-get", "-s", "upgrade")
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return updates
|
|
}
|
|
|
|
lines := strings.Split(string(output), "\n")
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
|
|
// Suche nach "Inst package-name" Zeilen
|
|
if strings.HasPrefix(line, "Inst ") {
|
|
fields := strings.Fields(line)
|
|
if len(fields) >= 3 {
|
|
packageName := fields[1]
|
|
|
|
// Sehr simple Erkennung, bessere Parsing schwierig ohne apt list
|
|
updates.Updates = append(updates.Updates, PendingUpdateInfo{
|
|
Package: packageName,
|
|
CurrentVer: "unknown",
|
|
NewVer: "available",
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
updates.PendingCount = len(updates.Updates)
|
|
updates.UpdateAvailable = updates.PendingCount > 0
|
|
|
|
return updates
|
|
} |