Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add webhook secret support for webhook alert channels [sc-22462] #985

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
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@ export const webhookChannel = new WebhookAlertChannel('webhook-channel-1', {
}`,
...sendDefaults,
})

export const webhookChannelWithSecret = new WebhookAlertChannel('webhook-channel-with-secret', {
name: 'Pushover webhook w/ secret',
method: 'POST',
url: new URL('https://webhook.site/ddead495-8b15-4b0d-a25d-f6cda4144dc7'),
template: `{
"token":"FILL_IN_YOUR_SECRET_TOKEN_FROM_PUSHOVER",
"user":"FILL_IN_YOUR_USER_FROM_PUSHOVER",
"title":"{{ALERT_TITLE}}",
"html":1,
"priority":2,
"retry":30,
"expire":10800,
"message":"{{ALERT_TYPE}} {{STARTED_AT}} ({{RESPONSE_TIME}}ms) {{RESULT_LINK}}"
}`,
webhookSecret: 'hunter2',
...sendDefaults,
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { ApiCheck, AssertionBuilder } from 'checkly/constructs'
import { slackChannel, webhookChannel } from '../../alert-channels'
import { slackChannel, webhookChannel, webhookChannelWithSecret } from '../../alert-channels'

const apiCheck = new ApiCheck('homepage-api-check-1', {

Check warning on line 4 in packages/cli/e2e/__tests__/fixtures/test-project/src/services/api/api.check.ts

View workflow job for this annotation

GitHub Actions / lint

'apiCheck' is assigned a value but never used
name: 'Runtimes',
alertChannels: [slackChannel, webhookChannel],
alertChannels: [
slackChannel,
webhookChannel,
webhookChannelWithSecret,
],
degradedResponseTime: 10000,
maxResponseTime: 20000,
request: {
Expand All @@ -18,7 +22,7 @@
},
})

const skipSslApiCheck = new ApiCheck('ssl-api-check-1', {

Check warning on line 25 in packages/cli/e2e/__tests__/fixtures/test-project/src/services/api/api.check.ts

View workflow job for this annotation

GitHub Actions / lint

'skipSslApiCheck' is assigned a value but never used
name: 'Skip SSL Check',
alertChannels: [slackChannel, webhookChannel],
degradedResponseTime: 10000,
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/constructs/webhook-alert-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export interface WebhookAlertChannelProps extends AlertChannelProps {
* Key-value elements array with the query parameters to include in the URL for the webhook HTTP request.
*/
queryParameters?: Array<QueryParam>
/**
* An optional value to use as the
* {@link https://www.checklyhq.com/docs/alerting-and-retries/webhooks/#webhook-secrets secret for the webhook}.
*
* You may specify any value that meets your security criteria.
*/
webhookSecret?: string
}

/**
Expand All @@ -49,6 +56,7 @@ export class WebhookAlertChannel extends AlertChannel {
method?: HttpRequestMethod
headers?: Array<HttpHeader>
queryParameters?: Array<QueryParam>
webhookSecret?: string
/**
* Constructs the Webhook Alert Channel instance
*
Expand All @@ -66,6 +74,7 @@ export class WebhookAlertChannel extends AlertChannel {
this.method = props.method
this.headers = props.headers
this.queryParameters = props.queryParameters
this.webhookSecret = props.webhookSecret
Session.registerConstruct(this)
}

Expand All @@ -81,6 +90,7 @@ export class WebhookAlertChannel extends AlertChannel {
method: this.method,
headers: this.headers,
queryParameters: this.queryParameters,
webhookSecret: this.webhookSecret,
},
}
}
Expand Down
Loading