diff --git a/server/datastore/mysql/migrations/tables/20231016091915_FixQueriesWithEmptyLoggingType.go b/server/datastore/mysql/migrations/tables/20231016091915_FixQueriesWithEmptyLoggingType.go new file mode 100644 index 000000000..1c831a025 --- /dev/null +++ b/server/datastore/mysql/migrations/tables/20231016091915_FixQueriesWithEmptyLoggingType.go @@ -0,0 +1,27 @@ +package tables + +import ( + "database/sql" + "fmt" + + "github.com/fleetdm/fleet/v4/server/fleet" +) + +func init() { + MigrationClient.AddMigration(Up_20231016091915, Down_20231016091915) +} + +func Up_20231016091915(tx *sql.Tx) error { + _, err := tx.Exec(` + UPDATE queries SET logging_type = ? WHERE logging_type = ''; + `, fleet.LoggingSnapshot) + if err != nil { + return fmt.Errorf("failed to update queries logging_type: %w", err) + } + + return nil +} + +func Down_20231016091915(tx *sql.Tx) error { + return nil +} diff --git a/server/datastore/mysql/migrations/tables/20231016091915_FixQueriesWithEmptyLoggingType_test.go b/server/datastore/mysql/migrations/tables/20231016091915_FixQueriesWithEmptyLoggingType_test.go new file mode 100644 index 000000000..ce64a26b0 --- /dev/null +++ b/server/datastore/mysql/migrations/tables/20231016091915_FixQueriesWithEmptyLoggingType_test.go @@ -0,0 +1,39 @@ +package tables + +import ( + "testing" + + "github.com/fleetdm/fleet/v4/server/fleet" + "github.com/stretchr/testify/require" +) + +func TestUp_20231016091915(t *testing.T) { + db := applyUpToPrev(t) + + insertStmt := `INSERT INTO queries ( + name, description, query, logging_type + ) VALUES (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?)` + + _, err := db.Exec(insertStmt, + "foobar", "logging_type set to something else", "SELECT 1;", fleet.LoggingDifferential, + "zoobar", "logging_type unset", "SELECT 2;", "", + "boobar", "logging_type set to snapshot already", "SELECT 3;", fleet.LoggingSnapshot, + ) + require.NoError(t, err) + + // Apply current migration. + applyNext(t, db) + + var foobarLogging string + err = db.Get(&foobarLogging, "SELECT logging_type FROM queries WHERE name = ?", "foobar") + require.NoError(t, err) + require.Equal(t, fleet.LoggingDifferential, foobarLogging) + var zoobarLogging string + err = db.Get(&zoobarLogging, "SELECT logging_type FROM queries WHERE name = ?", "zoobar") + require.NoError(t, err) + require.Equal(t, fleet.LoggingSnapshot, zoobarLogging) + var boobarLogging string + err = db.Get(&boobarLogging, "SELECT logging_type FROM queries WHERE name = ?", "boobar") + require.NoError(t, err) + require.Equal(t, fleet.LoggingSnapshot, boobarLogging) +} diff --git a/server/datastore/mysql/packs_test.go b/server/datastore/mysql/packs_test.go index 21eff1c89..750beaf96 100644 --- a/server/datastore/mysql/packs_test.go +++ b/server/datastore/mysql/packs_test.go @@ -141,12 +141,12 @@ func testPacksList(t *testing.T, ds *Datastore) { func setupPackSpecsTest(t *testing.T, ds fleet.Datastore) []*fleet.PackSpec { zwass := test.NewUser(t, ds, "Zach", "zwass@example.com", true) queries := []*fleet.Query{ - {Name: "foo", Description: "get the foos", Query: "select * from foo"}, - {Name: "bar", Description: "do some bars", Query: "select baz from bar"}, + {Name: "foo", Description: "get the foos", Query: "select * from foo", Logging: fleet.LoggingSnapshot}, + {Name: "bar", Description: "do some bars", Query: "select baz from bar", Logging: fleet.LoggingSnapshot}, } // Zach creates some queries err := ds.ApplyQueries(context.Background(), zwass.ID, queries, nil) - require.Nil(t, err) + require.NoError(t, err) labels := []*fleet.LabelSpec{ { diff --git a/server/datastore/mysql/policies_test.go b/server/datastore/mysql/policies_test.go index b15237294..215acb56c 100644 --- a/server/datastore/mysql/policies_test.go +++ b/server/datastore/mysql/policies_test.go @@ -69,6 +69,7 @@ func testPoliciesNewGlobalPolicyLegacy(t *testing.T, ds *Datastore) { Description: "query1 desc", Query: "select 1;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) p, err := ds.NewGlobalPolicy(context.Background(), &user1.ID, fleet.PolicyPayload{ @@ -87,6 +88,7 @@ func testPoliciesNewGlobalPolicyLegacy(t *testing.T, ds *Datastore) { Description: "query2 desc", Query: "select 42;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) _, err = ds.NewGlobalPolicy(context.Background(), &user1.ID, fleet.PolicyPayload{ @@ -233,6 +235,7 @@ func testPoliciesMembershipView(deferred bool, t *testing.T, ds *Datastore) { Description: "query1 desc", Query: "select 1;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) p, err := ds.NewGlobalPolicy(ctx, &user1.ID, fleet.PolicyPayload{ @@ -251,6 +254,7 @@ func testPoliciesMembershipView(deferred bool, t *testing.T, ds *Datastore) { Description: "query2 desc", Query: "select 42;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) p2, err := ds.NewGlobalPolicy(ctx, &user1.ID, fleet.PolicyPayload{ @@ -390,6 +394,7 @@ func testTeamPolicyLegacy(t *testing.T, ds *Datastore) { Description: "query1 desc", Query: "select 1;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -401,6 +406,7 @@ func testTeamPolicyLegacy(t *testing.T, ds *Datastore) { Description: "query2 desc", Query: "select 1;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -918,6 +924,7 @@ func testPolicyQueriesForHost(t *testing.T, ds *Datastore) { Description: "query1 desc", Query: "select 1;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) gp, err := ds.NewGlobalPolicy(context.Background(), &user1.ID, fleet.PolicyPayload{ @@ -931,6 +938,7 @@ func testPolicyQueriesForHost(t *testing.T, ds *Datastore) { Description: "query2 desc", Query: "select 42;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) tp, err := ds.NewTeamPolicy(context.Background(), team1.ID, &user1.ID, fleet.PolicyPayload{ @@ -1066,6 +1074,7 @@ func testTeamPolicyTransfer(t *testing.T, ds *Datastore) { Description: "query1 desc", Query: "select 1;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) team1Policy, err := ds.NewTeamPolicy(ctx, team1.ID, &user1.ID, fleet.PolicyPayload{ @@ -1078,6 +1087,7 @@ func testTeamPolicyTransfer(t *testing.T, ds *Datastore) { Description: "query2 desc", Query: "select 2;", Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) globalPolicy, err := ds.NewGlobalPolicy(ctx, &user1.ID, fleet.PolicyPayload{ diff --git a/server/datastore/mysql/queries.go b/server/datastore/mysql/queries.go index 2d5df3d51..be9f26fdc 100644 --- a/server/datastore/mysql/queries.go +++ b/server/datastore/mysql/queries.go @@ -175,6 +175,9 @@ func (ds *Datastore) NewQuery( query *fleet.Query, opts ...fleet.OptionalArg, ) (*fleet.Query, error) { + if err := query.Verify(); err != nil { + return nil, ctxerr.Wrap(ctx, err) + } sqlStatement := ` INSERT INTO queries ( name, @@ -226,6 +229,10 @@ func (ds *Datastore) NewQuery( // SaveQuery saves changes to a Query. func (ds *Datastore) SaveQuery(ctx context.Context, q *fleet.Query, shouldDiscardResults bool) (err error) { + if err := q.Verify(); err != nil { + return ctxerr.Wrap(ctx, err) + } + tx, err := ds.writer(ctx).BeginTxx(ctx, nil) if err != nil { return ctxerr.Wrap(ctx, err, "begin SaveQuery transaction") @@ -549,7 +556,15 @@ func (ds *Datastore) ListScheduledQueriesForAgents(ctx context.Context, teamID * q.discard_data FROM queries q WHERE q.saved = true - AND (q.schedule_interval > 0 AND %s AND (q.automations_enabled OR (NOT q.discard_data AND NOT ?))) + AND ( + q.schedule_interval > 0 AND + %s AND + ( + q.automations_enabled + OR + (NOT q.discard_data AND NOT ? AND q.logging_type = ?) + ) + ) ` args := []interface{}{} @@ -559,7 +574,7 @@ func (ds *Datastore) ListScheduledQueriesForAgents(ctx context.Context, teamID * teamSQL = " team_id = ?" } sqlStmt = fmt.Sprintf(sqlStmt, teamSQL) - args = append(args, queryReportsDisabled) + args = append(args, queryReportsDisabled, fleet.LoggingSnapshot) results := []*fleet.Query{} if err := sqlx.SelectContext(ctx, ds.reader(ctx), &results, sqlStmt, args...); err != nil { diff --git a/server/datastore/mysql/queries_test.go b/server/datastore/mysql/queries_test.go index 78a0e4eba..310b1205f 100644 --- a/server/datastore/mysql/queries_test.go +++ b/server/datastore/mysql/queries_test.go @@ -58,13 +58,14 @@ func testQueriesApply(t *testing.T, ds *Datastore) { Platform: "darwin", MinOsqueryVersion: "5.2.1", AutomationsEnabled: true, - Logging: "differential", + Logging: fleet.LoggingDifferential, DiscardData: true, }, { Name: "bar", Description: "do some bars", Query: "select baz from bar", + Logging: fleet.LoggingSnapshot, DiscardData: true, }, } @@ -114,6 +115,7 @@ func testQueriesApply(t *testing.T, ds *Datastore) { Description: "Look out!", Query: "select * from time", DiscardData: true, + Logging: fleet.LoggingDifferential, }, ) err = ds.ApplyQueries(context.Background(), zwass.ID, []*fleet.Query{expectedQueries[2]}, nil) @@ -150,7 +152,7 @@ func testQueriesApply(t *testing.T, ds *Datastore) { Platform: "not valid", MinOsqueryVersion: "5.2.1", AutomationsEnabled: true, - Logging: "differential", + Logging: fleet.LoggingDifferential, }, } err = ds.ApplyQueries(context.Background(), zwass.ID, invalidQueries, nil) @@ -164,6 +166,7 @@ func testQueriesDelete(t *testing.T, ds *Datastore) { Name: "foo", Query: "bar", AuthorID: &user.ID, + Logging: fleet.LoggingDifferential, } query, err := ds.NewQuery(context.Background(), query) require.NoError(t, err) @@ -259,6 +262,7 @@ func testQueriesSave(t *testing.T, ds *Datastore) { Name: "foo", Query: "bar", AuthorID: &user.ID, + Logging: fleet.LoggingSnapshot, } query, err := ds.NewQuery(context.Background(), query) require.NoError(t, err) @@ -275,10 +279,10 @@ func testQueriesSave(t *testing.T, ds *Datastore) { query.ObserverCanRun = true query.TeamID = &team.ID query.Interval = 10 - query.Platform = "macos" + query.Platform = "darwin" query.MinOsqueryVersion = "5.2.1" query.AutomationsEnabled = true - query.Logging = "differential" + query.Logging = fleet.LoggingDifferential query.DiscardData = true err = ds.SaveQuery(context.Background(), query, true) @@ -305,6 +309,7 @@ func testQueriesList(t *testing.T, ds *Datastore) { Saved: true, AuthorID: &user.ID, DiscardData: true, + Logging: fleet.LoggingSnapshot, }) require.Nil(t, err) } @@ -315,6 +320,7 @@ func testQueriesList(t *testing.T, ds *Datastore) { Query: "select * from time", Saved: false, AuthorID: &user.ID, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -354,8 +360,8 @@ func testQueriesList(t *testing.T, ds *Datastore) { func testQueriesLoadPacksForQueries(t *testing.T, ds *Datastore) { zwass := test.NewUser(t, ds, "Zach", "zwass@fleet.co", true) queries := []*fleet.Query{ - {Name: "q1", Query: "select * from time"}, - {Name: "q2", Query: "select * from osquery_info"}, + {Name: "q1", Query: "select * from time", Logging: fleet.LoggingSnapshot}, + {Name: "q2", Query: "select * from osquery_info", Logging: fleet.LoggingDifferential}, } err := ds.ApplyQueries(context.Background(), zwass.ID, queries, nil) require.NoError(t, err) @@ -483,12 +489,14 @@ func testQueriesDuplicateNew(t *testing.T, ds *Datastore) { Name: "foo", Query: "select * from time;", AuthorID: &user.ID, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) require.NotZero(t, globalQ1.ID) _, err = ds.NewQuery(context.Background(), &fleet.Query{ - Name: "foo", - Query: "select * from osquery_info;", + Name: "foo", + Query: "select * from osquery_info;", + Logging: fleet.LoggingSnapshot, }) require.Contains(t, err.Error(), "already exists") @@ -500,31 +508,35 @@ func testQueriesDuplicateNew(t *testing.T, ds *Datastore) { require.NoError(t, err) _, err = ds.NewQuery(context.Background(), &fleet.Query{ - Name: "foo", - Query: "select * from osquery_info;", - TeamID: &team.ID, + Name: "foo", + Query: "select * from osquery_info;", + TeamID: &team.ID, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) _, err = ds.NewQuery(context.Background(), &fleet.Query{ - Name: "foo", - Query: "select * from osquery_info;", - TeamID: &team.ID, + Name: "foo", + Query: "select * from osquery_info;", + TeamID: &team.ID, + Logging: fleet.LoggingSnapshot, }) require.Contains(t, err.Error(), "already exists") } func testQueriesListFiltersObservers(t *testing.T, ds *Datastore) { _, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: "query1", - Query: "select 1;", - Saved: true, + Name: "query1", + Query: "select 1;", + Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) _, err = ds.NewQuery(context.Background(), &fleet.Query{ - Name: "query2", - Query: "select 1;", - Saved: true, + Name: "query2", + Query: "select 1;", + Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) query3, err := ds.NewQuery(context.Background(), &fleet.Query{ @@ -532,6 +544,7 @@ func testQueriesListFiltersObservers(t *testing.T, ds *Datastore) { Query: "select 1;", Saved: true, ObserverCanRun: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -553,6 +566,7 @@ func testObserverCanRunQuery(t *testing.T, ds *Datastore) { Name: "canRunTrue", Query: "select 1;", ObserverCanRun: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -560,12 +574,14 @@ func testObserverCanRunQuery(t *testing.T, ds *Datastore) { Name: "canRunFalse", Query: "select 1;", ObserverCanRun: false, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) _, err = ds.NewQuery(context.Background(), &fleet.Query{ - Name: "canRunOmitted", - Query: "select 1;", + Name: "canRunOmitted", + Query: "select 1;", + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -581,21 +597,24 @@ func testObserverCanRunQuery(t *testing.T, ds *Datastore) { func testListQueriesFiltersByTeamID(t *testing.T, ds *Datastore) { globalQ1, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: "query1", - Query: "select 1;", - Saved: true, + Name: "query1", + Query: "select 1;", + Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) globalQ2, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: "query2", - Query: "select 1;", - Saved: true, + Name: "query2", + Query: "select 1;", + Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) globalQ3, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: "query3", - Query: "select 1;", - Saved: true, + Name: "query3", + Query: "select 1;", + Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -610,24 +629,27 @@ func testListQueriesFiltersByTeamID(t *testing.T, ds *Datastore) { require.NoError(t, err) teamQ1, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: "query1", - Query: "select 1;", - Saved: true, - TeamID: &team.ID, + Name: "query1", + Query: "select 1;", + Saved: true, + TeamID: &team.ID, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) teamQ2, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: "query2", - Query: "select 1;", - Saved: true, - TeamID: &team.ID, + Name: "query2", + Query: "select 1;", + Saved: true, + TeamID: &team.ID, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) teamQ3, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: "query3", - Query: "select 1;", - Saved: true, - TeamID: &team.ID, + Name: "query3", + Query: "select 1;", + Saved: true, + TeamID: &team.ID, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -647,6 +669,7 @@ func testListQueriesFiltersByIsScheduled(t *testing.T, ds *Datastore) { Query: "select 1;", Saved: true, Interval: 0, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) q2, err := ds.NewQuery(context.Background(), &fleet.Query{ @@ -655,6 +678,7 @@ func testListQueriesFiltersByIsScheduled(t *testing.T, ds *Datastore) { Saved: true, Interval: 10, AutomationsEnabled: false, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) q3, err := ds.NewQuery(context.Background(), &fleet.Query{ @@ -663,6 +687,7 @@ func testListQueriesFiltersByIsScheduled(t *testing.T, ds *Datastore) { Saved: true, Interval: 20, AutomationsEnabled: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -718,10 +743,11 @@ func testListScheduledQueriesForAgents(t *testing.T, ds *Datastore) { AutomationsEnabled: false, TeamID: teamID, DiscardData: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) - // Interval=0, AutomationsEnabled=0, DiscardData=0 + // Interval=0, AutomationsEnabled=0, DiscardData=0, Snapshot=0 _, err := ds.NewQuery(context.Background(), &fleet.Query{ Name: fmt.Sprintf("%s query2", teamIDStr), Query: "select 1;", @@ -730,90 +756,202 @@ func testListScheduledQueriesForAgents(t *testing.T, ds *Datastore) { TeamID: teamID, AutomationsEnabled: false, DiscardData: false, + Logging: fleet.LoggingDifferential, }) require.NoError(t, err) - // Interval=0, AutomationsEnabled=0, DiscardData=1 + // Interval=0, AutomationsEnabled=0, DiscardData=0, Snapshot=1 _, err = ds.NewQuery(context.Background(), &fleet.Query{ Name: fmt.Sprintf("%s query3", teamIDStr), Query: "select 1;", Saved: true, Interval: 0, - AutomationsEnabled: false, TeamID: teamID, - DiscardData: true, + AutomationsEnabled: false, + DiscardData: false, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) - // Interval=0, AutomationsEnabled=1, DiscardData=0 + // Interval=0, AutomationsEnabled=0, DiscardData=1, Snapshot=0 _, err = ds.NewQuery(context.Background(), &fleet.Query{ Name: fmt.Sprintf("%s query4", teamIDStr), Query: "select 1;", Saved: true, Interval: 0, - AutomationsEnabled: true, + AutomationsEnabled: false, TeamID: teamID, - DiscardData: false, + DiscardData: true, + Logging: fleet.LoggingDifferential, }) require.NoError(t, err) - // Interval=0, AutomationsEnabled=1, DiscardData=1 + // Interval=0, AutomationsEnabled=0, DiscardData=1, Snapshot=1 _, err = ds.NewQuery(context.Background(), &fleet.Query{ Name: fmt.Sprintf("%s query5", teamIDStr), Query: "select 1;", Saved: true, Interval: 0, + AutomationsEnabled: false, + TeamID: teamID, + DiscardData: true, + Logging: fleet.LoggingSnapshot, + }) + require.NoError(t, err) + + // Interval=0, AutomationsEnabled=1, DiscardData=0, Snapshot=0 + _, err = ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query6", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 0, + AutomationsEnabled: true, + TeamID: teamID, + DiscardData: false, + Logging: fleet.LoggingDifferential, + }) + require.NoError(t, err) + + // Interval=0, AutomationsEnabled=1, DiscardData=0, Snapshot=1 + _, err = ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query7", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 0, + AutomationsEnabled: true, + TeamID: teamID, + DiscardData: false, + Logging: fleet.LoggingSnapshot, + }) + require.NoError(t, err) + + // Interval=0, AutomationsEnabled=1, DiscardData=1, Snapshot=0 + _, err = ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query8", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 0, AutomationsEnabled: true, TeamID: teamID, DiscardData: true, + Logging: fleet.LoggingDifferential, }) require.NoError(t, err) - // Interval=1, AutomationsEnabled=0, DiscardData=0 - q6, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: fmt.Sprintf("%s query6", teamIDStr), - Query: "select 1;", - Saved: true, - Interval: 10, - AutomationsEnabled: false, - TeamID: teamID, - DiscardData: false, - }) - require.NoError(t, err) - - // Interval=1, AutomationsEnabled=0, DiscardData=1 + // Interval=0, AutomationsEnabled=1, DiscardData=1, Snapshot=1 _, err = ds.NewQuery(context.Background(), &fleet.Query{ - Name: fmt.Sprintf("%s query7", teamIDStr), - Query: "select 1;", - Saved: true, - Interval: 10, - AutomationsEnabled: false, - TeamID: teamID, - DiscardData: true, - }) - require.NoError(t, err) - - // Interval=1, AutomationsEnabled=1, DiscardData=0 - q8, err := ds.NewQuery(context.Background(), &fleet.Query{ - Name: fmt.Sprintf("%s query8", teamIDStr), - Query: "select 1;", - Saved: true, - Interval: 10, - AutomationsEnabled: true, - TeamID: teamID, - DiscardData: false, - }) - require.NoError(t, err) - - // Interval=1, AutomationsEnabled=1, DiscardData=1 - q9, err := ds.NewQuery(context.Background(), &fleet.Query{ Name: fmt.Sprintf("%s query9", teamIDStr), Query: "select 1;", Saved: true, + Interval: 0, + AutomationsEnabled: true, + TeamID: teamID, + DiscardData: true, + Logging: fleet.LoggingSnapshot, + }) + require.NoError(t, err) + + // Interval=1, AutomationsEnabled=0, DiscardData=0, Snapshot=0 + _, err = ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query10", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 10, + AutomationsEnabled: false, + TeamID: teamID, + DiscardData: false, + Logging: fleet.LoggingDifferentialIgnoreRemovals, + }) + require.NoError(t, err) + + // Interval=1, AutomationsEnabled=0, DiscardData=0, Snapshot=1 + q11, err := ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query11", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 10, + AutomationsEnabled: false, + TeamID: teamID, + DiscardData: false, + Logging: fleet.LoggingSnapshot, + }) + require.NoError(t, err) + + // Interval=1, AutomationsEnabled=0, DiscardData=1, Snapshot=0 + _, err = ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query12", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 10, + AutomationsEnabled: false, + TeamID: teamID, + DiscardData: true, + Logging: fleet.LoggingDifferentialIgnoreRemovals, + }) + require.NoError(t, err) + + // Interval=1, AutomationsEnabled=0, DiscardData=1, Snapshot=1 + _, err = ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query13", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 10, + AutomationsEnabled: false, + TeamID: teamID, + DiscardData: true, + Logging: fleet.LoggingSnapshot, + }) + require.NoError(t, err) + + // Interval=1, AutomationsEnabled=1, DiscardData=0, Snapshot=0 + q14, err := ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query14", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 10, + AutomationsEnabled: true, + TeamID: teamID, + DiscardData: false, + Logging: fleet.LoggingDifferential, + }) + require.NoError(t, err) + + // Interval=1, AutomationsEnabled=1, DiscardData=0, Snapshot=1 + q15, err := ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query15", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 10, + AutomationsEnabled: true, + TeamID: teamID, + DiscardData: false, + Logging: fleet.LoggingSnapshot, + }) + require.NoError(t, err) + + // Interval=1, AutomationsEnabled=1, DiscardData=1, Snapshot=0 + q16, err := ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query16", teamIDStr), + Query: "select 1;", + Saved: true, Interval: 10, AutomationsEnabled: true, TeamID: teamID, DiscardData: true, + Logging: fleet.LoggingDifferential, + }) + require.NoError(t, err) + + // Interval=1, AutomationsEnabled=1, DiscardData=1, Snapshot=1 + q17, err := ds.NewQuery(context.Background(), &fleet.Query{ + Name: fmt.Sprintf("%s query17", teamIDStr), + Query: "select 1;", + Saved: true, + Interval: 10, + AutomationsEnabled: true, + TeamID: teamID, + DiscardData: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -823,7 +961,7 @@ func testListScheduledQueriesForAgents(t *testing.T, ds *Datastore) { sort.Slice(result, func(i, j int) bool { return result[i].ID < result[j].ID }) - test.QueryElementsMatch(t, result, []*fleet.Query{q6, q8, q9}, i) + test.QueryElementsMatch(t, result, []*fleet.Query{q11, q14, q15, q16, q17}, i) queryReportsDisabled = true result, err = ds.ListScheduledQueriesForAgents(ctx, teamID, queryReportsDisabled) @@ -831,6 +969,6 @@ func testListScheduledQueriesForAgents(t *testing.T, ds *Datastore) { sort.Slice(result, func(i, j int) bool { return result[i].ID < result[j].ID }) - test.QueryElementsMatch(t, result, []*fleet.Query{q8, q9}, i) + test.QueryElementsMatch(t, result, []*fleet.Query{q14, q15, q16, q17}, i) } } diff --git a/server/datastore/mysql/scheduled_queries_test.go b/server/datastore/mysql/scheduled_queries_test.go index 04568fea6..8b09a1331 100644 --- a/server/datastore/mysql/scheduled_queries_test.go +++ b/server/datastore/mysql/scheduled_queries_test.go @@ -41,8 +41,8 @@ func TestScheduledQueries(t *testing.T) { func testScheduledQueriesListInPackWithStats(t *testing.T, ds *Datastore) { zwass := test.NewUser(t, ds, "Zach", "zwass@fleet.co", true) queries := []*fleet.Query{ - {Name: "foo", Description: "get the foos", Query: "select * from foo"}, - {Name: "bar", Description: "do some bars", Query: "select baz from bar"}, + {Name: "foo", Description: "get the foos", Query: "select * from foo", Logging: fleet.LoggingSnapshot}, + {Name: "bar", Description: "do some bars", Query: "select baz from bar", Logging: fleet.LoggingDifferential}, } err := ds.ApplyQueries(context.Background(), zwass.ID, queries, nil) require.NoError(t, err) @@ -131,8 +131,8 @@ func testScheduledQueriesListInPackWithStats(t *testing.T, ds *Datastore) { func testScheduledQueriesListInPack(t *testing.T, ds *Datastore) { zwass := test.NewUser(t, ds, "Zach", "zwass@fleet.co", true) queries := []*fleet.Query{ - {Name: "foo", Description: "get the foos", Query: "select * from foo"}, - {Name: "bar", Description: "do some bars", Query: "select baz from bar"}, + {Name: "foo", Description: "get the foos", Query: "select * from foo", Logging: fleet.LoggingSnapshot}, + {Name: "bar", Description: "do some bars", Query: "select baz from bar", Logging: fleet.LoggingSnapshot}, } err := ds.ApplyQueries(context.Background(), zwass.ID, queries, nil) require.NoError(t, err) @@ -324,8 +324,8 @@ func testScheduledQueriesDelete(t *testing.T, ds *Datastore) { func testScheduledQueriesCascadingDelete(t *testing.T, ds *Datastore) { zwass := test.NewUser(t, ds, "Zach", "zwass@fleet.co", true) queries := []*fleet.Query{ - {Name: "foo", Description: "get the foos", Query: "select * from foo"}, - {Name: "bar", Description: "do some bars", Query: "select baz from bar"}, + {Name: "foo", Description: "get the foos", Query: "select * from foo", Logging: fleet.LoggingSnapshot}, + {Name: "bar", Description: "do some bars", Query: "select baz from bar", Logging: fleet.LoggingSnapshot}, } err := ds.ApplyQueries(context.Background(), zwass.ID, queries, nil) require.Nil(t, err) @@ -374,10 +374,10 @@ func testScheduledQueriesIDsByName(t *testing.T, ds *Datastore) { ctx := context.Background() user := test.NewUser(t, ds, "User", "user@example.com", true) queries := []*fleet.Query{ - {Name: "foo", Description: "get the foos", Query: "select * from foo"}, - {Name: "bar", Description: "do some bars", Query: "select * from bar"}, - {Name: "foo2", Description: "get the foos", Query: "select * from foo2"}, - {Name: "bar2", Description: "do some bars", Query: "select * from bar2"}, + {Name: "foo", Description: "get the foos", Query: "select * from foo", Logging: fleet.LoggingSnapshot}, + {Name: "bar", Description: "do some bars", Query: "select * from bar", Logging: fleet.LoggingSnapshot}, + {Name: "foo2", Description: "get the foos", Query: "select * from foo2", Logging: fleet.LoggingSnapshot}, + {Name: "bar2", Description: "do some bars", Query: "select * from bar2", Logging: fleet.LoggingSnapshot}, } err := ds.ApplyQueries(ctx, user.ID, queries, nil) require.NoError(t, err) diff --git a/server/datastore/mysql/schema.sql b/server/datastore/mysql/schema.sql index b8c43ee5e..935cb2a39 100644 --- a/server/datastore/mysql/schema.sql +++ b/server/datastore/mysql/schema.sql @@ -686,9 +686,9 @@ CREATE TABLE `migration_status_tables` ( `tstamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=214 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=215 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -INSERT INTO `migration_status_tables` VALUES (1,0,1,'2020-01-01 01:01:01'),(2,20161118193812,1,'2020-01-01 01:01:01'),(3,20161118211713,1,'2020-01-01 01:01:01'),(4,20161118212436,1,'2020-01-01 01:01:01'),(5,20161118212515,1,'2020-01-01 01:01:01'),(6,20161118212528,1,'2020-01-01 01:01:01'),(7,20161118212538,1,'2020-01-01 01:01:01'),(8,20161118212549,1,'2020-01-01 01:01:01'),(9,20161118212557,1,'2020-01-01 01:01:01'),(10,20161118212604,1,'2020-01-01 01:01:01'),(11,20161118212613,1,'2020-01-01 01:01:01'),(12,20161118212621,1,'2020-01-01 01:01:01'),(13,20161118212630,1,'2020-01-01 01:01:01'),(14,20161118212641,1,'2020-01-01 01:01:01'),(15,20161118212649,1,'2020-01-01 01:01:01'),(16,20161118212656,1,'2020-01-01 01:01:01'),(17,20161118212758,1,'2020-01-01 01:01:01'),(18,20161128234849,1,'2020-01-01 01:01:01'),(19,20161230162221,1,'2020-01-01 01:01:01'),(20,20170104113816,1,'2020-01-01 01:01:01'),(21,20170105151732,1,'2020-01-01 01:01:01'),(22,20170108191242,1,'2020-01-01 01:01:01'),(23,20170109094020,1,'2020-01-01 01:01:01'),(24,20170109130438,1,'2020-01-01 01:01:01'),(25,20170110202752,1,'2020-01-01 01:01:01'),(26,20170111133013,1,'2020-01-01 01:01:01'),(27,20170117025759,1,'2020-01-01 01:01:01'),(28,20170118191001,1,'2020-01-01 01:01:01'),(29,20170119234632,1,'2020-01-01 01:01:01'),(30,20170124230432,1,'2020-01-01 01:01:01'),(31,20170127014618,1,'2020-01-01 01:01:01'),(32,20170131232841,1,'2020-01-01 01:01:01'),(33,20170223094154,1,'2020-01-01 01:01:01'),(34,20170306075207,1,'2020-01-01 01:01:01'),(35,20170309100733,1,'2020-01-01 01:01:01'),(36,20170331111922,1,'2020-01-01 01:01:01'),(37,20170502143928,1,'2020-01-01 01:01:01'),(38,20170504130602,1,'2020-01-01 01:01:01'),(39,20170509132100,1,'2020-01-01 01:01:01'),(40,20170519105647,1,'2020-01-01 01:01:01'),(41,20170519105648,1,'2020-01-01 01:01:01'),(42,20170831234300,1,'2020-01-01 01:01:01'),(43,20170831234301,1,'2020-01-01 01:01:01'),(44,20170831234303,1,'2020-01-01 01:01:01'),(45,20171116163618,1,'2020-01-01 01:01:01'),(46,20171219164727,1,'2020-01-01 01:01:01'),(47,20180620164811,1,'2020-01-01 01:01:01'),(48,20180620175054,1,'2020-01-01 01:01:01'),(49,20180620175055,1,'2020-01-01 01:01:01'),(50,20191010101639,1,'2020-01-01 01:01:01'),(51,20191010155147,1,'2020-01-01 01:01:01'),(52,20191220130734,1,'2020-01-01 01:01:01'),(53,20200311140000,1,'2020-01-01 01:01:01'),(54,20200405120000,1,'2020-01-01 01:01:01'),(55,20200407120000,1,'2020-01-01 01:01:01'),(56,20200420120000,1,'2020-01-01 01:01:01'),(57,20200504120000,1,'2020-01-01 01:01:01'),(58,20200512120000,1,'2020-01-01 01:01:01'),(59,20200707120000,1,'2020-01-01 01:01:01'),(60,20201011162341,1,'2020-01-01 01:01:01'),(61,20201021104586,1,'2020-01-01 01:01:01'),(62,20201102112520,1,'2020-01-01 01:01:01'),(63,20201208121729,1,'2020-01-01 01:01:01'),(64,20201215091637,1,'2020-01-01 01:01:01'),(65,20210119174155,1,'2020-01-01 01:01:01'),(66,20210326182902,1,'2020-01-01 01:01:01'),(67,20210421112652,1,'2020-01-01 01:01:01'),(68,20210506095025,1,'2020-01-01 01:01:01'),(69,20210513115729,1,'2020-01-01 01:01:01'),(70,20210526113559,1,'2020-01-01 01:01:01'),(71,20210601000001,1,'2020-01-01 01:01:01'),(72,20210601000002,1,'2020-01-01 01:01:01'),(73,20210601000003,1,'2020-01-01 01:01:01'),(74,20210601000004,1,'2020-01-01 01:01:01'),(75,20210601000005,1,'2020-01-01 01:01:01'),(76,20210601000006,1,'2020-01-01 01:01:01'),(77,20210601000007,1,'2020-01-01 01:01:01'),(78,20210601000008,1,'2020-01-01 01:01:01'),(79,20210606151329,1,'2020-01-01 01:01:01'),(80,20210616163757,1,'2020-01-01 01:01:01'),(81,20210617174723,1,'2020-01-01 01:01:01'),(82,20210622160235,1,'2020-01-01 01:01:01'),(83,20210623100031,1,'2020-01-01 01:01:01'),(84,20210623133615,1,'2020-01-01 01:01:01'),(85,20210708143152,1,'2020-01-01 01:01:01'),(86,20210709124443,1,'2020-01-01 01:01:01'),(87,20210712155608,1,'2020-01-01 01:01:01'),(88,20210714102108,1,'2020-01-01 01:01:01'),(89,20210719153709,1,'2020-01-01 01:01:01'),(90,20210721171531,1,'2020-01-01 01:01:01'),(91,20210723135713,1,'2020-01-01 01:01:01'),(92,20210802135933,1,'2020-01-01 01:01:01'),(93,20210806112844,1,'2020-01-01 01:01:01'),(94,20210810095603,1,'2020-01-01 01:01:01'),(95,20210811150223,1,'2020-01-01 01:01:01'),(96,20210818151827,1,'2020-01-01 01:01:01'),(97,20210818151828,1,'2020-01-01 01:01:01'),(98,20210818182258,1,'2020-01-01 01:01:01'),(99,20210819131107,1,'2020-01-01 01:01:01'),(100,20210819143446,1,'2020-01-01 01:01:01'),(101,20210903132338,1,'2020-01-01 01:01:01'),(102,20210915144307,1,'2020-01-01 01:01:01'),(103,20210920155130,1,'2020-01-01 01:01:01'),(104,20210927143115,1,'2020-01-01 01:01:01'),(105,20210927143116,1,'2020-01-01 01:01:01'),(106,20211013133706,1,'2020-01-01 01:01:01'),(107,20211013133707,1,'2020-01-01 01:01:01'),(108,20211102135149,1,'2020-01-01 01:01:01'),(109,20211109121546,1,'2020-01-01 01:01:01'),(110,20211110163320,1,'2020-01-01 01:01:01'),(111,20211116184029,1,'2020-01-01 01:01:01'),(112,20211116184030,1,'2020-01-01 01:01:01'),(113,20211202092042,1,'2020-01-01 01:01:01'),(114,20211202181033,1,'2020-01-01 01:01:01'),(115,20211207161856,1,'2020-01-01 01:01:01'),(116,20211216131203,1,'2020-01-01 01:01:01'),(117,20211221110132,1,'2020-01-01 01:01:01'),(118,20220107155700,1,'2020-01-01 01:01:01'),(119,20220125105650,1,'2020-01-01 01:01:01'),(120,20220201084510,1,'2020-01-01 01:01:01'),(121,20220208144830,1,'2020-01-01 01:01:01'),(122,20220208144831,1,'2020-01-01 01:01:01'),(123,20220215152203,1,'2020-01-01 01:01:01'),(124,20220223113157,1,'2020-01-01 01:01:01'),(125,20220307104655,1,'2020-01-01 01:01:01'),(126,20220309133956,1,'2020-01-01 01:01:01'),(127,20220316155700,1,'2020-01-01 01:01:01'),(128,20220323152301,1,'2020-01-01 01:01:01'),(129,20220330100659,1,'2020-01-01 01:01:01'),(130,20220404091216,1,'2020-01-01 01:01:01'),(131,20220419140750,1,'2020-01-01 01:01:01'),(132,20220428140039,1,'2020-01-01 01:01:01'),(133,20220503134048,1,'2020-01-01 01:01:01'),(134,20220524102918,1,'2020-01-01 01:01:01'),(135,20220526123327,1,'2020-01-01 01:01:01'),(136,20220526123328,1,'2020-01-01 01:01:01'),(137,20220526123329,1,'2020-01-01 01:01:01'),(138,20220608113128,1,'2020-01-01 01:01:01'),(139,20220627104817,1,'2020-01-01 01:01:01'),(140,20220704101843,1,'2020-01-01 01:01:01'),(141,20220708095046,1,'2020-01-01 01:01:01'),(142,20220713091130,1,'2020-01-01 01:01:01'),(143,20220802135510,1,'2020-01-01 01:01:01'),(144,20220818101352,1,'2020-01-01 01:01:01'),(145,20220822161445,1,'2020-01-01 01:01:01'),(146,20220831100036,1,'2020-01-01 01:01:01'),(147,20220831100151,1,'2020-01-01 01:01:01'),(148,20220908181826,1,'2020-01-01 01:01:01'),(149,20220914154915,1,'2020-01-01 01:01:01'),(150,20220915165115,1,'2020-01-01 01:01:01'),(151,20220915165116,1,'2020-01-01 01:01:01'),(152,20220928100158,1,'2020-01-01 01:01:01'),(153,20221014084130,1,'2020-01-01 01:01:01'),(154,20221027085019,1,'2020-01-01 01:01:01'),(155,20221101103952,1,'2020-01-01 01:01:01'),(156,20221104144401,1,'2020-01-01 01:01:01'),(157,20221109100749,1,'2020-01-01 01:01:01'),(158,20221115104546,1,'2020-01-01 01:01:01'),(159,20221130114928,1,'2020-01-01 01:01:01'),(160,20221205112142,1,'2020-01-01 01:01:01'),(161,20221216115820,1,'2020-01-01 01:01:01'),(162,20221220195934,1,'2020-01-01 01:01:01'),(163,20221220195935,1,'2020-01-01 01:01:01'),(164,20221223174807,1,'2020-01-01 01:01:01'),(165,20221227163855,1,'2020-01-01 01:01:01'),(166,20221227163856,1,'2020-01-01 01:01:01'),(167,20230202224725,1,'2020-01-01 01:01:01'),(168,20230206163608,1,'2020-01-01 01:01:01'),(169,20230214131519,1,'2020-01-01 01:01:01'),(170,20230303135738,1,'2020-01-01 01:01:01'),(171,20230313135301,1,'2020-01-01 01:01:01'),(172,20230313141819,1,'2020-01-01 01:01:01'),(173,20230315104937,1,'2020-01-01 01:01:01'),(174,20230317173844,1,'2020-01-01 01:01:01'),(175,20230320133602,1,'2020-01-01 01:01:01'),(176,20230330100011,1,'2020-01-01 01:01:01'),(177,20230330134823,1,'2020-01-01 01:01:01'),(178,20230405232025,1,'2020-01-01 01:01:01'),(179,20230408084104,1,'2020-01-01 01:01:01'),(180,20230411102858,1,'2020-01-01 01:01:01'),(181,20230421155932,1,'2020-01-01 01:01:01'),(182,20230425082126,1,'2020-01-01 01:01:01'),(183,20230425105727,1,'2020-01-01 01:01:01'),(184,20230501154913,1,'2020-01-01 01:01:01'),(185,20230503101418,1,'2020-01-01 01:01:01'),(186,20230515144206,1,'2020-01-01 01:01:01'),(187,20230517140952,1,'2020-01-01 01:01:01'),(188,20230517152807,1,'2020-01-01 01:01:01'),(189,20230518114155,1,'2020-01-01 01:01:01'),(190,20230520153236,1,'2020-01-01 01:01:01'),(191,20230525151159,1,'2020-01-01 01:01:01'),(192,20230530122103,1,'2020-01-01 01:01:01'),(193,20230602111827,1,'2020-01-01 01:01:01'),(194,20230608103123,1,'2020-01-01 01:01:01'),(195,20230629140529,1,'2020-01-01 01:01:01'),(196,20230629140530,1,'2020-01-01 01:01:01'),(197,20230711144622,1,'2020-01-01 01:01:01'),(198,20230721135421,1,'2020-01-01 01:01:01'),(199,20230721161508,1,'2020-01-01 01:01:01'),(200,20230726115701,1,'2020-01-01 01:01:01'),(201,20230807100822,1,'2020-01-01 01:01:01'),(202,20230814150442,1,'2020-01-01 01:01:01'),(203,20230823122728,1,'2020-01-01 01:01:01'),(204,20230906152143,1,'2020-01-01 01:01:01'),(205,20230911163618,1,'2020-01-01 01:01:01'),(206,20230912101759,1,'2020-01-01 01:01:01'),(207,20230915101341,1,'2020-01-01 01:01:01'),(208,20230918132351,1,'2020-01-01 01:01:01'),(209,20231004144339,1,'2020-01-01 01:01:01'),(210,20231009094541,1,'2020-01-01 01:01:01'),(211,20231009094542,1,'2020-01-01 01:01:01'),(212,20231009094543,1,'2020-01-01 01:01:01'),(213,20231009094544,1,'2020-01-01 01:01:01'); +INSERT INTO `migration_status_tables` VALUES (1,0,1,'2020-01-01 01:01:01'),(2,20161118193812,1,'2020-01-01 01:01:01'),(3,20161118211713,1,'2020-01-01 01:01:01'),(4,20161118212436,1,'2020-01-01 01:01:01'),(5,20161118212515,1,'2020-01-01 01:01:01'),(6,20161118212528,1,'2020-01-01 01:01:01'),(7,20161118212538,1,'2020-01-01 01:01:01'),(8,20161118212549,1,'2020-01-01 01:01:01'),(9,20161118212557,1,'2020-01-01 01:01:01'),(10,20161118212604,1,'2020-01-01 01:01:01'),(11,20161118212613,1,'2020-01-01 01:01:01'),(12,20161118212621,1,'2020-01-01 01:01:01'),(13,20161118212630,1,'2020-01-01 01:01:01'),(14,20161118212641,1,'2020-01-01 01:01:01'),(15,20161118212649,1,'2020-01-01 01:01:01'),(16,20161118212656,1,'2020-01-01 01:01:01'),(17,20161118212758,1,'2020-01-01 01:01:01'),(18,20161128234849,1,'2020-01-01 01:01:01'),(19,20161230162221,1,'2020-01-01 01:01:01'),(20,20170104113816,1,'2020-01-01 01:01:01'),(21,20170105151732,1,'2020-01-01 01:01:01'),(22,20170108191242,1,'2020-01-01 01:01:01'),(23,20170109094020,1,'2020-01-01 01:01:01'),(24,20170109130438,1,'2020-01-01 01:01:01'),(25,20170110202752,1,'2020-01-01 01:01:01'),(26,20170111133013,1,'2020-01-01 01:01:01'),(27,20170117025759,1,'2020-01-01 01:01:01'),(28,20170118191001,1,'2020-01-01 01:01:01'),(29,20170119234632,1,'2020-01-01 01:01:01'),(30,20170124230432,1,'2020-01-01 01:01:01'),(31,20170127014618,1,'2020-01-01 01:01:01'),(32,20170131232841,1,'2020-01-01 01:01:01'),(33,20170223094154,1,'2020-01-01 01:01:01'),(34,20170306075207,1,'2020-01-01 01:01:01'),(35,20170309100733,1,'2020-01-01 01:01:01'),(36,20170331111922,1,'2020-01-01 01:01:01'),(37,20170502143928,1,'2020-01-01 01:01:01'),(38,20170504130602,1,'2020-01-01 01:01:01'),(39,20170509132100,1,'2020-01-01 01:01:01'),(40,20170519105647,1,'2020-01-01 01:01:01'),(41,20170519105648,1,'2020-01-01 01:01:01'),(42,20170831234300,1,'2020-01-01 01:01:01'),(43,20170831234301,1,'2020-01-01 01:01:01'),(44,20170831234303,1,'2020-01-01 01:01:01'),(45,20171116163618,1,'2020-01-01 01:01:01'),(46,20171219164727,1,'2020-01-01 01:01:01'),(47,20180620164811,1,'2020-01-01 01:01:01'),(48,20180620175054,1,'2020-01-01 01:01:01'),(49,20180620175055,1,'2020-01-01 01:01:01'),(50,20191010101639,1,'2020-01-01 01:01:01'),(51,20191010155147,1,'2020-01-01 01:01:01'),(52,20191220130734,1,'2020-01-01 01:01:01'),(53,20200311140000,1,'2020-01-01 01:01:01'),(54,20200405120000,1,'2020-01-01 01:01:01'),(55,20200407120000,1,'2020-01-01 01:01:01'),(56,20200420120000,1,'2020-01-01 01:01:01'),(57,20200504120000,1,'2020-01-01 01:01:01'),(58,20200512120000,1,'2020-01-01 01:01:01'),(59,20200707120000,1,'2020-01-01 01:01:01'),(60,20201011162341,1,'2020-01-01 01:01:01'),(61,20201021104586,1,'2020-01-01 01:01:01'),(62,20201102112520,1,'2020-01-01 01:01:01'),(63,20201208121729,1,'2020-01-01 01:01:01'),(64,20201215091637,1,'2020-01-01 01:01:01'),(65,20210119174155,1,'2020-01-01 01:01:01'),(66,20210326182902,1,'2020-01-01 01:01:01'),(67,20210421112652,1,'2020-01-01 01:01:01'),(68,20210506095025,1,'2020-01-01 01:01:01'),(69,20210513115729,1,'2020-01-01 01:01:01'),(70,20210526113559,1,'2020-01-01 01:01:01'),(71,20210601000001,1,'2020-01-01 01:01:01'),(72,20210601000002,1,'2020-01-01 01:01:01'),(73,20210601000003,1,'2020-01-01 01:01:01'),(74,20210601000004,1,'2020-01-01 01:01:01'),(75,20210601000005,1,'2020-01-01 01:01:01'),(76,20210601000006,1,'2020-01-01 01:01:01'),(77,20210601000007,1,'2020-01-01 01:01:01'),(78,20210601000008,1,'2020-01-01 01:01:01'),(79,20210606151329,1,'2020-01-01 01:01:01'),(80,20210616163757,1,'2020-01-01 01:01:01'),(81,20210617174723,1,'2020-01-01 01:01:01'),(82,20210622160235,1,'2020-01-01 01:01:01'),(83,20210623100031,1,'2020-01-01 01:01:01'),(84,20210623133615,1,'2020-01-01 01:01:01'),(85,20210708143152,1,'2020-01-01 01:01:01'),(86,20210709124443,1,'2020-01-01 01:01:01'),(87,20210712155608,1,'2020-01-01 01:01:01'),(88,20210714102108,1,'2020-01-01 01:01:01'),(89,20210719153709,1,'2020-01-01 01:01:01'),(90,20210721171531,1,'2020-01-01 01:01:01'),(91,20210723135713,1,'2020-01-01 01:01:01'),(92,20210802135933,1,'2020-01-01 01:01:01'),(93,20210806112844,1,'2020-01-01 01:01:01'),(94,20210810095603,1,'2020-01-01 01:01:01'),(95,20210811150223,1,'2020-01-01 01:01:01'),(96,20210818151827,1,'2020-01-01 01:01:01'),(97,20210818151828,1,'2020-01-01 01:01:01'),(98,20210818182258,1,'2020-01-01 01:01:01'),(99,20210819131107,1,'2020-01-01 01:01:01'),(100,20210819143446,1,'2020-01-01 01:01:01'),(101,20210903132338,1,'2020-01-01 01:01:01'),(102,20210915144307,1,'2020-01-01 01:01:01'),(103,20210920155130,1,'2020-01-01 01:01:01'),(104,20210927143115,1,'2020-01-01 01:01:01'),(105,20210927143116,1,'2020-01-01 01:01:01'),(106,20211013133706,1,'2020-01-01 01:01:01'),(107,20211013133707,1,'2020-01-01 01:01:01'),(108,20211102135149,1,'2020-01-01 01:01:01'),(109,20211109121546,1,'2020-01-01 01:01:01'),(110,20211110163320,1,'2020-01-01 01:01:01'),(111,20211116184029,1,'2020-01-01 01:01:01'),(112,20211116184030,1,'2020-01-01 01:01:01'),(113,20211202092042,1,'2020-01-01 01:01:01'),(114,20211202181033,1,'2020-01-01 01:01:01'),(115,20211207161856,1,'2020-01-01 01:01:01'),(116,20211216131203,1,'2020-01-01 01:01:01'),(117,20211221110132,1,'2020-01-01 01:01:01'),(118,20220107155700,1,'2020-01-01 01:01:01'),(119,20220125105650,1,'2020-01-01 01:01:01'),(120,20220201084510,1,'2020-01-01 01:01:01'),(121,20220208144830,1,'2020-01-01 01:01:01'),(122,20220208144831,1,'2020-01-01 01:01:01'),(123,20220215152203,1,'2020-01-01 01:01:01'),(124,20220223113157,1,'2020-01-01 01:01:01'),(125,20220307104655,1,'2020-01-01 01:01:01'),(126,20220309133956,1,'2020-01-01 01:01:01'),(127,20220316155700,1,'2020-01-01 01:01:01'),(128,20220323152301,1,'2020-01-01 01:01:01'),(129,20220330100659,1,'2020-01-01 01:01:01'),(130,20220404091216,1,'2020-01-01 01:01:01'),(131,20220419140750,1,'2020-01-01 01:01:01'),(132,20220428140039,1,'2020-01-01 01:01:01'),(133,20220503134048,1,'2020-01-01 01:01:01'),(134,20220524102918,1,'2020-01-01 01:01:01'),(135,20220526123327,1,'2020-01-01 01:01:01'),(136,20220526123328,1,'2020-01-01 01:01:01'),(137,20220526123329,1,'2020-01-01 01:01:01'),(138,20220608113128,1,'2020-01-01 01:01:01'),(139,20220627104817,1,'2020-01-01 01:01:01'),(140,20220704101843,1,'2020-01-01 01:01:01'),(141,20220708095046,1,'2020-01-01 01:01:01'),(142,20220713091130,1,'2020-01-01 01:01:01'),(143,20220802135510,1,'2020-01-01 01:01:01'),(144,20220818101352,1,'2020-01-01 01:01:01'),(145,20220822161445,1,'2020-01-01 01:01:01'),(146,20220831100036,1,'2020-01-01 01:01:01'),(147,20220831100151,1,'2020-01-01 01:01:01'),(148,20220908181826,1,'2020-01-01 01:01:01'),(149,20220914154915,1,'2020-01-01 01:01:01'),(150,20220915165115,1,'2020-01-01 01:01:01'),(151,20220915165116,1,'2020-01-01 01:01:01'),(152,20220928100158,1,'2020-01-01 01:01:01'),(153,20221014084130,1,'2020-01-01 01:01:01'),(154,20221027085019,1,'2020-01-01 01:01:01'),(155,20221101103952,1,'2020-01-01 01:01:01'),(156,20221104144401,1,'2020-01-01 01:01:01'),(157,20221109100749,1,'2020-01-01 01:01:01'),(158,20221115104546,1,'2020-01-01 01:01:01'),(159,20221130114928,1,'2020-01-01 01:01:01'),(160,20221205112142,1,'2020-01-01 01:01:01'),(161,20221216115820,1,'2020-01-01 01:01:01'),(162,20221220195934,1,'2020-01-01 01:01:01'),(163,20221220195935,1,'2020-01-01 01:01:01'),(164,20221223174807,1,'2020-01-01 01:01:01'),(165,20221227163855,1,'2020-01-01 01:01:01'),(166,20221227163856,1,'2020-01-01 01:01:01'),(167,20230202224725,1,'2020-01-01 01:01:01'),(168,20230206163608,1,'2020-01-01 01:01:01'),(169,20230214131519,1,'2020-01-01 01:01:01'),(170,20230303135738,1,'2020-01-01 01:01:01'),(171,20230313135301,1,'2020-01-01 01:01:01'),(172,20230313141819,1,'2020-01-01 01:01:01'),(173,20230315104937,1,'2020-01-01 01:01:01'),(174,20230317173844,1,'2020-01-01 01:01:01'),(175,20230320133602,1,'2020-01-01 01:01:01'),(176,20230330100011,1,'2020-01-01 01:01:01'),(177,20230330134823,1,'2020-01-01 01:01:01'),(178,20230405232025,1,'2020-01-01 01:01:01'),(179,20230408084104,1,'2020-01-01 01:01:01'),(180,20230411102858,1,'2020-01-01 01:01:01'),(181,20230421155932,1,'2020-01-01 01:01:01'),(182,20230425082126,1,'2020-01-01 01:01:01'),(183,20230425105727,1,'2020-01-01 01:01:01'),(184,20230501154913,1,'2020-01-01 01:01:01'),(185,20230503101418,1,'2020-01-01 01:01:01'),(186,20230515144206,1,'2020-01-01 01:01:01'),(187,20230517140952,1,'2020-01-01 01:01:01'),(188,20230517152807,1,'2020-01-01 01:01:01'),(189,20230518114155,1,'2020-01-01 01:01:01'),(190,20230520153236,1,'2020-01-01 01:01:01'),(191,20230525151159,1,'2020-01-01 01:01:01'),(192,20230530122103,1,'2020-01-01 01:01:01'),(193,20230602111827,1,'2020-01-01 01:01:01'),(194,20230608103123,1,'2020-01-01 01:01:01'),(195,20230629140529,1,'2020-01-01 01:01:01'),(196,20230629140530,1,'2020-01-01 01:01:01'),(197,20230711144622,1,'2020-01-01 01:01:01'),(198,20230721135421,1,'2020-01-01 01:01:01'),(199,20230721161508,1,'2020-01-01 01:01:01'),(200,20230726115701,1,'2020-01-01 01:01:01'),(201,20230807100822,1,'2020-01-01 01:01:01'),(202,20230814150442,1,'2020-01-01 01:01:01'),(203,20230823122728,1,'2020-01-01 01:01:01'),(204,20230906152143,1,'2020-01-01 01:01:01'),(205,20230911163618,1,'2020-01-01 01:01:01'),(206,20230912101759,1,'2020-01-01 01:01:01'),(207,20230915101341,1,'2020-01-01 01:01:01'),(208,20230918132351,1,'2020-01-01 01:01:01'),(209,20231004144339,1,'2020-01-01 01:01:01'),(210,20231009094541,1,'2020-01-01 01:01:01'),(211,20231009094542,1,'2020-01-01 01:01:01'),(212,20231009094543,1,'2020-01-01 01:01:01'),(213,20231009094544,1,'2020-01-01 01:01:01'),(214,20231016091915,1,'2020-01-01 01:01:01'); /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mobile_device_management_solutions` ( diff --git a/server/fleet/queries.go b/server/fleet/queries.go index 6c0b86d0f..fc433aeed 100644 --- a/server/fleet/queries.go +++ b/server/fleet/queries.go @@ -236,8 +236,7 @@ func verifyQuerySQL(query string) error { } func verifyLogging(logging string) error { - // Empty string means snapshot. - if logging != "" && logging != LoggingSnapshot && logging != LoggingDifferential && logging != LoggingDifferentialIgnoreRemovals { + if logging != LoggingSnapshot && logging != LoggingDifferential && logging != LoggingDifferentialIgnoreRemovals { return errInvalidLogging } return nil diff --git a/server/fleet/scheduled_queries.go b/server/fleet/scheduled_queries.go index e44e2f398..91d4496bb 100644 --- a/server/fleet/scheduled_queries.go +++ b/server/fleet/scheduled_queries.go @@ -181,7 +181,7 @@ func ScheduledQueryFromQuery(query *Query) *ScheduledQuery { } func ScheduledQueryToQueryPayloadForNewQuery(originalQuery *Query, scheduledQuery *ScheduledQuery) QueryPayload { - var logging *string + logging := ptr.String(LoggingSnapshot) // default is snapshot. if scheduledQuery.Snapshot != nil && scheduledQuery.Removed != nil { if *scheduledQuery.Snapshot { logging = ptr.String(LoggingSnapshot) diff --git a/server/service/campaigns.go b/server/service/campaigns.go index 6b58b3e01..d98d35300 100644 --- a/server/service/campaigns.go +++ b/server/service/campaigns.go @@ -72,6 +72,8 @@ func (svc *Service) NewDistributedQueryCampaign(ctx context.Context, queryString Query: queryString, Saved: false, AuthorID: ptr.Uint(vc.UserID()), + // We must set a valid value for this field, even if unused by live queries. + Logging: fleet.LoggingSnapshot, } if err := query.Verify(); err != nil { return nil, ctxerr.Wrap(ctx, &fleet.BadRequestError{ diff --git a/server/service/integration_core_test.go b/server/service/integration_core_test.go index 8af8976a8..049725f88 100644 --- a/server/service/integration_core_test.go +++ b/server/service/integration_core_test.go @@ -559,6 +559,7 @@ func (s *integrationTestSuite) TestGlobalSchedule() { Query: "select * from osquery;", ObserverCanRun: true, Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -788,6 +789,7 @@ func (s *integrationTestSuite) TestGlobalPolicies() { Description: "Some description", Query: "select * from osquery;", ObserverCanRun: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -1795,6 +1797,7 @@ func (s *integrationTestSuite) TestGlobalPoliciesProprietary() { Description: "Some description", Query: "select * from osquery;", ObserverCanRun: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) // Cannot set both QueryID and Query. @@ -4478,6 +4481,7 @@ func (s *integrationTestSuite) TestQueriesBadRequests() { name string query string platform string + logging string }{ { tname: "empty name", @@ -4518,12 +4522,19 @@ func (s *integrationTestSuite) TestQueriesBadRequests() { query: "select 1", platform: "windows darwin", }, + { + tname: "invalid logging value", + name: "bad query", + query: "select 1", + logging: "foobar", + }, } { t.Run(tc.tname, func(t *testing.T) { reqQuery := &fleet.QueryPayload{ Name: ptr.String(tc.name), Query: ptr.String(tc.query), Platform: ptr.String(tc.platform), + Logging: ptr.String(tc.logging), } createQueryResp := createQueryResponse{} s.DoJSON("POST", "/api/latest/fleet/queries", reqQuery, http.StatusBadRequest, &createQueryResp) @@ -4533,6 +4544,7 @@ func (s *integrationTestSuite) TestQueriesBadRequests() { Name: ptr.String(tc.name), Query: ptr.String(tc.query), Platform: ptr.String(tc.platform), + Logging: ptr.String(tc.logging), } mResp := modifyQueryResponse{} s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/queries/%d", existingQueryID), &payload, http.StatusBadRequest, &mResp) @@ -6729,6 +6741,7 @@ func (s *integrationTestSuite) TestAPIVersion_v1_2022_04() { Query: "select * from osquery;", ObserverCanRun: true, Saved: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -7069,7 +7082,7 @@ func (s *integrationTestSuite) TestDirectIngestScheduledQueryStats() { Interval: 10, Platform: "darwin", AutomationsEnabled: true, - Logging: "snapshot", + Logging: fleet.LoggingSnapshot, Description: "foobar", Query: "SELECT * from time;", Saved: true, @@ -7081,7 +7094,7 @@ func (s *integrationTestSuite) TestDirectIngestScheduledQueryStats() { Interval: 0, Platform: "darwin", AutomationsEnabled: false, - Logging: "snapshot", + Logging: fleet.LoggingSnapshot, Description: "foobar", Query: "SELECT * from osquery_info;", Saved: true, @@ -7093,7 +7106,7 @@ func (s *integrationTestSuite) TestDirectIngestScheduledQueryStats() { Interval: 20, Platform: "", AutomationsEnabled: true, - Logging: "snapshot", + Logging: fleet.LoggingSnapshot, Description: "foobar", Query: "SELECT * from other;", Saved: true, @@ -7105,7 +7118,7 @@ func (s *integrationTestSuite) TestDirectIngestScheduledQueryStats() { Interval: 90, Platform: "", AutomationsEnabled: true, - Logging: "snapshot", + Logging: fleet.LoggingSnapshot, Description: "foobar", Query: "SELECT * from other;", Saved: true, @@ -7133,7 +7146,7 @@ func (s *integrationTestSuite) TestDirectIngestScheduledQueryStats() { Interval: 40, Platform: "", AutomationsEnabled: true, - Logging: "snapshot", + Logging: fleet.LoggingSnapshot, Description: "foobar", Query: "SELECT * from other;", Saved: true, diff --git a/server/service/integration_enterprise_test.go b/server/service/integration_enterprise_test.go index 8b2b12a57..085279de2 100644 --- a/server/service/integration_enterprise_test.go +++ b/server/service/integration_enterprise_test.go @@ -481,6 +481,7 @@ func (s *integrationEnterpriseTestSuite) TestTeamSchedule() { Query: "select * from osquery;", ObserverCanRun: true, Saved: true, + Logging: fleet.LoggingSnapshot, }, ) require.NoError(t, err) @@ -568,7 +569,13 @@ func (s *integrationEnterpriseTestSuite) TestTeamPolicies() { require.NoError(t, err) }() - qr, err := s.ds.NewQuery(context.Background(), &fleet.Query{Name: "TestQuery2", Description: "Some description", Query: "select * from osquery;", ObserverCanRun: true}) + qr, err := s.ds.NewQuery(context.Background(), &fleet.Query{ + Name: "TestQuery2", + Description: "Some description", + Query: "select * from osquery;", + ObserverCanRun: true, + Logging: fleet.LoggingSnapshot, + }) require.NoError(t, err) tpParams := teamPolicyRequest{ @@ -1846,6 +1853,7 @@ func (s *integrationEnterpriseTestSuite) TestListDevicePolicies() { Description: "Some description", Query: "select * from osquery;", ObserverCanRun: true, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) @@ -3010,8 +3018,9 @@ func (s *integrationEnterpriseTestSuite) TestGitOpsUserActions() { s.DoJSON("GET", "/api/latest/fleet/config", nil, http.StatusOK, &acr) require.False(t, acr.WebhookSettings.VulnerabilitiesWebhook.Enable) q1, err := s.ds.NewQuery(ctx, &fleet.Query{ - Name: "Foo", - Query: "SELECT * from time;", + Name: "Foo", + Query: "SELECT * from time;", + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err) ggsr := getGlobalScheduleResponse{} diff --git a/server/service/integration_live_queries_test.go b/server/service/integration_live_queries_test.go index adc0dc0d2..14c6e8ccd 100644 --- a/server/service/integration_live_queries_test.go +++ b/server/service/integration_live_queries_test.go @@ -83,7 +83,12 @@ func (s *liveQueriesTestSuite) TestLiveQueriesRestOneHostOneQuery() { host := s.hosts[0] - q1, err := s.ds.NewQuery(context.Background(), &fleet.Query{Query: "select 1 from osquery;", Description: "desc1", Name: t.Name() + "query1"}) + q1, err := s.ds.NewQuery(context.Background(), &fleet.Query{ + Query: "select 1 from osquery;", + Description: "desc1", + Name: t.Name() + "query1", + Logging: fleet.LoggingSnapshot, + }) require.NoError(t, err) s.lq.On("QueriesForHost", uint(1)).Return(map[string]string{fmt.Sprint(q1.ID): "select 1 from osquery;"}, nil) @@ -142,10 +147,20 @@ func (s *liveQueriesTestSuite) TestLiveQueriesRestOneHostMultipleQuery() { host := s.hosts[0] - q1, err := s.ds.NewQuery(context.Background(), &fleet.Query{Query: "select 1 from osquery;", Description: "desc1", Name: t.Name() + "query1"}) + q1, err := s.ds.NewQuery(context.Background(), &fleet.Query{ + Query: "select 1 from osquery;", + Description: "desc1", + Name: t.Name() + "query1", + Logging: fleet.LoggingSnapshot, + }) require.NoError(t, err) - q2, err := s.ds.NewQuery(context.Background(), &fleet.Query{Query: "select 2 from osquery;", Description: "desc2", Name: t.Name() + "query2"}) + q2, err := s.ds.NewQuery(context.Background(), &fleet.Query{ + Query: "select 2 from osquery;", + Description: "desc2", + Name: t.Name() + "query2", + Logging: fleet.LoggingSnapshot, + }) require.NoError(t, err) s.lq.On("QueriesForHost", host.ID).Return(map[string]string{ @@ -237,10 +252,20 @@ func (s *liveQueriesTestSuite) TestLiveQueriesRestMultipleHostMultipleQuery() { h1 := s.hosts[0] h2 := s.hosts[1] - q1, err := s.ds.NewQuery(context.Background(), &fleet.Query{Query: "select 1 from osquery;", Description: "desc1", Name: t.Name() + "query1"}) + q1, err := s.ds.NewQuery(context.Background(), &fleet.Query{ + Query: "select 1 from osquery;", + Description: "desc1", + Name: t.Name() + "query1", + Logging: fleet.LoggingSnapshot, + }) require.NoError(t, err) - q2, err := s.ds.NewQuery(context.Background(), &fleet.Query{Query: "select 2 from osquery;", Description: "desc2", Name: t.Name() + "query2"}) + q2, err := s.ds.NewQuery(context.Background(), &fleet.Query{ + Query: "select 2 from osquery;", + Description: "desc2", + Name: t.Name() + "query2", + Logging: fleet.LoggingSnapshot, + }) require.NoError(t, err) s.lq.On("QueriesForHost", h1.ID).Return(map[string]string{ @@ -344,7 +369,12 @@ func (s *liveQueriesTestSuite) TestLiveQueriesRestFailsOnSomeHost() { h1 := s.hosts[0] h2 := s.hosts[1] - q1, err := s.ds.NewQuery(context.Background(), &fleet.Query{Query: "select 1 from osquery;", Description: "desc1", Name: t.Name() + "query1"}) + q1, err := s.ds.NewQuery(context.Background(), &fleet.Query{ + Query: "select 1 from osquery;", + Description: "desc1", + Name: t.Name() + "query1", + Logging: fleet.LoggingSnapshot, + }) require.NoError(t, err) s.lq.On("QueriesForHost", h1.ID).Return(map[string]string{fmt.Sprint(q1.ID): "select 1 from osquery;"}, nil) diff --git a/server/service/queries.go b/server/service/queries.go index 6304df1ee..0ff0d850a 100644 --- a/server/service/queries.go +++ b/server/service/queries.go @@ -209,6 +209,10 @@ func (svc *Service) NewQuery(ctx context.Context, p fleet.QueryPayload) (*fleet. return nil, err } + if p.Logging == nil || (p.Logging != nil && *p.Logging == "") { + p.Logging = ptr.String(fleet.LoggingSnapshot) + } + if err := p.Verify(); err != nil { return nil, ctxerr.Wrap(ctx, &fleet.BadRequestError{ Message: fmt.Sprintf("query payload verification: %s", err), @@ -317,6 +321,10 @@ func (svc *Service) ModifyQuery(ctx context.Context, id uint, p fleet.QueryPaylo return nil, err } + if p.Logging != nil && *p.Logging == "" { + p.Logging = ptr.String(fleet.LoggingSnapshot) + } + if err := p.Verify(); err != nil { return nil, ctxerr.Wrap(ctx, &fleet.BadRequestError{ Message: fmt.Sprintf("query payload verification: %s", err), @@ -640,6 +648,10 @@ func (svc *Service) queryFromSpec(ctx context.Context, spec *fleet.QuerySpec) (* } teamID = &team.ID } + logging := spec.Logging + if logging == "" { + logging = fleet.LoggingSnapshot + } return &fleet.Query{ Name: spec.Name, Description: spec.Description, @@ -651,7 +663,7 @@ func (svc *Service) queryFromSpec(ctx context.Context, spec *fleet.QuerySpec) (* Platform: spec.Platform, MinOsqueryVersion: spec.MinOsqueryVersion, AutomationsEnabled: spec.AutomationsEnabled, - Logging: spec.Logging, + Logging: logging, DiscardData: spec.DiscardData, }, nil } diff --git a/server/test/new_objects.go b/server/test/new_objects.go index 407256527..8db4f5685 100644 --- a/server/test/new_objects.go +++ b/server/test/new_objects.go @@ -25,6 +25,7 @@ func NewQueryWithSchedule(t *testing.T, ds fleet.Datastore, teamID *uint, name, TeamID: teamID, Interval: interval, AutomationsEnabled: automationsEnabled, + Logging: fleet.LoggingSnapshot, }) require.NoError(t, err)