From 33b206ffd391fbbad2027892b881e2d125902d49 Mon Sep 17 00:00:00 2001 From: Dan Philibin Date: Wed, 18 Sep 2024 01:05:47 +0000 Subject: [PATCH] add axiom example --- examples/axiom-webhook/README.md | 11 ++++++ .../axiom-webhook/axiom-integration-icon.png | Bin 0 -> 3233 bytes examples/axiom-webhook/package.json | 17 ++++++++ examples/axiom-webhook/src/index.ts | 37 ++++++++++++++++++ examples/axiom-webhook/tsconfig.json | 3 ++ 5 files changed, 68 insertions(+) create mode 100644 examples/axiom-webhook/README.md create mode 100644 examples/axiom-webhook/axiom-integration-icon.png create mode 100644 examples/axiom-webhook/package.json create mode 100644 examples/axiom-webhook/src/index.ts create mode 100644 examples/axiom-webhook/tsconfig.json diff --git a/examples/axiom-webhook/README.md b/examples/axiom-webhook/README.md new file mode 100644 index 0000000..2da53e3 --- /dev/null +++ b/examples/axiom-webhook/README.md @@ -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. diff --git a/examples/axiom-webhook/axiom-integration-icon.png b/examples/axiom-webhook/axiom-integration-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..5374fb35a30f31a6aa815c113f5cf78ca5366db9 GIT binary patch literal 3233 zcmdT{_g_=V7Qdkv6Hq|bpdccOlogR8i*%$(kqFWj6BH>50#cNgAXQO_N)!P@s0u7A zAW8`(AWKk$N9cqAK_b#Z$3&i&4JzIV=?Gjktaa2u>juw>+m9I2nCos zngc*BR+8&03;_G|?X1jQ??G0kTCd32$&*>XF@&DjS*ztL`}vvqi{<7@!y)cRQ>9*O-&Gaa?w|7ZT~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(+VR&!r1zT z1`Rhucj6X@XTKk6{%1!$+~|IB@a6!yKP#=!4}^dT<|rTc)!JJAs=v&E~k@`J1)1yM8@qrK+9%pD(X2H8nw{3UiU07fu2+{ za=IqF=8G*fdREQZas-t6QPTZako93FjAZiB>Er4#uy4WWcOJJJ_bC-Ia;eJxqkOna zttDYm9gz%;s(DUfD;yk2L)~8!2U(cwTxtN0E~8eZeGwX6MPY9ofhYY6ay%^ocejk? zVt{c_pcoPSIvbb~_omg4p=+t!0+1I0mML&!jDj4cH3R8a#?KwURVu6ua2)j5THPa-`AIzOwCiLt|?2;Tp-b%?ZK1YlKE}^V4>jH z*qHeGUrt;ek5_8_4k&l?#PvI&yBLV*Bki9*i#rR_EAF@xo>fy=WP3d-kml25LU@_ zur8qgnP~I}q_;PRkx`X3IA5Hj7 zl|H<)aY=vlS-tL~LJGFQ9=hG}jXljR6;1owJzPaSvfsL*BTJT+>o(V3s9at&^Ai$X z8X0o~zx^M_a0u;DkO1smT49L7_U7WyaJ`EHrjsJQS^XE8ezYP(?5lAt3TKW7l_-yo-goI~fL+}GEiMz0j8}6+deY8o!=$7%z6Fp(ox8&xfk3OEcgo|g zj8KpBZPSMxORM$dX+npGT`eha%r?ASZ)M`z-fA_H^cpPbDd($L@ItMkET1(vF@FZ5m zH+%P-!D4g0LaEO99?FB%{^j1H==;u$KXT~dufa+-FxlWt>W;IZtvqND$@guQuF%YFa= literal 0 HcmV?d00001 diff --git a/examples/axiom-webhook/package.json b/examples/axiom-webhook/package.json new file mode 100644 index 0000000..659c4dc --- /dev/null +++ b/examples/axiom-webhook/package.json @@ -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" + } +} diff --git a/examples/axiom-webhook/src/index.ts b/examples/axiom-webhook/src/index.ts new file mode 100644 index 0000000..2e858a1 --- /dev/null +++ b/examples/axiom-webhook/src/index.ts @@ -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 { + 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 }) + } +} diff --git a/examples/axiom-webhook/tsconfig.json b/examples/axiom-webhook/tsconfig.json new file mode 100644 index 0000000..4082f16 --- /dev/null +++ b/examples/axiom-webhook/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.json" +}