Track power events

This commit is contained in:
DaneEveritt
2022-07-04 17:55:17 -04:00
parent 9eab08b92f
commit 0380488cd2
2 changed files with 18 additions and 7 deletions

View File

@@ -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