-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathise-get-ers-raw.py
executable file
·67 lines (54 loc) · 1.8 KB
/
ise-get-ers-raw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""
A simple, single GET request for an ISE ERS resource.
See https://cs.co/ise-api for REST API resource names.
Usage:
ise-get-ers-raw.py {resource}
Examples:
ise-get-ers-raw.py networkdevice
ise-get-ers-raw.py networkdevice/0b6e9500-8b4a-11ec-ac96-46ca1867e58d
ise-get-ers-raw.py networkdevicegroup
ise-get-ers-raw.py identitygroup
ise-get-ers-raw.py op/systemconfig/iseversion
Requires setting the these environment variables using the `export` command:
export ISE_PPAN='1.2.3.4' # hostname or IP address of ISE Primary PAN
export ISE_REST_USERNAME='admin' # ISE ERS admin or operator username
export ISE_REST_PASSWORD='C1sco12345' # ISE ERS admin or operator password
export ISE_CERT_VERIFY=false # validate the ISE certificate
You may add these export lines to a text file and load with `source`:
source ise.sh
"""
__author__ = "Thomas Howard"
__email__ = "thomas@cisco.com"
__license__ = "MIT - https://mit-license.org/"
import requests
import json
import os
import sys
requests.packages.urllib3.disable_warnings() # Silence any warnings about certificates
HEADERS_JSON = {"Accept": "application/json"}
# Validate command line arguments
if len(sys.argv) < 2:
print(USAGE)
sys.exit(1)
resource_name = sys.argv[1]
#
# Load Environment Variables
#
env = {k: v for (k, v) in os.environ.items()}
#
# Show the resource
#
url = f"https://{env['ISE_PPAN']}/ers/config/{resource_name}"
r = requests.get(
url,
auth=(env["ISE_REST_USERNAME"], env["ISE_REST_PASSWORD"]),
headers=HEADERS_JSON,
verify=(False if env["ISE_CERT_VERIFY"][0].lower() in ["f", "n"] else True),
)
if r.status_code == 401:
print(r.status_code, file=sys.stderr)
print(USAGE, file=sys.stderr)
print(r.json())
else:
print(json.dumps(r.json(), indent=2))