From 2f585e391629aeee6ac3f386783cf6c2d6a7aa30 Mon Sep 17 00:00:00 2001 From: Lucas Manuel Rodriguez Date: Mon, 13 Mar 2023 10:06:39 -0300 Subject: [PATCH] Improve logging to detect unrecognized platforms (#10423) Just improving logs to detect platforms that Fleet does not recognize yet (mostly Linux distributions) - ~[ ] Changes file added for user-visible changes in `changes/` or `orbit/changes/`.~ See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - ~[ ] Documented any API changes (docs/Using-Fleet/REST-API.md or docs/Contributing/API-for-contributors.md)~ - ~[ ] Documented any permissions changes~ - ~[ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements)~ - ~[ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features.~ - ~[ ] Added/updated tests~ - [X] Manual QA for all new/changed functionality - ~For Orbit and Fleet Desktop changes:~ - ~[ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ - ~[ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ --- server/datastore/mysql/hosts.go | 4 ++-- server/datastore/mysql/policies.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/datastore/mysql/hosts.go b/server/datastore/mysql/hosts.go index 387518f65f..eebacff3b0 100644 --- a/server/datastore/mysql/hosts.go +++ b/server/datastore/mysql/hosts.go @@ -1914,7 +1914,7 @@ func (ds *Datastore) DeleteHosts(ctx context.Context, ids []uint) error { func (ds *Datastore) FailingPoliciesCount(ctx context.Context, host *fleet.Host) (uint, error) { if host.FleetPlatform() == "" { // We log to help troubleshooting in case this happens. - level.Error(ds.logger).Log("err", fmt.Sprintf("host %d with empty platform", host.ID)) + level.Error(ds.logger).Log("err", "unrecognized platform", "hostID", host.ID, "platform", host.Platform) //nolint:errcheck } query := ` @@ -1937,7 +1937,7 @@ func (ds *Datastore) FailingPoliciesCount(ctx context.Context, host *fleet.Host) func (ds *Datastore) ListPoliciesForHost(ctx context.Context, host *fleet.Host) ([]*fleet.HostPolicy, error) { if host.FleetPlatform() == "" { // We log to help troubleshooting in case this happens. - level.Error(ds.logger).Log("err", fmt.Sprintf("host %d with empty platform", host.ID)) + level.Error(ds.logger).Log("err", "unrecognized platform", "hostID", host.ID, "platform", host.Platform) //nolint:errcheck } query := `SELECT p.*, COALESCE(u.name, '') AS author_name, diff --git a/server/datastore/mysql/policies.go b/server/datastore/mysql/policies.go index 97ae583a6f..a2299fa356 100644 --- a/server/datastore/mysql/policies.go +++ b/server/datastore/mysql/policies.go @@ -382,7 +382,7 @@ func (ds *Datastore) PolicyQueriesForHost(ctx context.Context, host *fleet.Host) if host.FleetPlatform() == "" { // We log to help troubleshooting in case this happens, as the host // won't be receiving any policies targeted for specific platforms. - level.Error(ds.logger).Log("err", fmt.Sprintf("host %d with empty platform", host.ID)) //nolint:errcheck + level.Error(ds.logger).Log("err", "unrecognized platform", "hostID", host.ID, "platform", host.Platform) //nolint:errcheck } q := dialect.From("policies").Select( goqu.I("id"),