type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get top locations by total traffic anomalies generated.
* Internet traffic anomalies are signals that might point to an outage,
These alerts are automatically detected by Radar and then manually verified by our team.
This endpoint returns the sum of alerts grouped by location.
*/
export async function main(
auth: Cloudflare,
limit: string | undefined,
dateRange:
| "1d"
| "2d"
| "7d"
| "14d"
| "28d"
| "12w"
| "24w"
| "52w"
| "1dControl"
| "2dControl"
| "7dControl"
| "14dControl"
| "28dControl"
| "12wControl"
| "24wControl"
| undefined,
dateStart: string | undefined,
dateEnd: string | undefined,
status: "VERIFIED" | "UNVERIFIED" | undefined,
format: "JSON" | "CSV" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/radar/traffic_anomalies/locations`
);
for (const [k, v] of [
["limit", limit],
["dateRange", dateRange],
["dateStart", dateStart],
["dateEnd", dateEnd],
["status", status],
["format", format],
]) {
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 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get top locations by total traffic anomalies generated.
* Internet traffic anomalies are signals that might point to an outage,
These alerts are automatically detected by Radar and then manually verified by our team.
This endpoint returns the sum of alerts grouped by location.
*/
export async function main(
auth: Cloudflare,
limit: string | undefined,
dateRange:
| "1d"
| "2d"
| "7d"
| "14d"
| "28d"
| "12w"
| "24w"
| "52w"
| "1dControl"
| "2dControl"
| "7dControl"
| "14dControl"
| "28dControl"
| "12wControl"
| "24wControl"
| undefined,
dateStart: string | undefined,
dateEnd: string | undefined,
status: "VERIFIED" | "UNVERIFIED" | undefined,
format: "JSON" | "CSV" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/radar/traffic_anomalies/locations`
);
for (const [k, v] of [
["limit", limit],
["dateRange", dateRange],
["dateStart", dateStart],
["dateEnd", dateEnd],
["status", status],
["format", format],
]) {
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 920 days ago