diff --git a/server/datastore/mysql/aggregated_stats_test.go b/server/datastore/mysql/aggregated_stats_test.go index 85e8dfc6c..ee81eef98 100644 --- a/server/datastore/mysql/aggregated_stats_test.go +++ b/server/datastore/mysql/aggregated_stats_test.go @@ -3,12 +3,11 @@ package mysql import ( "context" "fmt" + "math" "math/rand" "strings" - "time" - - "math" "testing" + "time" "github.com/fleetdm/fleet/v4/server/fleet" "github.com/stretchr/testify/assert" @@ -114,11 +113,11 @@ func TestAggregatedStats(t *testing.T) { ` select id, - JSON_EXTRACT(json_value, "$.user_time_p50") as user_time_p50, - JSON_EXTRACT(json_value, "$.user_time_p95") as user_time_p95, - JSON_EXTRACT(json_value, "$.system_time_p50") as system_time_p50, - JSON_EXTRACT(json_value, "$.system_time_p95") as system_time_p95, - JSON_EXTRACT(json_value, "$.total_executions") as total_executions + JSON_EXTRACT(json_value, '$.user_time_p50') as user_time_p50, + JSON_EXTRACT(json_value, '$.user_time_p95') as user_time_p95, + JSON_EXTRACT(json_value, '$.system_time_p50') as system_time_p50, + JSON_EXTRACT(json_value, '$.system_time_p95') as system_time_p95, + JSON_EXTRACT(json_value, '$.total_executions') as total_executions from aggregated_stats where type=?`, tt.aggregate)) require.True(t, len(stats) > 0) diff --git a/server/datastore/mysql/hosts.go b/server/datastore/mysql/hosts.go index b51a2690d..623bbe467 100644 --- a/server/datastore/mysql/hosts.go +++ b/server/datastore/mysql/hosts.go @@ -1047,7 +1047,7 @@ func (ds *Datastore) ListPoliciesForHost(ctx context.Context, host *fleet.Host) LEFT JOIN policy_membership pm ON (p.id=pm.policy_id AND host_id=?) LEFT JOIN users u ON p.author_id = u.id WHERE (p.team_id IS NULL OR p.team_id = (select team_id from hosts WHERE id = ?)) - AND (p.platforms IS NULL OR p.platforms = "" OR FIND_IN_SET(?, p.platforms) != 0)` + AND (p.platforms IS NULL OR p.platforms = '' OR FIND_IN_SET(?, p.platforms) != 0)` var policies []*fleet.HostPolicy if err := sqlx.SelectContext(ctx, ds.reader, &policies, query, host.ID, host.ID, host.FleetPlatform()); err != nil { diff --git a/server/datastore/mysql/migrations/tables/20171116163618_CreateTableOsqueryOptions.go b/server/datastore/mysql/migrations/tables/20171116163618_CreateTableOsqueryOptions.go index 2babcf075..1a0138e93 100644 --- a/server/datastore/mysql/migrations/tables/20171116163618_CreateTableOsqueryOptions.go +++ b/server/datastore/mysql/migrations/tables/20171116163618_CreateTableOsqueryOptions.go @@ -46,7 +46,7 @@ func Up_20171116163618(tx *sql.Tx) error { // Insert default options _, err = tx.Exec("INSERT INTO `osquery_options`" + "(override_type, override_identifier, options)" + - `VALUES (0, "", '{"options": {"logger_plugin": "tls", "pack_delimiter": "/", "logger_tls_period": 10, "distributed_plugin": "tls", "disable_distributed": false, "logger_tls_endpoint": "/api/v1/osquery/log", "distributed_interval": 10, "distributed_tls_max_attempts": 3}, "decorators": {"load": ["SELECT uuid AS host_uuid FROM system_info;", "SELECT hostname AS hostname FROM system_info;"]}}')`, + `VALUES (0, '', '{"options": {"logger_plugin": "tls", "pack_delimiter": "/", "logger_tls_period": 10, "distributed_plugin": "tls", "disable_distributed": false, "logger_tls_endpoint": "/api/v1/osquery/log", "distributed_interval": 10, "distributed_tls_max_attempts": 3}, "decorators": {"load": ["SELECT uuid AS host_uuid FROM system_info;", "SELECT hostname AS hostname FROM system_info;"]}}')`, ) if err != nil { return errors.Wrap(err, "insert options") @@ -73,7 +73,7 @@ func migrateOptions(tx *sql.Tx) error { query := ` SELECT * FROM options - WHERE value != "null" + WHERE value != 'null' ` // Intentionally initialize empty instead of nil so that we generate a // config with empty options rather than a null value. diff --git a/server/datastore/mysql/migrations/tables/20211116184030_PolicyWithProprietaryQuery.go b/server/datastore/mysql/migrations/tables/20211116184030_PolicyWithProprietaryQuery.go index 883bab94c..fdbee72f8 100644 --- a/server/datastore/mysql/migrations/tables/20211116184030_PolicyWithProprietaryQuery.go +++ b/server/datastore/mysql/migrations/tables/20211116184030_PolicyWithProprietaryQuery.go @@ -59,7 +59,7 @@ func Up_20211116184030(tx *sql.Tx) error { } query, args, err := sqlx.In(` UPDATE policies - SET name = CONCAT(name, " (", CONVERT(id, CHAR) ,")") + SET name = CONCAT(name, ' (', CONVERT(id, CHAR) ,')') WHERE query_id IN (?)`, queryIDs, ) diff --git a/server/datastore/mysql/queries.go b/server/datastore/mysql/queries.go index fc6d3878f..0afa8c0f2 100644 --- a/server/datastore/mysql/queries.go +++ b/server/datastore/mysql/queries.go @@ -179,14 +179,14 @@ func (ds *Datastore) ListQueries(ctx context.Context, opt fleet.ListQueryOptions q.*, COALESCE(u.name, '') AS author_name, COALESCE(u.email, '') AS author_email, - JSON_EXTRACT(json_value, "$.user_time_p50") as user_time_p50, - JSON_EXTRACT(json_value, "$.user_time_p95") as user_time_p95, - JSON_EXTRACT(json_value, "$.system_time_p50") as system_time_p50, - JSON_EXTRACT(json_value, "$.system_time_p95") as system_time_p95, - JSON_EXTRACT(json_value, "$.total_executions") as total_executions + JSON_EXTRACT(json_value, '$.user_time_p50') as user_time_p50, + JSON_EXTRACT(json_value, '$.user_time_p95') as user_time_p95, + JSON_EXTRACT(json_value, '$.system_time_p50') as system_time_p50, + JSON_EXTRACT(json_value, '$.system_time_p95') as system_time_p95, + JSON_EXTRACT(json_value, '$.total_executions') as total_executions FROM queries q LEFT JOIN users u ON (q.author_id = u.id) - LEFT JOIN aggregated_stats ag ON (ag.id=q.id AND ag.type="query") + LEFT JOIN aggregated_stats ag ON (ag.id=q.id AND ag.type='query') WHERE saved = true ` if opt.OnlyObserverCanRun { diff --git a/server/datastore/mysql/scheduled_queries.go b/server/datastore/mysql/scheduled_queries.go index c0e37fc97..1681a6e74 100644 --- a/server/datastore/mysql/scheduled_queries.go +++ b/server/datastore/mysql/scheduled_queries.go @@ -28,14 +28,14 @@ func (ds *Datastore) ListScheduledQueriesInPackWithStats(ctx context.Context, id sq.denylist, q.query, q.id AS query_id, - JSON_EXTRACT(ag.json_value, "$.user_time_p50") as user_time_p50, - JSON_EXTRACT(ag.json_value, "$.user_time_p95") as user_time_p95, - JSON_EXTRACT(ag.json_value, "$.system_time_p50") as system_time_p50, - JSON_EXTRACT(ag.json_value, "$.system_time_p95") as system_time_p95, - JSON_EXTRACT(ag.json_value, "$.total_executions") as total_executions + JSON_EXTRACT(ag.json_value, '$.user_time_p50') as user_time_p50, + JSON_EXTRACT(ag.json_value, '$.user_time_p95') as user_time_p95, + JSON_EXTRACT(ag.json_value, '$.system_time_p50') as system_time_p50, + JSON_EXTRACT(ag.json_value, '$.system_time_p95') as system_time_p95, + JSON_EXTRACT(ag.json_value, '$.total_executions') as total_executions FROM scheduled_queries sq JOIN queries q ON (sq.query_name = q.name) - LEFT JOIN aggregated_stats ag ON (ag.id=sq.id AND ag.type="scheduled_query") + LEFT JOIN aggregated_stats ag ON (ag.id=sq.id AND ag.type='scheduled_query') WHERE sq.pack_id = ? ` query = appendListOptionsToSQL(query, opts)