0

List devices

by
Published today

List the devices monitored by SecureTrack, optionally filtered by name, vendor, model or IP.

Script tufin_securetrack Verified

The script

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

3
/**
4
 * List devices
5
 * List the devices (firewalls, routers, management servers) monitored by SecureTrack, optionally filtered by name, vendor, model or IP.
6
 */
7
export async function main(
8
  auth: RT.TufinSecuretrack,
9
  name: string | undefined,
10
  vendor: string | undefined,
11
  model: string | undefined,
12
  ip: string | undefined,
13
  show_os_version: boolean | undefined,
14
  show_license: boolean | undefined
15
) {
16
  const base = auth.base_url.replace(/\/+$/, "")
17
  const url = new URL(`${base}/securetrack/api/devices`)
18
  for (const [key, value] of Object.entries({ name, vendor, model, ip })) {
19
    if (value != null && value !== "") {
20
      url.searchParams.append(key, value)
21
    }
22
  }
23
  if (show_os_version) url.searchParams.append("show_os_version", "true")
24
  if (show_license) url.searchParams.append("show_license", "true")
25

26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
30
      Accept: "application/json",
31
    },
32
  })
33

34
  if (!response.ok) {
35
    throw new Error(`${response.status} ${await response.text()}`)
36
  }
37

38
  return await response.json()
39
}
40