Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

add host additional info filters #2330

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1d7c78f
add host additional info filters
billcobbler Oct 13, 2020
be28d8e
Update build documentation (#3)
noahtalerman Nov 3, 2020
72b0efc
Fix handling of --quiet flag in fleetctl query (#2)
zwass Nov 3, 2020
582d086
handle json filtering in sql
billcobbler Nov 4, 2020
eb606f1
Merge branch 'master' into add-host-additional-info-filters
billcobbler Nov 4, 2020
ac0bdf0
remove old inmemory filtering
billcobbler Nov 4, 2020
f06c3cf
Add pretty-printing option for query results (#4)
zwass Nov 4, 2020
2e333a4
Fix regression in list hosts (#6)
zwass Nov 4, 2020
d604c6a
Updated 500 page copy and added button to reveal error message. (#1)
noahtalerman Nov 4, 2020
fca44bb
Make enroll secret and node key validation case-sensitive (#5)
zwass Nov 4, 2020
7c923d9
Implement fleetctl user create (#9)
zwass Nov 5, 2020
a36bef6
Improve "Add New Host" dialog (#8)
zwass Nov 5, 2020
222cdc7
Update LICENSE (#10)
mikermcneil Nov 5, 2020
8e37b89
Implement osquery options page (#11)
noahtalerman Nov 5, 2020
660289e
Add GOPATH tips to contributor docs (#13)
mikermcneil Nov 5, 2020
43eb8bc
Update README URLs (#14)
zwass Nov 5, 2020
e452cc6
Add file carving support (#15)
zwass Nov 5, 2020
d4a39de
Branding (shallow first pass) (#12)
mikermcneil Nov 5, 2020
1fbc4b3
Remove erroneously added __debug_bin (#16)
zwass Nov 5, 2020
a1720db
Fix regression creating packs (#17)
zwass Nov 5, 2020
0ff6216
Changed the Help link and other links to fleetdm/fleet documentation
noahtalerman Nov 5, 2020
394e5a2
Update Docker image name in Makefile (#19)
zwass Nov 5, 2020
ecacbf2
Changes to additional links for transition to fleetdm (#21)
noahtalerman Nov 5, 2020
f08557d
Update Slack channel names (#22)
zwass Nov 5, 2020
f93a952
Changelog for 3.3.0 release (#18)
zwass Nov 5, 2020
ecacbbd
Update Docker image name in Makefile (#23)
zwass Nov 5, 2020
6d4fa69
Create README.md (#24)
mikermcneil Nov 5, 2020
ab738f1
continuity (#25)
mikermcneil Nov 5, 2020
fb22ec5
Add transition note to readme (#26)
zwass Nov 5, 2020
defa1e7
Merge branch 'master' of github.com:fleetdm/fleet into add-host-addit…
billcobbler Nov 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions server/datastore/inmem/hosts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package inmem

import (
"encoding/json"
"errors"
"sort"
"strings"
Expand Down Expand Up @@ -103,6 +104,33 @@ func (d *Datastore) ListHosts(opt kolide.HostListOptions) ([]*kolide.Host, error
low, high := d.getLimitOffsetSliceBounds(opt.ListOptions, len(hosts))
hosts = hosts[low:high]

// Filter additional info
if len(opt.AdditionalFilters) > 0 {
fieldsWanted := map[string]interface{}{}
for _, field := range opt.AdditionalFilters {
fieldsWanted[field] = true
}
for i, host := range hosts {
addInfo := map[string]interface{}{}
if err := json.Unmarshal(*host.Additional, &addInfo); err != nil {
return nil, err
}

for k := range addInfo {
if _, ok := fieldsWanted[k]; !ok {
delete(addInfo, k)
}
}
addInfoJSON := json.RawMessage{}
addInfoJSON, err := json.Marshal(addInfo)
if err != nil {
return nil, err
}
host.Additional = &addInfoJSON
hosts[i] = host
}
}

return hosts, nil
}

Expand Down
28 changes: 28 additions & 0 deletions server/datastore/mysql/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mysql

import (
"database/sql"
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -178,6 +179,33 @@ func (d *Datastore) ListHosts(opt kolide.HostListOptions) ([]*kolide.Host, error
return nil, errors.Wrap(err, "list hosts")
}

// Filter additional info
if len(opt.AdditionalFilters) > 0 {
fieldsWanted := map[string]interface{}{}
for _, field := range opt.AdditionalFilters {
fieldsWanted[field] = true
}
for i, host := range hosts {
addInfo := map[string]interface{}{}
if err := json.Unmarshal(*host.Additional, &addInfo); err != nil {
return nil, err
}

for k := range addInfo {
if _, ok := fieldsWanted[k]; !ok {
delete(addInfo, k)
}
}
addInfoJSON := json.RawMessage{}
addInfoJSON, err := json.Marshal(addInfo)
if err != nil {
return nil, err
}
host.Additional = &addInfoJSON
hosts[i] = host
}
}

return hosts, nil
}

Expand Down
3 changes: 2 additions & 1 deletion server/kolide/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ type HostService interface {
type HostListOptions struct {
ListOptions

StatusFilter HostStatus
AdditionalFilters []string
StatusFilter HostStatus
}

type Host struct {
Expand Down
6 changes: 6 additions & 0 deletions server/service/transport_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"context"
"net/http"
"strings"

"github.com/kolide/fleet/server/kolide"
"github.com/pkg/errors"
Expand Down Expand Up @@ -48,5 +49,10 @@ func decodeListHostsRequest(ctx context.Context, r *http.Request) (interface{},
if err != nil {
return nil, err
}

additionalInfoFiltersString := r.URL.Query().Get("additional_info_filters")
if additionalInfoFiltersString != "" {
hopt.AdditionalFilters = strings.Split(additionalInfoFiltersString, ",")
}
return listHostsRequest{ListOptions: hopt}, nil
}