Get Layer 7 Attacks By Target Industries Time Series

Percentage distribution of attacks by industry used over time.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get Layer 7 Attacks By Target Industries Time Series
8
 * Percentage distribution of attacks by industry used over time.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  aggInterval: "15m" | "1h" | "1d" | "1w" | undefined,
13
  name: string | undefined,
14
  dateRange: string | undefined,
15
  dateStart: string | undefined,
16
  dateEnd: string | undefined,
17
  asn: string | undefined,
18
  location: string | undefined,
19
  ipVersion: string | undefined,
20
  httpVersion: string | undefined,
21
  httpMethod: string | undefined,
22
  mitigationProduct: string | undefined,
23
  normalization: "PERCENTAGE" | "MIN0_MAX" | undefined,
24
  limitPerGroup: string | undefined,
25
  format: "JSON" | "CSV" | undefined
26
) {
27
  const url = new URL(
28
    `https://api.cloudflare.com/client/v4/radar/attacks/layer7/timeseries_groups/industry`
29
  );
30
  for (const [k, v] of [
31
    ["aggInterval", aggInterval],
32
    ["name", name],
33
    ["dateRange", dateRange],
34
    ["dateStart", dateStart],
35
    ["dateEnd", dateEnd],
36
    ["asn", asn],
37
    ["location", location],
38
    ["ipVersion", ipVersion],
39
    ["httpVersion", httpVersion],
40
    ["httpMethod", httpMethod],
41
    ["mitigationProduct", mitigationProduct],
42
    ["normalization", normalization],
43
    ["limitPerGroup", limitPerGroup],
44
    ["format", format],
45
  ]) {
46
    if (v !== undefined && v !== "") {
47
      url.searchParams.append(k, v);
48
    }
49
  }
50
  const response = await fetch(url, {
51
    method: "GET",
52
    headers: {
53
      "X-AUTH-EMAIL": auth.email,
54
      "X-AUTH-KEY": auth.key,
55
      Authorization: "Bearer " + auth.token,
56
    },
57
    body: undefined,
58
  });
59
  if (!response.ok) {
60
    const text = await response.text();
61
    throw new Error(`${response.status} ${text}`);
62
  }
63
  return await response.json();
64
}
65