type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* List Healthcheck Events
* List origin health changes.
*/
export async function main(
auth: Cloudflare,
until: string | undefined,
pool_name: string | undefined,
origin_healthy: string | undefined,
identifier: string | undefined,
since: string | undefined,
origin_name: string | undefined,
pool_healthy: string | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/user/load_balancing_analytics/events`
);
for (const [k, v] of [
["until", until],
["pool_name", pool_name],
["origin_healthy", origin_healthy],
["identifier", identifier],
["since", since],
["origin_name", origin_name],
["pool_healthy", pool_healthy],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 402 days ago