-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert.ts
35 lines (31 loc) · 908 Bytes
/
alert.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { type Alert } from "@/types/alert";
import { retryRequest } from "@utils/axios";
export default async function alert(alert: Alert): Promise<void> {
// add your custom alert code here!
basicAlert(alert);
// or
// await pagerDutyAlert
}
function basicAlert(alert: Alert): void {
console.log(alert);
}
export async function pagerDutyAlert(alert: Alert): Promise<void> {
const data = {
routing_key: "yourPagerDutyKeyHere",
payload: {
summary: `Whistleblower ${alert.type} alert`,
severity: "error",
source: "Whistleblower ",
component: undefined,
custom_details: {
...alert,
},
},
event_action: "trigger",
};
await retryRequest("https://events.pagerduty.com/v2/enqueue", {
data,
method: "post",
headers: { "content-type": "application/json" },
}).catch((e) => console.error("Error posting alert to PD", e));
}