-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec329f2
commit 33b206f
Showing
5 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Axiom Webhook | ||
|
||
This example creates a webhook handler for [Axiom](https://axiom.co) that sends a new chat message when a [monitor](https://axiom.co/docs/monitor-data/monitors#custom-webhook) is triggered or resolved. | ||
|
||
_This code is provided as an example and is not intended to be deployed as-is. Adapt the code in `src/index.ts` to fit your use case and deployment environment._ | ||
|
||
### Prerequisites | ||
|
||
A `CAMPSITE_API_KEY` environment variable is required. | ||
|
||
Additionally, [follow these steps](https://axiom.co/docs/monitor-data/monitors#custom-webhook) to create a custom webhook notifier in Axiom. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,17 @@ | ||
{ | ||
"name": "axiom-webhook", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"clean": "rm -rf .turbo node_modules", | ||
"format": "prettier --write \"**/*.{ts,md,yml,json}\"" | ||
}, | ||
"dependencies": { | ||
"dotenv": "^16.4.5" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.16.5", | ||
"ts-node": "^10.9.2", | ||
"ts-node-dev": "^2.0.0", | ||
"typescript": "^5.5.4" | ||
} | ||
} |
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,37 @@ | ||
const CAMPSITE_API_KEY = process.env.CAMPSITE_API_KEY | ||
const CAMPSITE_ALERTS_THREAD_ID = 'sdcup465jb7y' | ||
|
||
export default async function server(request: Request): Promise<Response> { | ||
if (request.method !== 'POST') { | ||
return new Response('Method not allowed', { status: 405 }) | ||
} | ||
|
||
const payload = await request.json() | ||
|
||
// Modify this to suit your needs, e.g. for threshold alerts vs. match alerts | ||
const status = payload.action === 'Open' ? '🔴 Monitor triggered' : '🟢 Monitor resolved' | ||
|
||
const message = `**${status}: ${payload.event.title}**\n${payload.event.body}` | ||
|
||
try { | ||
const campsiteResponse = await fetch(`https://api.campsite.com/v2/threads/${CAMPSITE_ALERTS_THREAD_ID}/messages`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${CAMPSITE_API_KEY}` | ||
}, | ||
body: JSON.stringify({ | ||
content_markdown: message | ||
}) | ||
}) | ||
|
||
if (!campsiteResponse.ok) { | ||
throw new Error(`Campsite API error: ${campsiteResponse.statusText}`) | ||
} | ||
|
||
return new Response('OK', { status: 200 }) | ||
} catch (error) { | ||
console.error('Error posting to Campsite:', error) | ||
return new Response('Error posting to Campsite', { status: 500 }) | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"extends": "../../tsconfig.json" | ||
} |