fleet/server/service/logging_osquery_options.go
thehellajeff 6580fe1c5a Improvements to server logging (#2155)
- Add logging for new campaigns
- Add logging for new query creations/modification/deletion
- Add usernames for logs found in labels, options, packs, osquery options, queries and scheduled queries where something is created, modified or deleted
2019-12-04 09:42:10 -08:00

43 lines
913 B
Go

package service
import (
"context"
"time"
"github.com/kolide/fleet/server/contexts/viewer"
"github.com/kolide/fleet/server/kolide"
)
func (mw loggingMiddleware) GetOptionsSpec(ctx context.Context) (spec *kolide.OptionsSpec, err error) {
defer func(begin time.Time) {
mw.logger.Log(
"method", "GetOptionsSpec",
"err", err,
"took", time.Since(begin),
)
}(time.Now())
spec, err = mw.Service.GetOptionsSpec(ctx)
return spec, err
}
func (mw loggingMiddleware) ApplyOptionsSpec(ctx context.Context, spec *kolide.OptionsSpec) (err error) {
var (
loggedInUser = "unauthenticated"
)
if vc, ok := viewer.FromContext(ctx); ok {
loggedInUser = vc.Username()
}
defer func(begin time.Time) {
mw.logger.Log(
"method", "ApplyOptionsSpec",
"err", err,
"user", loggedInUser,
"took", time.Since(begin),
)
}(time.Now())
err = mw.Service.ApplyOptionsSpec(ctx, spec)
return err
}