Agent-Status und Inaktivitaets-Erkennung implementiert
- Status wird aus last_heartbeat berechnet (online/stale/offline/unknown)
- GET /agents und GET /agents/{id} liefern status Feld
- agent_events Tabelle fuer Event-Tracking (Migration automatisch)
- Inaktivitaets-Monitor als Goroutine (prueft alle 60s, schreibt Events bei Statuswechsel)
- WebSocket Connect/Disconnect Events werden automatisch geschrieben
- API-Endpoints: GET /agents/events und GET /agents/{id}/events (?limit=N&type=X)
- DB-Methoden: InsertAgentEvent, GetAgentEvents, GetAllAgentEvents, GetAgentStatus
- README aktualisiert (Status-Doku, Events API, Dateistruktur)
This commit is contained in:
@@ -13,6 +13,37 @@ type Agent struct {
|
||||
LastHeartbeat *time.Time `json:"last_heartbeat,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"`
|
||||
|
||||
Reference in New Issue
Block a user