mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
971eca9b2b
As of recently, osquery will report when a distributed query fails. We now expose errors over the results websocket. When a query errored on the host, the `error` key in the result will be non-null. Note that osquery currently doesn't provide any details so the error string will always be "failed". I anticipate that we will fix this and the string is included for future-proofing. Successful result: ``` { "type": "result", "data": { "distributed_query_execution_id": 15, "host": { ... omitted ... }, "rows": [ { "hour": "1" } ], "error": null } } ``` Failed result: ``` { "type": "result", "data": { "distributed_query_execution_id": 14, "host": { ... omitted ... }, "rows": [ ], "error": "failed" } } ```
132 lines
2.7 KiB
Go
132 lines
2.7 KiB
Go
package service
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func (mw loggingMiddleware) EnrollAgent(ctx context.Context, enrollSecret string, hostIdentifier string) (string, error) {
|
|
var (
|
|
nodeKey string
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "EnrollAgent",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
nodeKey, err = mw.Service.EnrollAgent(ctx, enrollSecret, hostIdentifier)
|
|
return nodeKey, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) AuthenticateHost(ctx context.Context, nodeKey string) (*kolide.Host, error) {
|
|
var (
|
|
host *kolide.Host
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "AuthenticateHost",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
host, err = mw.Service.AuthenticateHost(ctx, nodeKey)
|
|
return host, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) GetClientConfig(ctx context.Context) (*kolide.OsqueryConfig, error) {
|
|
var (
|
|
config *kolide.OsqueryConfig
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "GetClientConfig",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
config, err = mw.Service.GetClientConfig(ctx)
|
|
return config, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) GetDistributedQueries(ctx context.Context) (map[string]string, error) {
|
|
var (
|
|
queries map[string]string
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "GetDistributedQueries",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
queries, err = mw.Service.GetDistributedQueries(ctx)
|
|
return queries, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) SubmitDistributedQueryResults(ctx context.Context, results kolide.OsqueryDistributedQueryResults, statuses map[string]string) error {
|
|
var (
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "SubmitDistributedQueryResults",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
err = mw.Service.SubmitDistributedQueryResults(ctx, results, statuses)
|
|
return err
|
|
}
|
|
|
|
func (mw loggingMiddleware) SubmitStatusLogs(ctx context.Context, logs []kolide.OsqueryStatusLog) error {
|
|
var (
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "SubmitStatusLogs",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
err = mw.Service.SubmitStatusLogs(ctx, logs)
|
|
return err
|
|
}
|
|
|
|
func (mw loggingMiddleware) SubmitResultLogs(ctx context.Context, logs []kolide.OsqueryResultLog) error {
|
|
var (
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "SubmitResultLogs",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
err = mw.Service.SubmitResultLogs(ctx, logs)
|
|
return err
|
|
}
|