0

Get KPIs

by
Published today

Get a site KPI: latency, throughput or top devices.

Script ericsson_ep5g Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 hours ago
1
//native
2

3
/**
4
 * Get KPIs
5
 * Get a site KPI: latency (per-watchdog latency data points, optionally for one watchdog IMSI), throughput (average uplink and downlink in Mbit) or topdevices (top data-consuming devices). The watchdog IMSI only applies to latency.
6
 */
7
export async function main(
8
  auth: RT.EricssonEp5g,
9
  kpi: "latency" | "throughput" | "topdevices",
10
  watchdog_imsi: string | undefined
11
) {
12
  const base = auth.base_url.replace(/\/+$/, "")
13
  const url = new URL(
14
    `${base}/v2/organization/${encodeURIComponent(auth.organization)}/site/${encodeURIComponent(auth.site)}/kpi/${kpi}`
15
  )
16
  if (kpi === "latency" && watchdog_imsi != null && watchdog_imsi !== "") {
17
    url.searchParams.append("imsi", watchdog_imsi)
18
  }
19

20
  const response = await fetch(url, {
21
    headers: {
22
      "X-Api-Key": auth.api_key,
23
      ...(auth.user_role ? { "X-User-Role": auth.user_role } : {}),
24
      Accept: "application/json",
25
    },
26
  })
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  return await response.json()
33
}
34