forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INFRA] Add alerts count to hosts data (elastic#176034)
Closes elastic#175567 #### What has been done - create alerts infra client to retrieve alerts data - add endpoint to get the alerts count for hosts - merged alerts count with hosts data - add alertsCount badge to hosts table - sort by alert count by clicking on the column title - If no hosts have active alerts, the column should be hidden. - Default hosts sorting is alerts count and cpu desc https://github.com/elastic/kibana/assets/31922082/96794041-d129-49e2-920c-80b45c624144
- Loading branch information
1 parent
930b012
commit f76e7ec
Showing
17 changed files
with
351 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/infra/server/routes/infra/lib/helpers/get_infra_alerts_client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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 { isEmpty } from 'lodash'; | ||
import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; | ||
import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common'; | ||
import { KibanaRequest } from '@kbn/core/server'; | ||
import type { InfraPluginStartServicesAccessor } from '../../../../types'; | ||
|
||
type RequiredParams = ESSearchRequest & { | ||
size: number; | ||
track_total_hits: boolean | number; | ||
}; | ||
|
||
export type InfraAlertsClient = Awaited<ReturnType<typeof getInfraAlertsClient>>; | ||
|
||
export async function getInfraAlertsClient({ | ||
getStartServices, | ||
request, | ||
}: { | ||
getStartServices: InfraPluginStartServicesAccessor; | ||
request: KibanaRequest; | ||
}) { | ||
const [, { ruleRegistry }] = await getStartServices(); | ||
const alertsClient = await ruleRegistry.getRacClientWithRequest(request); | ||
const infraAlertsIndices = await alertsClient.getAuthorizedAlertsIndices(['infrastructure']); | ||
|
||
if (!infraAlertsIndices || isEmpty(infraAlertsIndices)) { | ||
throw Error('No alert indices exist for "infrastrucuture"'); | ||
} | ||
|
||
return { | ||
search<TParams extends RequiredParams>( | ||
searchParams: TParams | ||
): Promise<InferSearchResponseOf<ParsedTechnicalFields, TParams>> { | ||
return alertsClient.find({ | ||
...searchParams, | ||
index: infraAlertsIndices.join(','), | ||
}) as Promise<any>; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.