Skip to content

Commit

Permalink
feat: adds incident.io channel
Browse files Browse the repository at this point in the history
  • Loading branch information
tnolet committed Feb 24, 2025
1 parent 18857dc commit b64d671
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
82 changes: 82 additions & 0 deletions packages/cli/src/constructs/incidentio-alert-channel.ts
Original file line number Diff line number Diff line change
@@ -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,
},
}
}
}
1 change: 1 addition & 0 deletions packages/cli/src/constructs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit b64d671

Please sign in to comment.