From b64d67179ee4281ad19b9e24c4d48248fd6f6ebe Mon Sep 17 00:00:00 2001 From: tnolet Date: Mon, 24 Feb 2025 15:46:29 +0100 Subject: [PATCH] feat: adds incident.io channel --- .../constructs/incidentio-alert-channel.ts | 82 +++++++++++++++++++ packages/cli/src/constructs/index.ts | 1 + 2 files changed, 83 insertions(+) create mode 100644 packages/cli/src/constructs/incidentio-alert-channel.ts diff --git a/packages/cli/src/constructs/incidentio-alert-channel.ts b/packages/cli/src/constructs/incidentio-alert-channel.ts new file mode 100644 index 00000000..da6a47c5 --- /dev/null +++ b/packages/cli/src/constructs/incidentio-alert-channel.ts @@ -0,0 +1,82 @@ +import { WebhookAlertChannel } from './webhook-alert-channel' +import { AlertChannelProps } from './alert-channel' + +export interface IncidentioAlertChannelProps extends AlertChannelProps { + /** + * Friendly name to recognise the integration. + */ + name: string + /** + * The unique URL created by installing the Checkly integration in Incident.io. + * {@link https://www.checklyhq.com/docs/integrations/incidentio/} + */ + url: URL|string + /** + * The API key created by installing the Checkly integration in Incident.io. + * {@link {@link https://www.checklyhq.com/docs/integrations/incidentio/}} + */ + apiKey: string +} + +/** + * Creates an Incident.io Alert Channel + * + * @remarks + * + * This class make use of the Alert Channel endpoints. + */ +export class IncidentioAlertChannel extends WebhookAlertChannel { + /** + * Constructs the Incident.io Alert Channel instance + * + * @param logicalId unique project-scoped resource name identification + * @param props Incident.io alert channel configuration properties + * + * {@link https://checklyhq.com/docs/cli/constructs-reference/#incidentioalertchannel Read more in the docs} + */ + constructor (logicalId: string, props: IncidentioAlertChannelProps) { + super(logicalId, props) + this.webhookType = 'WEBHOOK_INCIDENTIO' + this.method = 'POST' + this.headers = [ + { + key: 'authorization', + value: `Bearer ${props.apiKey}`, + locked: false, + }, + ] + this.template = `{ + "title": "{{ALERT_TITLE}}", + "description": "{{ALERT_TITLE}} at {{STARTED_AT}} in {{RUN_LOCATION}} {{RESPONSE_TIME}}ms", + "deduplication_key": "{{CHECK_ID}}", + "metadata": { + "alertType": "{{ALERT_TYPE}}", + "check_result_id": "{{CHECK_RESULT_ID}}", + "resultLink": "{{RESULT_LINK}}" + }, + {{#contains ALERT_TYPE "RECOVERY"}} + "status": "resolved" + {{else}} + "status": "firing" + {{/contains}} +} +` + } + + synthesize () { + return { + ...super.synthesize(), + type: 'WEBHOOK', + config: { + name: this.name, + webhookType: this.webhookType, + url: this.url, + template: this.template, + method: this.method, + headers: this.headers, + queryParameters: this.queryParameters, + webhookSecret: this.webhookSecret, + }, + } + } +} diff --git a/packages/cli/src/constructs/index.ts b/packages/cli/src/constructs/index.ts index dd91eb10..b9329b7c 100644 --- a/packages/cli/src/constructs/index.ts +++ b/packages/cli/src/constructs/index.ts @@ -26,3 +26,4 @@ export * from './retry-strategy' export * from './multi-step-check' export * from './alert-escalation-policy' export * from './tcp-check' +export * from './incidentio-alert-channel'