mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
|
// package logging provides logger "plugins" for writing osquery status and
|
||
|
// result logs to various destinations.
|
||
|
package logging
|
||
|
|
||
|
import (
|
||
|
"github.com/go-kit/kit/log"
|
||
|
"github.com/go-kit/kit/log/level"
|
||
|
"github.com/kolide/fleet/server/config"
|
||
|
"github.com/kolide/fleet/server/kolide"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
type OsqueryLogger struct {
|
||
|
Status kolide.JSONLogger
|
||
|
Result kolide.JSONLogger
|
||
|
}
|
||
|
|
||
|
func New(config config.KolideConfig, logger log.Logger) (*OsqueryLogger, error) {
|
||
|
var status, result kolide.JSONLogger
|
||
|
var err error
|
||
|
|
||
|
switch config.Osquery.StatusLogPlugin {
|
||
|
case "":
|
||
|
// Allow "" to mean filesystem for backwards compatibility
|
||
|
level.Info(logger).Log("msg", "kolide_status_log_plugin not explicitly specified. Assuming 'filesystem'")
|
||
|
fallthrough
|
||
|
case "filesystem":
|
||
|
status, err = NewFilesystemLogWriter(
|
||
|
config.Filesystem.StatusLogFile,
|
||
|
logger,
|
||
|
config.Filesystem.EnableLogRotation,
|
||
|
)
|
||
|
if err != nil {
|
||
|
return nil, errors.Wrap(err, "create filesystem status logger")
|
||
|
}
|
||
|
case "firehose":
|
||
|
status, err = NewFirehoseLogWriter(
|
||
|
config.Firehose.Region,
|
||
|
config.Firehose.AccessKeyID,
|
||
|
config.Firehose.SecretAccessKey,
|
||
|
config.Firehose.StatusStream,
|
||
|
logger,
|
||
|
)
|
||
|
if err != nil {
|
||
|
return nil, errors.Wrap(err, "create firehose status logger")
|
||
|
}
|
||
|
default:
|
||
|
return nil, errors.Errorf(
|
||
|
"unknown status log plugin: %s", config.Osquery.StatusLogPlugin,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
switch config.Osquery.ResultLogPlugin {
|
||
|
case "":
|
||
|
// Allow "" to mean filesystem for backwards compatibility
|
||
|
level.Info(logger).Log("msg", "kolide_result_log_plugin not explicitly specified. Assuming 'filesystem'")
|
||
|
fallthrough
|
||
|
case "filesystem":
|
||
|
result, err = NewFilesystemLogWriter(
|
||
|
config.Filesystem.ResultLogFile,
|
||
|
logger,
|
||
|
config.Filesystem.EnableLogRotation,
|
||
|
)
|
||
|
if err != nil {
|
||
|
return nil, errors.Wrap(err, "create filesystem result logger")
|
||
|
}
|
||
|
case "firehose":
|
||
|
result, err = NewFirehoseLogWriter(
|
||
|
config.Firehose.Region,
|
||
|
config.Firehose.AccessKeyID,
|
||
|
config.Firehose.SecretAccessKey,
|
||
|
config.Firehose.ResultStream,
|
||
|
logger,
|
||
|
)
|
||
|
if err != nil {
|
||
|
return nil, errors.Wrap(err, "create firehose result logger")
|
||
|
}
|
||
|
default:
|
||
|
return nil, errors.Errorf(
|
||
|
"unknown result log plugin: %s", config.Osquery.StatusLogPlugin,
|
||
|
)
|
||
|
}
|
||
|
return &OsqueryLogger{Status: status, Result: result}, nil
|
||
|
}
|