Initial logic to support logging activity on Wings to send back to the panel

This commit is contained in:
DaneEveritt
2022-07-04 17:36:03 -04:00
parent 214baf83fb
commit 9eab08b92f
10 changed files with 256 additions and 8 deletions

View File

@@ -40,6 +40,7 @@ type Handler struct {
Connection *websocket.Conn `json:"-"`
jwt *tokens.WebsocketPayload
server *server.Server
ra server.RequestActivity
uuid uuid.UUID
}
@@ -109,6 +110,7 @@ func GetHandler(s *server.Server, w http.ResponseWriter, r *http.Request) (*Hand
Connection: conn,
jwt: nil,
server: s,
ra: s.NewRequestActivity("", r.RemoteAddr),
uuid: u,
}, nil
}
@@ -264,6 +266,7 @@ func (h *Handler) GetJwt() *tokens.WebsocketPayload {
// setJwt sets the JWT for the websocket in a race-safe manner.
func (h *Handler) setJwt(token *tokens.WebsocketPayload) {
h.Lock()
h.ra = h.ra.SetUser(token.UserUUID)
h.jwt = token
h.Unlock()
}
@@ -421,6 +424,15 @@ func (h *Handler) HandleInbound(ctx context.Context, m Message) error {
}
}
// Track this command sending event in the local database.
e := h.ra.Event(server.ActivityCommandSent, server.ActivityMeta{
"command": strings.Join(m.Args, ""),
})
if err := e.Save(); err != nil {
h.server.Log().WithField("error", err).Error("activity: failed to persist event to database")
}
return h.server.Environment.SendCommand(strings.Join(m.Args, ""))
}
}