Track power events
This commit is contained in:
parent
9eab08b92f
commit
0380488cd2
|
@ -368,6 +368,10 @@ func (h *Handler) HandleInbound(ctx context.Context, m Message) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
_ = h.ra.Save(h.server, server.ActivityPower, server.ActivityMeta{
|
||||
"signal": string(action),
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
case SendServerLogsEvent:
|
||||
|
@ -424,15 +428,10 @@ 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{
|
||||
_ = h.ra.Save(h.server, server.ActivityConsoleCommand, 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, ""))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ type Event string
|
|||
type ActivityMeta map[string]interface{}
|
||||
|
||||
const (
|
||||
ActivityCommandSent = Event("command.sent")
|
||||
ActivityPower = Event("power")
|
||||
ActivityConsoleCommand = Event("console_command")
|
||||
)
|
||||
|
||||
type Activity struct {
|
||||
|
@ -56,6 +57,17 @@ func (ra RequestActivity) Event(event Event, metadata ActivityMeta) Activity {
|
|||
}
|
||||
}
|
||||
|
||||
// Save creates a new event instance and saves it. If an error is encountered it is automatically
|
||||
// logged to the provided server's error logging output. The error is also returned to the caller
|
||||
// but can be ignored.
|
||||
func (ra RequestActivity) Save(s *Server, event Event, metadata ActivityMeta) error {
|
||||
if err := ra.Event(event, metadata).Save(); err != nil {
|
||||
s.Log().WithField("error", err).WithField("event", event).Error("activity: failed to save event")
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IP returns the IP address associated with this entry.
|
||||
func (ra RequestActivity) IP() string {
|
||||
return ra.ip
|
||||
|
|
Loading…
Reference in New Issue
Block a user