-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into custom_highlighted_fields
- Loading branch information
Showing
10 changed files
with
1,593 additions
and
12 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
239 changes: 239 additions & 0 deletions
239
...est_serverless/api_integration/test_suites/common/alerting/helpers/alerting_api_helper.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,239 @@ | ||
/* | ||
* 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 type { SuperTest, Test } from 'supertest'; | ||
|
||
interface CreateEsQueryRuleParams { | ||
size: number; | ||
thresholdComparator: string; | ||
threshold: number[]; | ||
timeWindowSize?: number; | ||
timeWindowUnit?: string; | ||
esQuery?: string; | ||
timeField?: string; | ||
searchConfiguration?: unknown; | ||
indexName?: string; | ||
excludeHitsFromPreviousRun?: boolean; | ||
aggType?: string; | ||
aggField?: string; | ||
groupBy?: string; | ||
termField?: string; | ||
termSize?: number; | ||
index?: string[]; | ||
} | ||
|
||
export async function createIndexConnector({ | ||
supertest, | ||
name, | ||
indexName, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
name: string; | ||
indexName: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/actions/connector`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo') | ||
.send({ | ||
name, | ||
config: { | ||
index: indexName, | ||
refresh: true, | ||
}, | ||
connector_type_id: '.index', | ||
}); | ||
return body.id as string; | ||
} | ||
|
||
export async function createSlackConnector({ | ||
supertest, | ||
name, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
name: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/actions/connector`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo') | ||
.send({ | ||
name, | ||
config: {}, | ||
secrets: { | ||
webhookUrl: 'http://test', | ||
}, | ||
connector_type_id: '.slack', | ||
}); | ||
return body.id as string; | ||
} | ||
|
||
export async function createEsQueryRule({ | ||
supertest, | ||
name, | ||
ruleTypeId, | ||
params, | ||
actions = [], | ||
tags = [], | ||
schedule, | ||
consumer, | ||
notifyWhen, | ||
enabled = true, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
ruleTypeId: string; | ||
name: string; | ||
params: CreateEsQueryRuleParams; | ||
consumer: string; | ||
actions?: any[]; | ||
tags?: any[]; | ||
schedule?: { interval: string }; | ||
notifyWhen?: string; | ||
enabled?: boolean; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/alerting/rule`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo') | ||
.send({ | ||
enabled, | ||
params, | ||
consumer, | ||
schedule: schedule || { | ||
interval: '1h', | ||
}, | ||
tags, | ||
name, | ||
rule_type_id: ruleTypeId, | ||
actions, | ||
...(notifyWhen ? { notify_when: notifyWhen, throttle: '1m' } : {}), | ||
}); | ||
return body; | ||
} | ||
|
||
export async function disableRule({ | ||
supertest, | ||
ruleId, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
ruleId: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/alerting/rule/${ruleId}/_disable`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo'); | ||
return body; | ||
} | ||
|
||
export async function updateEsQueryRule({ | ||
supertest, | ||
ruleId, | ||
updates, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
ruleId: string; | ||
updates: any; | ||
}) { | ||
const { body: r } = await supertest | ||
.get(`/api/alerting/rule/${ruleId}`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo'); | ||
const body = await supertest | ||
.put(`/api/alerting/rule/${ruleId}`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo') | ||
.send({ | ||
...{ | ||
name: r.name, | ||
schedule: r.schedule, | ||
throttle: r.throttle, | ||
tags: r.tags, | ||
params: r.params, | ||
notify_when: r.notifyWhen, | ||
actions: r.actions.map((action: any) => ({ | ||
group: action.group, | ||
params: action.params, | ||
id: action.id, | ||
frequency: action.frequency, | ||
})), | ||
}, | ||
...updates, | ||
}); | ||
return body; | ||
} | ||
|
||
export async function runRule({ | ||
supertest, | ||
ruleId, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
ruleId: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/internal/alerting/rule/${ruleId}/_run_soon`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo'); | ||
return body; | ||
} | ||
|
||
export async function muteRule({ | ||
supertest, | ||
ruleId, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
ruleId: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/alerting/rule/${ruleId}/_mute_all`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo'); | ||
return body; | ||
} | ||
|
||
export async function enableRule({ | ||
supertest, | ||
ruleId, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
ruleId: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/alerting/rule/${ruleId}/_enable`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo'); | ||
return body; | ||
} | ||
|
||
export async function muteAlert({ | ||
supertest, | ||
ruleId, | ||
alertId, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
ruleId: string; | ||
alertId: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/alerting/rule/${ruleId}/alert/${alertId}/_mute`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo'); | ||
return body; | ||
} | ||
|
||
export async function unmuteRule({ | ||
supertest, | ||
ruleId, | ||
}: { | ||
supertest: SuperTest<Test>; | ||
ruleId: string; | ||
}) { | ||
const { body } = await supertest | ||
.post(`/api/alerting/rule/${ruleId}/_unmute_all`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo'); | ||
return body; | ||
} |
Oops, something went wrong.