diff --git a/cmd/fleetctl/get.go b/cmd/fleetctl/get.go index f1dd2fd73..9818d6b13 100644 --- a/cmd/fleetctl/get.go +++ b/cmd/fleetctl/get.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "os" + "strconv" "github.com/ghodss/yaml" "github.com/kolide/fleet/server/kolide" @@ -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() diff --git a/docs/cli/file-format.md b/docs/cli/file-format.md index e4f319258..acf4f13d0 100644 --- a/docs/cli/file-format.md +++ b/docs/cli/file-format.md @@ -115,6 +115,7 @@ apiVersion: v1 kind: pack spec: name: osquery_monitoring + disabled: false targets: labels: - All Hosts diff --git a/server/datastore/datastore_packs_test.go b/server/datastore/datastore_packs_test.go index 153e83dff..4cfaec585 100644 --- a/server/datastore/datastore_packs_test.go +++ b/server/datastore/datastore_packs_test.go @@ -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) diff --git a/server/datastore/mysql/packs.go b/server/datastore/mysql/packs.go index 6254de5a2..0adfc4c7d 100644 --- a/server/datastore/mysql/packs.go +++ b/server/datastore/mysql/packs.go @@ -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") } @@ -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") } @@ -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") } diff --git a/server/kolide/packs.go b/server/kolide/packs.go index deb7ea434..87d9dbe5f 100644 --- a/server/kolide/packs.go +++ b/server/kolide/packs.go @@ -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"` }