From f14ab358fe5a5adc5b24f3a980a2df251ffa7bc2 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 1 Dec 2023 17:59:41 -0600 Subject: [PATCH] 2023-11-21 Website: Add new usage statistics (#15263) Closes: #15255 Changes: - Added the usage statistics added in https://github.com/fleetdm/fleet/pull/14216 to the inputs of the `receive-usage-analytics` webhook. - Updated the `receive-usage-analytics` webhook to send the new usage statistics to Datadog. - Added attributes for the new usage statistics to the `HistoricalUsageSnapshot` model. - Removed the `columnName` from the `hostsStatusWebHookEnabled` attribute of the `HistoricalUsageSnapshot` model, the name of this column will be changed in the database when the new columns are added to the databse table. - Updated the usage statistics documentation to have the new statistics. This PR requires database migrations. When this is approved and ready to merge, we will need to: - [ ] Merge this PR - [ ] Put fleetdm.com into maintenance mode while the "Deploy Fleet website" GH action runs. - [ ] Add the new columns to the database table - [ ] Change the name of the `hostStatusWebhookEnabled` column to `hostsStatusWebHookEnabled` - [ ] Set the default values for the new columns on the existing records. - [ ] When the website has finished redeploying, take it out of maintenance mode. --- docs/Using Fleet/Usage-statistics.md | 4 ++++ .../api/controllers/webhooks/receive-usage-analytics.js | 8 ++++++++ website/api/models/HistoricalUsageSnapshot.js | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/Using Fleet/Usage-statistics.md b/docs/Using Fleet/Usage-statistics.md index 1f34ce9074..0e6628601d 100644 --- a/docs/Using Fleet/Usage-statistics.md +++ b/docs/Using Fleet/Usage-statistics.md @@ -21,6 +21,10 @@ Below is the JSON payload that is sent to Fleet Device Management Inc: "vulnDetectionEnabled": true, "systemUsersEnabled": true, "hostsStatusWebHookEnabled": true, + "mdmMacOsEnabled": true, + "hostExpiryEnabled": true, + "mdmWindowsEnabled": false, + "liveQueryDisabled": false, "numWeeklyActiveUsers": 999, "numWeeklyPolicyViolationDaysActual": 999, "numWeeklyPolicyViolationDaysPossible": 999, diff --git a/website/api/controllers/webhooks/receive-usage-analytics.js b/website/api/controllers/webhooks/receive-usage-analytics.js index 699baa2f8c..eaada1fd8e 100644 --- a/website/api/controllers/webhooks/receive-usage-analytics.js +++ b/website/api/controllers/webhooks/receive-usage-analytics.js @@ -29,6 +29,10 @@ module.exports = { storedErrors: { type: [{}], defaultsTo: [] }, // TODO migrate all rows that have "[]" to {} numHostsNotResponding: { type: 'number', defaultsTo: 0, description: 'The number of hosts per deployment that have not submitted results for distibuted queries. A host is counted as not responding if Fleet hasn\'t received a distributed write to requested distibuted queries for the host during the 2-hour interval since the host was last seen. Hosts that have not been seen for 7 days or more are not counted.', }, organization: { type: 'string', defaultsTo: 'unknown', description: 'For Fleet Premium deployments, the organization registered with the license.', }, + mdmMacOsEnabled: {type: 'boolean', defaultsTo: false}, + mdmWindowsEnabled: {type: 'boolean', defaultsTo: false}, + liveQueryDisabled: {type: 'boolean', defaultsTo: false}, + hostExpiryEnabled: {type: 'boolean', defaultsTo: false}, }, @@ -54,6 +58,10 @@ module.exports = { `vuln_detection_enabled:${inputs.vulnDetectionEnabled}`, `system_users_enabled:${inputs.systemUsersEnabled}`, `host_status_webhook_enabled:${inputs.hostsStatusWebHookEnabled}`, + `mdm_macos_enabled:${inputs.mdmMacOsEnabled}`, + `mdm_windows_enabled:${inputs.mdmWindowsEnabled}`, + `live_query_disabled:${inputs.liveQueryDisabled}`, + `host_expiry_enabled:${inputs.hostExpiryEnabled}`, ]; // Create a timestamp in seconds for these metrics diff --git a/website/api/models/HistoricalUsageSnapshot.js b/website/api/models/HistoricalUsageSnapshot.js index d101b66150..2263304c0b 100644 --- a/website/api/models/HistoricalUsageSnapshot.js +++ b/website/api/models/HistoricalUsageSnapshot.js @@ -23,7 +23,7 @@ module.exports = { softwareInventoryEnabled: { required: true, type: 'boolean' }, vulnDetectionEnabled: { required: true, type: 'boolean' }, systemUsersEnabled: { required: true, type: 'boolean' }, - hostsStatusWebHookEnabled: { required: true, type: 'boolean', columnName: 'hostStatusWebhookEnabled'},// Note: We are specifying a columnName for this attribute to avoid migrating the exsiting records when the name of this attribute was changed. FUTURE: Next time we add attributes to this model, change the column name in the database and remove the columnName from this attribute. + hostsStatusWebHookEnabled: { required: true, type: 'boolean'}, numWeeklyActiveUsers: { required: true, type: 'number' }, numWeeklyPolicyViolationDaysActual: { required: true, type: 'number' }, numWeeklyPolicyViolationDaysPossible: { required: true, type: 'number'}, @@ -33,6 +33,10 @@ module.exports = { storedErrors: { required: true, type: 'json' }, numHostsNotResponding: { required: true, type: 'number', description: 'The number of hosts per deployment that have not submitted results for distibuted queries. A host is counted as not responding if Fleet hasn\'t received a distributed write to requested distibuted queries for the host during the 2-hour interval since the host was last seen. Hosts that have not been seen for 7 days or more are not counted.', }, organization: { required: true, type: 'string' }, + mdmMacOsEnabled: {required: true, type: 'boolean'}, + mdmWindowsEnabled: {required: true, type: 'boolean'}, + liveQueryDisabled: {required: true, type: 'boolean'}, + hostExpiryEnabled: {required: true, type: 'boolean'}, // ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗ // ║╣ ║║║╠╩╗║╣ ║║╚═╗