type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get details and aggregate metrics for an http test
* Get test details and aggregate performance metrics for an http test for a given time period between 1 hour and 7 days.
*/
export async function main(
auth: Cloudflare,
account_identifier: string,
test_id: string,
deviceId: string | undefined,
timeStart: string | undefined,
timeEnd: string | undefined,
interval: "minute" | "hour" | undefined,
colo: string | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dex/http-tests/${test_id}`
);
for (const [k, v] of [
["deviceId", deviceId],
["timeStart", timeStart],
["timeEnd", timeEnd],
["interval", interval],
["colo", colo],
]) {
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 329 days ago