Whilst trying to automate some mundane networking tasks in Python, I’ve started looking our UC environment. This lead me to a great post (thanks!) here:
https://ucnote.wordpress.com/2015/11/29/extension-mobility-remotely-login-user-to-phone/
I’m by no means a coder, but I’ve converted the PowerShell script from there into a Python version (feel free to suggest a more PEP8 improvement), that uses the Requests library.
Some uses for this is to make a web app to see who is logged in where and give the ability to log them out remotely. Alternatively, provide a Windows login/log off script that automatically logs a user into their handset (users with no roles can log themselves in/out, whilst users with the EM Authentication Proxy Rights role can login/logout any user).
Ingredients Used:
If you want to try this out it should work on most UCM versions and I think in Py3, but to rule out any incompatibilities, my environment was:
- Python 2.7
- Requests 2.9.1
- CUCM 10.5(1)
- Softphone
The Code:
Change the hard coded variables for your own and comment in/out the logout/in respectively:
#! /usr/bin/env python import getpass import requests # YOUR DETAILS FROM HERE cucm_server = "CUCM" mac = "000000000002" device = "SEP" + mac emuser = "emuser" appEmProxyUser = "appemadmin" appPw = getpass.getpass(prompt="Enter the EMProxyUser password: ") # TO HERE uri = "http://" + cucm_server + ":8080/emservice/EMServiceServlet" headers = {"Content-Type": "application/x-www-form-urlencoded"} parameters = "<request>" parameters += "<appInfo><appID>" + appEmProxyUser +\ "</appID><appCertificate>" + appPw + "</appCertificate></appInfo>" # parameters += "<logout><deviceName>" + device + "</deviceName></logout>" parameters += "<login><deviceName>" + device + "</deviceName><userID>" +\ emuser + "</userID></login>" parameters += "</request>" r = requests.post(uri, data={"xml": parameters}, headers=headers) print(r.text)
thanks heaps, if you need device profile maybe can try this
#! /usr/bin/env python
import getpass
import requests
# YOUR DETAILS FROM HERE
mac = “C444A03E131A”
emuser = “7744”
deviceprofile = “UDP_7744_7925_test”
# TO HERE
cucm_server = “CUCM_IPADDRESS”
device = “SEP” + mac
appEmProxyUser = “EM_USERNAME”
appPw = getpass.getpass(prompt=”Enter the EMProxyUser password: “)
#
uri = “http://” + cucm_server + “:8080/emservice/EMServiceServlet”
headers = {“Content-Type”:
“application/x-www-form-urlencoded”}
parameters = “”
parameters += “” + appEmProxyUser +\
“” + appPw + “”
# parameters += “” + device + “”
parameters += “” + device + “” +\
emuser + “”
parameters += “” + deviceprofile + “”
parameters += “”
#print parameters
r = requests.post(uri,
data={“xml”:
parameters},
headers=headers)
print(r.text)
LikeLike