rmm2/agent/collector/opnsense.go
cynfo3000 6120d0cffa Initial commit: RMM Agent + Backend
- Go Agent (FreeBSD/amd64) fuer OPNsense
- Go Backend (Linux/amd64) mit REST API + SQLite
- Collector: Hardware, CPU, Memory, Disks, Network, Services,
  WireGuard, DHCP (KEA/ISC/dnsmasq), Routes, Gateways,
  Certificates, Plugins, Updates
- Persistente Agent-ID
- TLS + API-Key Auth
- WebSocket-Infrastruktur (WIP): bidirektionaler Command-Kanal,
  TCP-Tunnel fuer Remote-Zugriff auf Firewall-WebUI
- Lastenheft und README
2026-02-28 07:38:14 +01:00

62 lines
1.2 KiB
Go

package collector
import (
"os/exec"
"strconv"
"strings"
"time"
)
func CollectOPNsenseVersion() string {
out, err := exec.Command("opnsense-version").Output()
if err != nil {
return ""
}
// Format: "OPNsense 24.1.1_1" - alles nach erstem Leerzeichen
s := strings.TrimSpace(string(out))
return s
}
func CollectFreeBSDVersion() string {
out, err := exec.Command("freebsd-version").Output()
if err != nil {
return sysctlGet("kern.osrelease")
}
return strings.TrimSpace(string(out))
}
func CollectHostname() string {
return sysctlGet("kern.hostname")
}
func CollectUptime() int64 {
// kern.boottime: { sec = 1706000000, usec = 0 } ... oder "sec = 1706000000"
out := sysctlGet("kern.boottime")
if out == "" {
return 0
}
// Parse "{ sec = TIMESTAMP, usec = ... }"
idx := strings.Index(out, "sec = ")
if idx == -1 {
return 0
}
numStr := out[idx+6:]
if commaIdx := strings.IndexAny(numStr, ", }"); commaIdx != -1 {
numStr = numStr[:commaIdx]
}
numStr = strings.TrimSpace(numStr)
bootTime, err := strconv.ParseInt(numStr, 10, 64)
if err != nil {
return 0
}
uptime := time.Now().Unix() - bootTime
if uptime < 0 {
return 0
}
return uptime
}