[Fleet] Fix fleet server collector in case settings are not set (#101752)

This commit is contained in:
Nicolas Chaulet 2021-06-10 16:32:23 -04:00 committed by GitHub
parent e55a93ce58
commit 6df58dd7ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}
throw err;
});
// Find all policies with Fleet server than query agent status
let hasMore = true;
const policyIds = new Set<string>();
let page = 1;