//native
type Digitalocean = {
token: string;
};
/**
* Create a New Alert
* To create an Uptime alert, send a POST request to `/v2/uptime/checks/$CHECK_ID/alerts` specifying the attributes
in the table below in the JSON body.
*/
export async function main(
auth: Digitalocean,
check_id: string,
body: { id?: string } & {
name?: string;
type?: "latency" | "down" | "down_global" | "ssl_expiry";
threshold?: number;
comparison?: "greater_than" | "less_than";
notifications?: {
email: string[];
slack: { channel: string; url: string }[];
};
period?: "2m" | "3m" | "5m" | "10m" | "15m" | "30m" | "1h";
},
) {
const url = new URL(
`https://api.digitalocean.com/v2/uptime/checks/${check_id}/alerts`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago