04-07-2022 01:08 PM
I was trying to query the status of cisco phones status in the following python script. But received following errors
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='localhost', port=8443): Max retries exceeded with url: /realtimeservice2/services/RISService70 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x110685460>: Failed to establish a new connection: [Errno 61] Connection refused'))
# Common Plugins
history = HistoryPlugin()
# Build Client Object for AXL Service
axl_wsdl = 'schema/AXLAPI.wsdl'
axl_location = f'https://{server}:8443/axl/'
axl_binding = '{http://www.cisco.com/AXLAPIService/}AXLAPIBinding'
axl_session = Session()
axl_session.verify = False
axl_session.auth = HTTPBasicAuth(username, password)
axl_transport = Transport(cache=SqliteCache(), session=axl_session,
timeout=20)
axl_client = Client(wsdl=axl_wsdl, transport=axl_transport,
plugins=[history])
axl_service = axl_client.create_service(axl_binding, axl_location)
# Build Client Object for RisPort70 Service
wsdl = f'https://{server}:8443/realtimeservice2/services/RISService70?wsdl'
session = Session()
session.verify = False
session.auth = HTTPBasicAuth(username, password)
transport = Transport(cache=SqliteCache(), session=session, timeout=20)
client = Client(wsdl=wsdl, transport=transport, plugins=[history])
def show_history():
for hist in [history.last_sent, history.last_received]:
print(etree.tostring(hist["envelope"],
encoding="unicode",
pretty_print=True))
# Get List of Phones to query via AXL
# (required when using SelectCmDeviceExt)
try:
resp = axl_service.listPhone(searchCriteria={'name': 'ATA%'},
returnedTags={'name': ''})
except Fault:
show_history()
raise
# Build item list for RisPort70 SelectCmDeviceExt
items = []
for phone in resp['return'].phone:
items.append(phone.name)
print(items)
print("len = ", len(items))
if len(items) > 1000:
print("This demo app only supports under 1000 results")
print("Exiting...")
sys.exit()
# Run SelectCmDeviceExt
CmSelectionCriteria = {
'MaxReturnedDevices': '1000',
'DeviceClass': 'Phone',
'Model': '255',
'Status': 'Any',
'NodeName': '',
'SelectBy': 'Name',
'SelectItems': {
'item': items
},
'Protocol': 'Any',
'DownloadStatus': 'Any'
}
StateInfo = ''
try:
resp = client.service.selectCmDeviceExt(
CmSelectionCriteria=CmSelectionCriteria,
StateInfo=StateInfo)
except Fault:
show_history()
raise
snapshot = {}
CmNodes = resp.SelectCmDeviceResult.CmNodes.item
for CmNode in CmNodes:
if len(CmNode.CmDevices.item) > 0:
# If the node has returned CmDevices, save to the snapshot to
# later compare
for item in CmNode.CmDevices.item:
# Creates a new list if the key in the dictionary isn't yet
# assigned or simply appends to the entry if there is already
# a value present
snapshot.setdefault(CmNode.Name,
[]).append({'Name': item.Name,
'Status': item.Status})
print("Successfully captured current Risport status.")
while True:
print("Press Enter to query Risport and compare to the initial result")
print("or Ctrl+C to exit")
input("...")
try:
resp = client.service.selectCmDeviceExt(
CmSelectionCriteria=CmSelectionCriteria,
StateInfo=StateInfo)
except Fault:
show_history()
raise
no_change = True
CmNodes = resp.SelectCmDeviceResult.CmNodes.item
for CmNode in CmNodes:
# Skip the CmNode if it doesn't contain any entries
if len(CmNode.CmDevices.item) > 0:
# Loop through all the returned items and compare the status
# to that of the snapshot
for item in CmNode.CmDevices.item:
for snapshot_item in snapshot[CmNode.Name]:
if snapshot_item['Name'] == item.Name and snapshot_item['Status'] != item.Status:
print(f"{item.Name} changed status from {snapshot_item['Status']} to {item.Status}")
no_change = False
if no_change:
print("No difference between snapshot and most recent query detected")
04-08-2022 08:11 AM
I believe in some versions of CUCM, the Risport70 WSDL includes the actual CUCM hostname in the WSDL contents, but in some it provides a generic one, i.e. localhost.
What should work with any version is to specifically set the target hostname when creating the Risport70 service, similar to what you are already doing with AXL (which always provides a generic hostname in the WSDL:)
axl_service = axl_client.create_service(axl_binding, axl_location)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide