Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Loading