//native
/**
* Trigger Event (Events API v2)
* Trigger an alert/incident on the routing key's service via the Events API v2. summary, source and severity are required. Pass a stable dedup_key to deduplicate and to later acknowledge or resolve this alert; if omitted, PagerDuty generates one and returns it.
*/
export async function main(
auth: RT.PagerdutyEvents,
summary: string,
source: string,
severity: "critical" | "error" | "warning" | "info",
dedup_key: string | undefined,
component: string | undefined,
group: string | undefined,
event_class: string | undefined,
custom_details: { [key: string]: any } | undefined,
client: string | undefined,
client_url: string | undefined,
) {
const payload: { [key: string]: any } = { summary, source, severity }
if (component !== undefined && component !== "") payload.component = component
if (group !== undefined && group !== "") payload.group = group
if (event_class !== undefined && event_class !== "")
payload.class = event_class
if (custom_details !== undefined) payload.custom_details = custom_details
const event: { [key: string]: any } = {
routing_key: auth.routing_key,
event_action: "trigger",
payload,
}
if (dedup_key !== undefined && dedup_key !== "") event.dedup_key = dedup_key
if (client !== undefined && client !== "") event.client = client
if (client_url !== undefined && client_url !== "") event.client_url = client_url
const response = await fetch("https://events.pagerduty.com/v2/enqueue", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(event),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 days ago