- last_api_key Spalte in agents, wird bei Heartbeat gesetzt - GetAgentsByCustomer liefert last_api_key mit - Frontend: rot + Warnsymbol wenn Key abweicht vom Kunden-Agent-Key - Grau wenn noch kein Heartbeat mit Key-Info
68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
// Agent repraesentiert einen registrierten OPNsense-Agent
|
|
type Agent struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Hostname string `json:"hostname"`
|
|
IP string `json:"ip"`
|
|
OPNsenseVersion string `json:"opnsense_version"`
|
|
AgentVersion string `json:"agent_version,omitempty"`
|
|
Platform string `json:"platform"`
|
|
RegisteredAt time.Time `json:"registered_at"`
|
|
LastHeartbeat *time.Time `json:"last_heartbeat,omitempty"`
|
|
CustomerID *int `json:"customer_id,omitempty"`
|
|
UpdateRequested bool `json:"update_requested"`
|
|
LastAPIKey string `json:"last_api_key,omitempty"`
|
|
}
|
|
|
|
// AgentResponse erweitert Agent um den berechneten Status
|
|
type AgentResponse struct {
|
|
Agent
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// AgentEvent repraesentiert ein Event in der agent_events Tabelle
|
|
type AgentEvent struct {
|
|
ID int `json:"id"`
|
|
AgentID string `json:"agent_id"`
|
|
EventType string `json:"event_type"`
|
|
Message string `json:"message,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// CalculateAgentStatus berechnet den Status aus dem letzten Heartbeat
|
|
func CalculateAgentStatus(lastHeartbeat *time.Time) string {
|
|
if lastHeartbeat == nil {
|
|
return "unknown"
|
|
}
|
|
age := time.Since(*lastHeartbeat)
|
|
switch {
|
|
case age < 2*time.Minute:
|
|
return "online"
|
|
case age < 5*time.Minute:
|
|
return "stale"
|
|
default:
|
|
return "offline"
|
|
}
|
|
}
|
|
|
|
// RegisterRequest - Agent-Registrierung
|
|
type RegisterRequest struct {
|
|
AgentID string `json:"agent_id,omitempty"`
|
|
Name string `json:"name"`
|
|
Hostname string `json:"hostname"`
|
|
IP string `json:"ip"`
|
|
OPNsenseVersion string `json:"opnsense_version"`
|
|
AgentVersion string `json:"agent_version,omitempty"`
|
|
Platform string `json:"platform,omitempty"`
|
|
}
|
|
|
|
// RegisterResponse
|
|
type RegisterResponse struct {
|
|
ID string `json:"id"`
|
|
Message string `json:"message"`
|
|
}
|