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

fleetctl: allow disabling packs via apply #2325

Merged
merged 2 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion cmd/fleetctl/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/ghodss/yaml"
"github.com/kolide/fleet/server/kolide"
Expand Down Expand Up @@ -374,11 +375,12 @@ func getPacksCommand() cli.Command {
pack.Name,
pack.Platform,
pack.Description,
strconv.FormatBool(pack.Disabled),
})
}

table := defaultTable()
table.SetHeader([]string{"name", "platform", "description"})
table.SetHeader([]string{"name", "platform", "description", "disabled"})
table.AppendBulk(data)
table.Render()

Expand Down
1 change: 1 addition & 0 deletions docs/cli/file-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ apiVersion: v1
kind: pack
spec:
name: osquery_monitoring
disabled: false
targets:
labels:
- All Hosts
Expand Down
35 changes: 35 additions & 0 deletions server/datastore/datastore_packs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,41 @@ func setupPackSpecsTest(t *testing.T, ds kolide.Datastore) []*kolide.PackSpec {
},
},
},
&kolide.PackSpec{
ID: 2,
Name: "test_pack_disabled",
Disabled: true,
Targets: kolide.PackSpecTargets{
Labels: []string{
"foo",
"bar",
"bing",
},
},
Queries: []kolide.PackSpecQuery{
kolide.PackSpecQuery{
QueryName: queries[0].Name,
Name: "q0",
Description: "test_foo",
Interval: 42,
},
kolide.PackSpecQuery{
QueryName: queries[0].Name,
Name: "foo_snapshot",
Interval: 600,
Snapshot: boolPtr(true),
},
kolide.PackSpecQuery{
Name: "q2",
QueryName: queries[1].Name,
Interval: 600,
Removed: boolPtr(false),
Shard: uintPtr(73),
Platform: stringPtr("foobar"),
Version: stringPtr("0.0.0.0.0.1"),
},
},
},
}

err = ds.ApplyPackSpecs(expectedSpecs)
Expand Down
11 changes: 6 additions & 5 deletions server/datastore/mysql/packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ func applyPackSpec(tx *sqlx.Tx, spec *kolide.PackSpec) error {
}
// Insert/update pack
query := `
INSERT INTO packs (name, description, platform)
VALUES (?, ?, ?)
INSERT INTO packs (name, description, platform, disabled)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
name = VALUES(name),
description = VALUES(description),
platform = VALUES(platform),
disabled = VALUES(disabled),
deleted = false
`
if _, err := tx.Exec(query, spec.Name, spec.Description, spec.Platform); err != nil {
if _, err := tx.Exec(query, spec.Name, spec.Description, spec.Platform, spec.Disabled); err != nil {
return errors.Wrap(err, "insert/update pack")
}

Expand Down Expand Up @@ -107,7 +108,7 @@ func applyPackSpec(tx *sqlx.Tx, spec *kolide.PackSpec) error {
func (d *Datastore) GetPackSpecs() (specs []*kolide.PackSpec, err error) {
err = d.withRetryTxx(func(tx *sqlx.Tx) error {
// Get basic specs
query := "SELECT id, name, description, platform FROM packs"
query := "SELECT id, name, description, platform, disabled FROM packs"
if err := tx.Select(&specs, query); err != nil {
return errors.Wrap(err, "get packs")
}
Expand Down Expand Up @@ -152,7 +153,7 @@ func (d *Datastore) GetPackSpec(name string) (spec *kolide.PackSpec, err error)
err = d.withRetryTxx(func(tx *sqlx.Tx) error {
// Get basic spec
var specs []*kolide.PackSpec
query := "SELECT id, name, description, platform FROM packs WHERE name = ?"
query := "SELECT id, name, description, platform, disabled FROM packs WHERE name = ?"
if err := tx.Select(&specs, query, name); err != nil {
return errors.Wrap(err, "get packs")
}
Expand Down
1 change: 1 addition & 0 deletions server/kolide/packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type PackSpec struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Platform string `json:"platform,omitempty"`
Disabled bool `json:"disabled"`
Targets PackSpecTargets `json:"targets,omitempty"`
Queries []PackSpecQuery `json:"queries,omitempty"`
}
Expand Down