Skip to content

Commit

Permalink
[Fleet] Fix fleet server collector in case settings are not set (#101752
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nchaulet authored Jun 10, 2021
1 parent e55a93c commit 6df58dd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions x-pack/plugins/fleet/server/collectors/fleet_server_collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string>();
let page = 1;
Expand Down

0 comments on commit 6df58dd

Please sign in to comment.