0

Get network device

by
Published today

Get the full configuration of a Cisco ISE network access device by ID or name.

Script cisco_ise Verified

The script

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

3
/**
4
 * Get network device
5
 * Get the full configuration of one network access device, by ID or by name. Set exactly one of device_id and name.
6
 */
7
export async function main(
8
  auth: RT.CiscoIse,
9
  device_id: string | undefined,
10
  name: string | undefined
11
) {
12
  if (!device_id === !name) {
13
    throw new Error("Set exactly one of device_id and name")
14
  }
15
  const base = new URL(auth.base_url)
16
  if (auth.ers_port) base.port = String(auth.ers_port)
17
  const path = device_id
18
    ? `/ers/config/networkdevice/${encodeURIComponent(device_id)}`
19
    : `/ers/config/networkdevice/name/${encodeURIComponent(name!)}`
20
  const url = new URL(path, base)
21

22
  const response = await fetch(url, {
23
    headers: {
24
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
25
      Accept: "application/json",
26
    },
27
  })
28

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

33
  return await response.json()
34
}
35