cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
925
Views
0
Helpful
1
Replies

Export Guest User from ISE 2.4

Hi,

 

i tried to export 1500 guest user from ISE 2.4 with follow python script but the output is only for 20 users. What's the procedure to export 1500 guest user with the ISE rest API?

import http.client
import base64
import ssl
import sys
import json
import sys
import getpass

 


# host and authentication credentials
host = "ise_host"
user = "user_rest_ise"
password = "password_rest_ise"

# OR Challenge the user for the appropriate
#host = input("Host IP:")
#user = input("Username:")
#password = getpass.getpass()

conn = http.client.HTTPSConnection("{}:9060".format(host), context=ssl.SSLContext(ssl.PROTOCOL_TLSv1_2))

creds = str.encode(':'.join((user, password)))
encodedAuth = bytes.decode(base64.b64encode(creds))

headers = {
'accept': "application/json",
'authorization': " ".join(("Basic",encodedAuth)),
'cache-control': "no-cache",
}

conn.request("GET", "/ers/config/guestuser/", headers=headers)



#conn.request("GET", "/ers/config/adminuser/", headers=headers)

res = conn.getresponse()
print(res.status, res.reason)
data = res.read()

if res.status ==401:
 print("Connection unauthorised - Exit")
 sys.exit()
elif res.status == 200:
 Rawjsondata = json.loads(data.decode("utf-8"))
 blob = Rawjsondata["SearchResult"]["resources"]
 print("Guest Entry Count = " +str(len(blob)))
for item in blob:
 print(item["name"],",",end='')# print the guest username
conn.request("GET", item["link"]["href"], headers=headers) #Fetch the guest details data
res = conn.getresponse()
data = res.read()
Rawjsondata = json.loads(data.decode("utf-8"))
subblob = Rawjsondata["GuestUser"] # This is the Guest detail containing stuff we want
print(subblob["guestType"],",",end='') # Guest Type
print(subblob["status"],",",end='') # Guest account status
print(subblob["guestInfo"]["lastName"],",",end='') # Last name
print(subblob["guestInfo"]["firstName"],",",end='') # First name
print(subblob["guestInfo"]["emailAddress"],",",end='') # Login username - this is the final item
#print(subblob["guestAccessInfo"]["validDays"],",",end='') # Valid Days
#print(subblob["guestAccessInfo"]["fromDate"],",",end='') # From
#print(subblob["guestAccessInfo"]["toDate"],",",end='') # To
1 Reply 1

Arne Bier
VIP
VIP

You can specify the return elements with a ?size= argument ... but that's only if you roughly know what you're dealing with. To handle arbitrary length lists you should check the return code for each GET.

 

Try this (and amend for your API call)

 

def get_device_list(s):
    """
    Return list of the Network Devices
    Maximum is 100 devices per page ?size=100
    Go through the pages &page = 1
    """
    url = "https://" + ISE_SERVER + ":9060/ers/config/networkdevice?size=100&page="
    url = url + "1"
     resp= requests.request("GET", url, data=payload, headers=headers, params=querystring)
    
    device_list = []
if resp.status_code == 200:
        result  = resp.json()['SearchResult']
        total = result['total']
        pages = total / 100 + 1
        for page in range (1, int(pages + 1)):
            resp= requests.request("GET", url + str(page), data=payload, headers=headers, params=querystring)
            if resp.ok:
                result = resp.json()['SearchResult']['resources']
                for item in result:
                    device = {}
                    device['id'] = item['id']
                    device['name'] = item['name']
                    """ Not all devices has description field """
                    # device['description'] = item['description']
                    device['link'] = item['link']['href']
                    device_list.append(device)
return device_list