mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 01:18:42 +00:00
Change label queries to use platform instead of build_platform (#1282)
This commit is contained in:
parent
8d4d6fa486
commit
6c7862c42e
6 changed files with 105 additions and 10 deletions
|
|
@ -96,7 +96,7 @@ const formatLabelResponse = (response) => {
|
|||
'All Hosts': 'all',
|
||||
'MS Windows': 'platform',
|
||||
'CentOS Linux': 'platform',
|
||||
'Mac OS X': 'platform',
|
||||
macOS: 'platform',
|
||||
'Ubuntu Linux': 'platform',
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ func testListHostsInLabel(t *testing.T, db kolide.Datastore) {
|
|||
func testBuiltInLabels(t *testing.T, db kolide.Datastore) {
|
||||
require.Nil(t, db.MigrateData())
|
||||
|
||||
hits, err := db.SearchLabels("Mac OS X")
|
||||
hits, err := db.SearchLabels("macOS")
|
||||
require.Nil(t, err)
|
||||
// Should get Mac OS X and All Hosts
|
||||
assert.Equal(t, 2, len(hits))
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ func (d *Datastore) createDevPacksAndQueries() error {
|
|||
}
|
||||
|
||||
func (d *Datastore) createBuiltinLabels() error {
|
||||
for _, label := range appstate.Labels() {
|
||||
for _, label := range appstate.Labels2() {
|
||||
label := label
|
||||
_, err := d.NewLabel(&label)
|
||||
if err != nil {
|
||||
|
|
@ -393,7 +393,7 @@ func (d *Datastore) createDevQueries() error {
|
|||
},
|
||||
},
|
||||
Name: "dev_query_5",
|
||||
Query: "select 1 from osquery_info where build_platform='darwin'",
|
||||
Query: "select 1 from osquery_info where platform='darwin'",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -506,7 +506,7 @@ func (d *Datastore) createDevLabels() error {
|
|||
},
|
||||
|
||||
Name: "dev_label_darwin",
|
||||
Query: "select * from osquery_info where build_platform='darwin'",
|
||||
Query: "select * from osquery_info where platform='darwin'",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import "github.com/kolide/kolide/server/kolide"
|
|||
|
||||
// Labels is the set of builtin labels that should be populated in the
|
||||
// datastore
|
||||
func Labels() []kolide.Label {
|
||||
func Labels1() []kolide.Label {
|
||||
return []kolide.Label{
|
||||
{
|
||||
Name: "All Hosts",
|
||||
|
|
@ -37,3 +37,42 @@ func Labels() []kolide.Label {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func Labels2() []kolide.Label {
|
||||
return []kolide.Label{
|
||||
{
|
||||
Name: "All Hosts",
|
||||
Query: "select 1;",
|
||||
Description: "All hosts which have enrolled in Kolide",
|
||||
LabelType: kolide.LabelTypeBuiltIn,
|
||||
},
|
||||
{
|
||||
Platform: "darwin",
|
||||
Name: "macOS",
|
||||
Query: "select 1 from os_version where platform = 'darwin';",
|
||||
Description: "All macOS hosts",
|
||||
LabelType: kolide.LabelTypeBuiltIn,
|
||||
},
|
||||
{
|
||||
Platform: "ubuntu",
|
||||
Name: "Ubuntu Linux",
|
||||
Query: "select 1 from os_version where platform = 'ubuntu';",
|
||||
Description: "All Ubuntu hosts",
|
||||
LabelType: kolide.LabelTypeBuiltIn,
|
||||
},
|
||||
{
|
||||
Platform: "centos",
|
||||
Name: "CentOS Linux",
|
||||
Query: "select 1 from os_version where platform = 'centos';",
|
||||
Description: "All CentOS hosts",
|
||||
LabelType: kolide.LabelTypeBuiltIn,
|
||||
},
|
||||
{
|
||||
Platform: "windows",
|
||||
Name: "MS Windows",
|
||||
Query: "select 1 from os_version where platform = 'windows';",
|
||||
Description: "All Windows hosts",
|
||||
LabelType: kolide.LabelTypeBuiltIn,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func Up_20161229171615(tx *sql.Tx) error {
|
|||
) VALUES (?, ?, ?, ?, ?)
|
||||
`
|
||||
|
||||
for _, label := range appstate.Labels() {
|
||||
for _, label := range appstate.Labels1() {
|
||||
_, err := tx.Exec(sql, label.Name, label.Description, label.Query, label.Platform, label.LabelType)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -34,11 +34,11 @@ func Up_20161229171615(tx *sql.Tx) error {
|
|||
func Down_20161229171615(tx *sql.Tx) error {
|
||||
sql := `
|
||||
DELETE FROM labels
|
||||
WHERE name = ? AND label_type = ?
|
||||
WHERE name = ? AND label_type = ? AND query = ?
|
||||
`
|
||||
|
||||
for _, label := range appstate.Labels() {
|
||||
_, err := tx.Exec(sql, label.Name, label.LabelType)
|
||||
for _, label := range appstate.Labels1() {
|
||||
_, err := tx.Exec(sql, label.Name, label.LabelType, label.Query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/kolide/kolide/server/datastore/internal/appstate"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MigrationClient.AddMigration(Up_20170223171234, Down_20170223171234)
|
||||
}
|
||||
|
||||
func Up_20170223171234(tx *sql.Tx) error {
|
||||
// Remove the old labels
|
||||
Down_20161229171615(tx)
|
||||
|
||||
// Insert the new labels
|
||||
sql := `
|
||||
INSERT INTO labels (
|
||||
name,
|
||||
description,
|
||||
query,
|
||||
platform,
|
||||
label_type
|
||||
) VALUES (?, ?, ?, ?, ?)
|
||||
`
|
||||
|
||||
for _, label := range appstate.Labels2() {
|
||||
_, err := tx.Exec(sql, label.Name, label.Description, label.Query, label.Platform, label.LabelType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Down_20170223171234(tx *sql.Tx) error {
|
||||
// Remove the new labels
|
||||
sql := `
|
||||
DELETE FROM labels
|
||||
WHERE name = ? AND label_type = ? AND QUERY = ?
|
||||
`
|
||||
|
||||
for _, label := range appstate.Labels2() {
|
||||
_, err := tx.Exec(sql, label.Name, label.LabelType, label.Query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the old labels
|
||||
Up_20161229171615(tx)
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in a new issue