mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
showing alerts created in the management page (#72031)
This commit is contained in:
parent
22365de6ed
commit
fbf54f0023
2 changed files with 48 additions and 6 deletions
|
@ -40,7 +40,43 @@ describe('getObservabilityAlerts', () => {
|
|||
expect(alerts).toEqual([]);
|
||||
});
|
||||
|
||||
it('Shows alerts from Observability', async () => {
|
||||
it('Returns empty array when alerts are not allowed based on consumer type', async () => {
|
||||
const core = ({
|
||||
http: {
|
||||
get: async () => {
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
consumer: 'siem',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
consumer: 'kibana',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
consumer: 'index',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
consumer: 'foo',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
consumer: 'bar',
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
basePath,
|
||||
},
|
||||
} as unknown) as AppMountContext['core'];
|
||||
const alerts = await getObservabilityAlerts({ core });
|
||||
expect(alerts).toEqual([]);
|
||||
});
|
||||
|
||||
it('Shows alerts from Observability and Alerts', async () => {
|
||||
const core = ({
|
||||
http: {
|
||||
get: async () => {
|
||||
|
@ -66,6 +102,10 @@ describe('getObservabilityAlerts', () => {
|
|||
id: 5,
|
||||
consumer: 'metrics',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
consumer: 'alerts',
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
|
@ -91,6 +131,10 @@ describe('getObservabilityAlerts', () => {
|
|||
id: 5,
|
||||
consumer: 'metrics',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
consumer: 'alerts',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
import { AppMountContext } from 'kibana/public';
|
||||
import { Alert } from '../../../alerts/common';
|
||||
|
||||
const allowedConsumers = ['apm', 'uptime', 'logs', 'metrics', 'alerts'];
|
||||
|
||||
export async function getObservabilityAlerts({ core }: { core: AppMountContext['core'] }) {
|
||||
try {
|
||||
const { data = [] }: { data: Alert[] } = await core.http.get(
|
||||
|
@ -19,11 +21,7 @@ export async function getObservabilityAlerts({ core }: { core: AppMountContext['
|
|||
}
|
||||
);
|
||||
|
||||
return data.filter(({ consumer }) => {
|
||||
return (
|
||||
consumer === 'apm' || consumer === 'uptime' || consumer === 'logs' || consumer === 'metrics'
|
||||
);
|
||||
});
|
||||
return data.filter(({ consumer }) => allowedConsumers.includes(consumer));
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Error while fetching alerts', e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue