package handlers import ( "gitea.d3m0k1d.ru/d3m0k1d/HellreigN/backend/internal/grpcsrv/collector" "github.com/gin-gonic/gin" "net/http" ) type AgentsGroup struct { *Handlers collector *collector.Collector } func NewAgentsGroup(h *Handlers, coll *collector.Collector) AgentsGroup { return AgentsGroup{Handlers: h, collector: coll} } type AgentInfo struct { Token string `json:"token"` Label string `json:"label"` Services []string `json:"services"` ConnectedAt string `json:"connected_at"` } // @Summary Get connected agents // @Description Returns a list of all agents currently connected via Collector (log streaming) // @Tags agents // @Security Bearer // @Produce json // @Success 200 {array} AgentInfo // @Router /agents [get] func (ag *AgentsGroup) List(c *gin.Context) { agents := make([]AgentInfo, 0) for _, agent := range ag.collector.Agents() { agents = append(agents, AgentInfo{ Token: agent.ID, Label: agent.Label, Services: agent.Services, ConnectedAt: agent.ConnectedAt.Format("2006-01-02 15:04:05"), }) } c.JSON(http.StatusOK, agents) }