kibana/x-pack/plugins/osquery/public/agent_policies/use_agent_policies.ts
Bryan Clement b94f712f8c
[Asset management] Text updates (#98192)
* updated scheduled query activation toggle text and interval header in query group

* added id validation for schedule queries

* fixed up agent resolution to ignore inactive agents, and properly pull all agents

* nixed unused file

* more validation for query fields

* added status table to the results data tab, added more validation

* updated wording

* added error notifications for failed queries

* pr feedback and cleanup

* fix up last hook

* use the pluralize macro, removed rbac tags

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-04-28 22:54:09 -04:00

45 lines
1.3 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { useQuery } from 'react-query';
import { i18n } from '@kbn/i18n';
import { useKibana } from '../common/lib/kibana';
import {
agentPolicyRouteService,
GetAgentPoliciesResponse,
GetAgentPoliciesResponseItem,
} from '../../../fleet/common';
export const useAgentPolicies = () => {
const {
http,
notifications: { toasts },
} = useKibana().services;
return useQuery<GetAgentPoliciesResponse, unknown, GetAgentPoliciesResponseItem[]>(
['agentPolicies'],
() =>
http.get(agentPolicyRouteService.getListPath(), {
query: {
perPage: 100,
},
}),
{
initialData: { items: [], total: 0, page: 1, perPage: 100 },
placeholderData: [],
keepPreviousData: true,
select: (response) => response.items,
onError: (error) =>
toasts.addError(error as Error, {
title: i18n.translate('xpack.osquery.agent_policies.fetchError', {
defaultMessage: 'Error while fetching agent policies',
}),
}),
}
);
};