package collector import ( "context" "fmt" "log" "gitea.d3m0k1d.ru/d3m0k1d/HellreigN/proto/proto" "google.golang.org/grpc/metadata" ) // ReportServices handles a unary service status update from an agent. // Agents send their current services list, which is stored in the collector. func (c *Collector) ReportServices(ctx context.Context, req *proto.ServicesUpdate) (*proto.ServicesUpdateResp, error) { md, ok := metadata.FromIncomingContext(ctx) if !ok { return nil, fmt.Errorf("no metadata in context") } whoamiVals := md["whoami"] if len(whoamiVals) == 0 { return nil, fmt.Errorf("whoami metadata missing") } agentName := whoamiVals[0] services := make([]Service, 0, len(req.Services)) for _, s := range req.Services { services = append(services, Service{s.Name, s.Status}) } if ok := c.tracker.UpdateServices(agentName, services); ok { log.Printf("Updated services for agent %s: %v", agentName, services) } else { log.Printf("Warning: received services update for unknown agent %s", agentName) } return &proto.ServicesUpdateResp{}, nil }