Fix missing removed and shard keys in query packs (#1680)

Include the appropriate values for `removed` and `shard` when generating config
to return to osqueryd.
This commit is contained in:
Zachary Wasserman 2018-01-02 16:06:50 -08:00 committed by GitHub
parent 5e9fe9d5a1
commit 2d3e5c11cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -158,6 +158,12 @@ func (svc service) GetClientConfig(ctx context.Context) (map[string]interface{},
Interval: query.Interval,
Platform: query.Platform,
Version: query.Version,
Removed: query.Removed,
Shard: query.Shard,
}
if query.Removed != nil {
queryContent.Removed = query.Removed
}
if query.Snapshot != nil && *query.Snapshot {

View File

@ -382,14 +382,16 @@ func TestGetClientConfig(t *testing.T) {
}
ds.ListScheduledQueriesInPackFunc = func(pid uint, opt kolide.ListOptions) ([]*kolide.ScheduledQuery, error) {
tru := true
fals := false
fortytwo := uint(42)
switch pid {
case 1:
return []*kolide.ScheduledQuery{
{Name: "time", Query: "select * from time", Interval: 30},
{Name: "time", Query: "select * from time", Interval: 30, Removed: &fals},
}, nil
case 4:
return []*kolide.ScheduledQuery{
{Name: "foobar", Query: "select 3", Interval: 20},
{Name: "foobar", Query: "select 3", Interval: 20, Shard: &fortytwo},
{Name: "froobing", Query: "select 'guacamole'", Interval: 60, Snapshot: &tru},
}, nil
default:
@ -437,13 +439,13 @@ func TestGetClientConfig(t *testing.T) {
assert.JSONEq(t, `{
"pack_by_explicit_host": {
"queries": {
"foobar":{"query":"select 3","interval":20},
"foobar":{"query":"select 3","interval":20,"shard":42},
"froobing":{"query":"select 'guacamole'","interval":60,"snapshot":true}
}
},
"pack_by_label": {
"queries":{
"time":{"query":"select * from time","interval":30}
"time":{"query":"select * from time","interval":30,"removed":false}
}
}
}`,