-
Notifications
You must be signed in to change notification settings - Fork 3
/
ise-walk.py
executable file
·154 lines (127 loc) · 3.93 KB
/
ise-walk.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
"""
Walk the ISE ERS resource endpoints.
Get the total number of a specific ISE ERS resource.
Usage: ise-walk.py
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-env.sh
"""
__author__ = "Thomas Howard"
__email__ = "[email protected]"
__license__ = "MIT - https://mit-license.org/"
import os
import requests
import sys
import time
# Silence any warnings about certificates
requests.packages.urllib3.disable_warnings()
# List of supported ISE resources
RESOURCE_NAMES = [
# Deployment
'node',
'sessionservicenode',
# Network Devices
'networkdevicegroup',
'networkdevice',
# Endpoints
'endpointgroup',
'endpoint',
'endpointcert', # POST(create) only!!!
'profilerprofile',
# RADIUS Authentications
'activedirectory',
'allowedprotocols',
'adminuser',
'identitygroup',
'internaluser',
'externalradiusserver',
'radiusserversequence',
'idstoresequence',
'restidstore', # RESTIDStore must be enabled / 404 if not configured
# RADIUS Authorizations / Policy
'authorizationprofile',
'downloadableacl',
'filterpolicy', # 404 if none configured
# Portals
'portal',
'portalglobalsetting',
'portaltheme',
'hotspotportal',
'selfregportal',
# Guest
'guestlocation',
'guestsmtpnotificationsettings',
'guestssid',
'guesttype',
'guestuser', # 🛑 requires sponsor account!!!
'smsprovider',
'sponsorportal',
'sponsoredguestportal',
'sponsorgroup',
'sponsorgroupmember',
# BYOD
'certificateprofile',
'certificatetemplate',
'byodportal',
'mydeviceportal',
'nspprofile',
# SDA
'sgt',
'sgacl',
'sgmapping',
'sgmappinggroup',
'sgtvnvlan',
'egressmatrixcell',
'sxpconnections',
'sxplocalbindings',
'sxpvpns',
# TACACS
'tacacscommandsets',
'tacacsexternalservers', # 404 if none configured
'tacacsprofile',
'tacacsserversequence', # 404 if none configured
# pxGrid / ANC / RTC / TC-NAC
# 'pxgridnode', # 🐛 🛑 404 always whether pxGrid is enabled or not
'ancendpoint',
'ancpolicy',
]
def resource_count (resource) :
"""
Walk through the list of ISE Resources and count them.
"""
LEAF = ' ┣╸'
count = 0
try :
url = 'https://'+env['ISE_PPAN']+'/ers/config/'+resource
r = requests.get(url,
auth=(env['ISE_REST_USERNAME'], env['ISE_REST_PASSWORD']),
headers={'Accept': 'application/json'},
verify=(False if env['ISE_CERT_VERIFY'][0:1].lower() in ['f','n'] else True)
)
if r.status_code == 401 :
if resource == 'guestuser' :
print(f"{LEAF}{resource} [{count}] ⟁ requires sponsor account")
elif r.status_code == 404 :
print(f'{LEAF}{resource} [{count}] ⟁ Not configured')
else :
count = r.json()['SearchResult']['total']
print(f'{LEAF}{resource} [{count}]')
except Exception as e:
if resource == 'endpointcert' :
print(f"{LEAF}{resource} [{count}] ⟁ POST endpointcert only!")
else :
print(f"{LEAF}{resource} [{count}] ⟁ Exception ")
if __name__ == "__main__":
"""
Entrypoint for local script.
"""
# Load Environment Variables
env = { k : v for (k, v) in os.environ.items() }
print('C▶'+env['ISE_PPAN'])
for resource in RESOURCE_NAMES :
resource_count(resource)