fleet/server/service/service.go
Mike Arpaia 704ddd424b Host summary endpoint (#742)
* Initial scaffolding of the host summary endpoint

* inmem datastore implementation of GenerateHostStatusStatistics

* HostSummary docstring

* changing the url of the host summary endpoint

* datastore tests for GenerateHostStatusStatistics

* MySQL datastore implementation of GenerateHostStatusStatistics

* <= and >= to catch exact time edge case

* removing clock interface method

* lowercase error wraps

* removin superfluous whitespace

* use updated_at

* adding a seen_at column to the hosts table

* moving the update of seen_time to the caller

* using db.Get instead of db.Select
2017-01-04 14:16:17 -07:00

63 lines
1.6 KiB
Go

// Package service holds the implementation of the kolide service interface and the HTTP endpoints
// for the API
package service
import (
"io"
"github.com/WatchBeam/clock"
kitlog "github.com/go-kit/kit/log"
"github.com/kolide/kolide-ose/server/config"
"github.com/kolide/kolide-ose/server/kolide"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
// NewService creates a new service from the config struct
func NewService(ds kolide.Datastore, resultStore kolide.QueryResultStore, logger kitlog.Logger, kolideConfig config.KolideConfig, mailService kolide.MailService, c clock.Clock) (kolide.Service, error) {
var svc kolide.Service
logFile := func(path string) io.Writer {
return &lumberjack.Logger{
Filename: path,
MaxSize: 500, // megabytes
MaxBackups: 3,
MaxAge: 28, //days
}
}
svc = service{
ds: ds,
resultStore: resultStore,
logger: logger,
config: kolideConfig,
clock: c,
osqueryStatusLogWriter: logFile(kolideConfig.Osquery.StatusLogFile),
osqueryResultLogWriter: logFile(kolideConfig.Osquery.ResultLogFile),
mailService: mailService,
}
svc = validationMiddleware{svc}
return svc, nil
}
type service struct {
ds kolide.Datastore
resultStore kolide.QueryResultStore
logger kitlog.Logger
config config.KolideConfig
clock clock.Clock
osqueryStatusLogWriter io.Writer
osqueryResultLogWriter io.Writer
mailService kolide.MailService
}
func (s service) SendEmail(mail kolide.Email) error {
return s.mailService.SendEmail(mail)
}
func (s service) Clock() clock.Clock {
return s.clock
}