diff --git a/x-pack/plugins/fleet/server/collectors/fleet_server_collector.ts b/x-pack/plugins/fleet/server/collectors/fleet_server_collector.ts index d861b211b8848..9616ba11545e0 100644 --- a/x-pack/plugins/fleet/server/collectors/fleet_server_collector.ts +++ b/x-pack/plugins/fleet/server/collectors/fleet_server_collector.ts @@ -4,6 +4,8 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ + +import { isBoom } from '@hapi/boom'; import type { SavedObjectsClient, ElasticsearchClient } from 'kibana/server'; import { packagePolicyService, settingsService } from '../services'; @@ -38,11 +40,18 @@ export const getFleetServerUsage = async ( return DEFAULT_USAGE; } - const numHostsUrls = - (await settingsService.getSettings(soClient)).fleet_server_hosts?.length ?? 0; + const numHostsUrls = await settingsService + .getSettings(soClient) + .then((settings) => settings.fleet_server_hosts?.length ?? 0) + .catch((err) => { + if (isBoom(error) && error.output.statusCode === 404) { + return 0; + } - // Find all policies with Fleet server than query agent status + throw err; + }); + // Find all policies with Fleet server than query agent status let hasMore = true; const policyIds = new Set(); let page = 1;