diff --git a/agent-linux/collector/pbs.go b/agent-linux/collector/pbs.go index 0268f36..27fd131 100644 --- a/agent-linux/collector/pbs.go +++ b/agent-linux/collector/pbs.go @@ -5,6 +5,8 @@ import ( "log" "os" "os/exec" + "strconv" + "strings" ) type PBSInfo struct { @@ -88,11 +90,16 @@ func CollectPBS() *PBSInfo { if avail, ok := d["avail"].(float64); ok { ds.Available = int64(avail) } - // Backup-Anzahl ermitteln - if snapOut, err := exec.Command("/usr/sbin/proxmox-backup-manager", "snapshot", "list", ds.Name, "--output-format", "json").Output(); err == nil { - var snaps []interface{} - if json.Unmarshal(snapOut, &snaps) == nil { - ds.BackupCount = len(snaps) + // Backup-Anzahl: Zeitstempel-Verzeichnisse zaehlen (depth 3 ohne ns, depth 5 mit ns) + // Struktur: /// oder /ns//// + if ds.Path != "" { + // Alle Timestamp-Verzeichnisse: entweder depth 3 (ohne ns) oder depth 5 (mit ns) + countCmd := exec.Command("/bin/sh", "-c", + "find "+ds.Path+" \\( -mindepth 3 -maxdepth 3 -o -mindepth 5 -maxdepth 5 \\) -type d 2>/dev/null | grep -cE '^.*[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$'") + if out, err := countCmd.Output(); err == nil { + if n, err := strconv.Atoi(strings.TrimSpace(string(out))); err == nil { + ds.BackupCount = n + } } }