Make and AXL Query Against CUCM with Python

I recently had a need to interact with Cisco Unified Communications Manager (CUCM) in an automated way. Some quick searched returned some code that worked a little bit, but not all the way. Here is the code that I ended up with that works.


#!/usr/bin/python
#The purpose of this script is to execute a basic query against CUCM via AXL
from suds.client import Client
from suds.sax.element import Element
import base64
import ssl
if hasattr(ssl, '_create_unverified_context'):
ssl._create_default_https_context = ssl._create_unverified_context
cmserver = 'IP-ADDRESS'
cmport = '8443'
wsdl = 'file:///var/www/html/AXLAPI.wsdl'
location = 'https://' + cmserver + ':' + cmport + '/axl/'
username = 'MyAXLUser'
password = 'MyPassword'
def getUser(userName):
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
authenticationHeader = {
"SOAPAction" : "ActionName",
"Authorization" : "Basic %s" % base64string
}
client = Client(wsdl, location=location, username=username, password=password, headers=authenticationHeader)
userName = str(userName)[:-1].lower()
agentName = Element('userid').setText(userName)
try:
getUser = client.service.getUser(agentName)
DEVICEID = getUser[0][0][11][0][0]
return DEVICEID
except:
return "no device associated"
print getUser('Rick.Breidenstein')

GitHub Link: Here it is

 

 

Snippets of problems and errors along the way

Hopefully providing the errors that I came across will help others with the same issue find a solution faster.

Creating the unverified ssl context resolved the issue below

Traceback (most recent call last):
File "test.py", line 15, in
result = client.service.getOSVersion()
File "build/bdist.linux-x86_64/egg/suds/client.py", line 535, in __call__
File "build/bdist.linux-x86_64/egg/suds/client.py", line 595, in invoke
File "build/bdist.linux-x86_64/egg/suds/client.py", line 620, in send
File "build/bdist.linux-x86_64/egg/suds/transport/http.py", line 85, in send
File "build/bdist.linux-x86_64/egg/suds/transport/http.py", line 107, in __open
File "/usr/lib/python2.7/urllib2.py", line 429, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 447, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1241, in https_open
context=self._context)
File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
raise URLError(err)
urllib2.URLError:

adding the authentication header resolved the issue below

Traceback (most recent call last):
File "test.py", line 16, in
result = client.service.getOSVersion()
File "build/bdist.linux-x86_64/egg/suds/client.py", line 535, in __call__
File "build/bdist.linux-x86_64/egg/suds/client.py", line 595, in invoke
File "build/bdist.linux-x86_64/egg/suds/client.py", line 630, in send
File "build/bdist.linux-x86_64/egg/suds/client.py", line 687, in failed
Exception: (401, u'Unauthorized')

Introducing the Element to pass through the suds client resolved the issue below

No handlers could be found for logger "suds.client"
Traceback (most recent call last):
File "test.py", line 29, in
result = client.service.getPhone(name = 'SEPD0C282D1ECE0')
File "build/bdist.linux-x86_64/egg/suds/client.py", line 535, in __call__
File "build/bdist.linux-x86_64/egg/suds/client.py", line 595, in invoke
File "build/bdist.linux-x86_64/egg/suds/client.py", line 630, in send
File "build/bdist.linux-x86_64/egg/suds/client.py", line 681, in failed
File "build/bdist.linux-x86_64/egg/suds/bindings/binding.py", line 235, in get_fault
suds.WebFault: Server raised fault: 'No uuid or name element found'

Error below became present when passing the user name through as a variable. Removing the last character from the string resolved this.

No handlers could be found for logger "suds.client"
Traceback (most recent call last):
File "test.py", line 29, in
result = client.service.getUser(user = 'Tony.Hasting')
File "build/bdist.linux-x86_64/egg/suds/client.py", line 535, in __call__
File "build/bdist.linux-x86_64/egg/suds/client.py", line 595, in invoke
File "build/bdist.linux-x86_64/egg/suds/client.py", line 630, in send
File "build/bdist.linux-x86_64/egg/suds/client.py", line 681, in failed
File "build/bdist.linux-x86_64/egg/suds/bindings/binding.py", line 235, in get_fault
suds.WebFault: Server raised fault: 'Item not valid: The specified User was not found'

Error below is when you do not create an element for searchCriteria and returnedTags. reference the listUser function.

No handlers could be found for logger "suds.client"
Traceback (most recent call last):
File "./cucm-axl.py", line 46, in
listUser(user[:-1])
File "./cucm-axl.py", line 42, in listUser
result = client.service.listUser()
File "build/bdist.linux-x86_64/egg/suds/client.py", line 535, in __call__
File "build/bdist.linux-x86_64/egg/suds/client.py", line 595, in invoke
File "build/bdist.linux-x86_64/egg/suds/client.py", line 630, in send
File "build/bdist.linux-x86_64/egg/suds/client.py", line 681, in failed
File "build/bdist.linux-x86_64/egg/suds/bindings/binding.py", line 235, in get_fault
suds.WebFault: Server raised fault: 'No Search Criteria Defined'

References:

This is the result from a collection of many different sources. Sorry I do no have all the links to site.

Google OnHub Port Forwarding Not Working

Issue: Port forwarding of external ports to internal devices using the Google OnHub router stopped working

Cause: A device supporting UPnP was recently added to the network. I was able to arrive at this hypothesis because once I swapped in a Linksys router with no static port forwarding configured, the offending device was available and responding externally.

Resolution: Disable UPnP on the offending device.

Windows hosts file not being used for resolution

windows version: Server 2003 R2 Standard x64 SP2

Verify it’s not working

ipconfig /flushdns

ipconfig /displaydns | more

Check for type-o’s!

Start with the simple solution first

Verify hosts file location

Open Registry Editor

Verify key: My Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services|Tcpip\Parameters\DataBasePath

Copy Value data and paste it into Explorer to verify you are editing the correct file

Verify file permissions (This was my issue)

If machine\users is not given Read and Read & Execute permissions, add the account.

 

Networking not working after Windows 10 Update (version 1511, build 10586.3)

My device:  Lenovo ThinkPad Yogo 2

After applying the latest Windows 10, update, version 1511, build 10586.3, all of my networking was jacked up. I was unable to connect to any wireless networks (showed a small amount of sent packets, 0 received, and great single strength). I attempted to uninstall the device from device manager and when I rebooted the device reinstalled, but still nothing worked.

When I got home I attempted to use my USB Ethernet adapter and even that didn’t work.

The Solution

NOTE: Following the procedure below will reset all networking. This includes Hyper-V and VPN interfaces. (My Cisco VPN client rebuilt everything automatically when I attempted to connect).

Run “netcfg -d” from an admin command prompt, then reboot and reconfigure networking.

Microsoft Windows [Version 10.0.10586]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>netcfg -d
SetupDiCallClassInstaller Erorr: 0x6
SetupDiCallClassInstaller Erorr: 0x6
SetupDiCallClassInstaller Erorr: 0x6
SetupDiCallClassInstaller Erorr: 0x6
SetupDiCallClassInstaller Erorr: 0x6
SetupDiCallClassInstaller Erorr: 0x6
SetupDiCallClassInstaller Erorr: 0x6
SetupDiCallClassInstaller Erorr: 0x6
NetSetup object deleted successfully on MUX
Successfully commited changes to the registry
Successfully commited changes to the registry
We are going to reboot now to complete the clean up. Save all of your work.
Press any key to continue…

Need to check your windows version?

  1. Start menu
  2. type “about your pc”
  3. press enter

Capture

 

 

References:

  • http://windows.microsoft.com/en-us/windows/which-operating-system
  • http://windows.microsoft.com/en-us/windows-10/fix-network-connection-issues

Reverse DNS Lookup

Need to setup reverse DNS lookup for your public IP? Here’s the quick cheat sheet.

Note: In this example the IP address is 188.251.142.63 and the host name is mail.virtualrick.com

  1. Request that your ISP (or if you control your IP’s through ARIN log in to their management portal) to delegate the reverse lookup for your IP’s to your DNS server
    1. If you do not want to control this you can ask that they create/update the PTR records
  2. Create the reverse DNS zone
    1. example: 142.251.188.in-addr.arpa
  3. Create the PTR record with the partial IP address and host name
    1. example: IP:”63″ and hostname:”mail.virtualrick.com”
  4. Wait for propagation
  5. Verify
      1. # dig ptr 63.142.251.188.in-addr.arpa; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> ptr 63.142.251.188.in-addr.arpa
        ;; global options: +cmd
        ;; Got answer:
        ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26138
        ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1;; OPT PSEUDOSECTION:
        ; EDNS: version: 0, flags:; udp: 512
        ;; QUESTION SECTION:
        ;63.142.251.188.in-addr.arpa. IN PTR;; ANSWER SECTION:
        63.142.251.188.in-addr.arpa. 21265 IN PTR mail.virtualrick.com.
        
        ;; Query time: 9 msec
        ;; SERVER: 8.8.8.8#53(8.8.8.8)
        ;; WHEN: Wed Oct 28 16:01:54 CDT 2015
        ;; MSG SIZE rcvd: 92

     

Windows 8 automatically connecting to unsecured wireless networks (MAKE IT STOP!)

Issue: Windows 8.1 w/ Intel wireless driver will automatically connect to “free”, unsecured, wireless networks.

This issue has been bugging me for a little bit, but has not been at the top of list until there were a large number of unsecured wireless networks available while traveling. So here’s the solution.

resolution:

  1. open the control panel
  2. Open “Network and Internet”
  3. Select “Intel ProSet/Wireless Tools”
  4. Select “Settings…” under “Intel Wifi HotSpot Assistant”
  5. Remove all check boxes
  6. Close out of the dialog box

 

 

Win8_Wifi

Configure sFlow for HP switches

A-series

Execute the following commands on the desired interface

sflow flow collector 1
sflow sampling-rate 1000
sflow counter collector 1
sflow counter interval 60

E-series

sflow 1 destination ${collector}
sflow 1 polling ${interface} 60
sflow 1 sampling ${interface} 1000

Packet captures on Windows 2008 R2 ( & 2012, 2016)

Need to run a packet capture but your services for some unknown reason are running on a Windows Server? If yes, then your in luck. As of Windows Server 2008 R2 the tools you need are already installed on the server for you!

Quick capture

Note: Needs to be run from an elevated command prompt

Start the capture

netsh trace start scenario=NetConnection capture=yes tracefile=tracefile.etl

Stop the capture

netsh trace stop

Results

The results will be a nice cab file you can easily transfer to your client workstation for review.
You may want to use a tool like Microsoft’s Message Analyzer to review the capture.
Micosoft Message Analyzer

 

References: http://blogs.technet.com/b/yongrhee/archive/2012/12/01/network-tracing-packet-sniffing-built-in-to-windows-server-2008-r2-and-windows-server-2012.aspx

Replace failed HP-3800 E-Series stack member

Recently we had to replace a few failed HP-3800 stack members. Luckily this is pretty easy. Execute the following command on the switch stack once the  failed switch has been removed and before the replacement switch has been connected to the stack.

Proceedure

  1. Power down and remove the failed switch
  2. Update the switch stack for the new switch
    1. Locate the system mac address from the back of the switch
    2. switch-stack-01(config)#Stacking member <member ID> type <type ID> mac-address <mac address ID>
  3. Power on the new switch
  4. A message indicating incompatible OS may be displayed when the switch is first powered on. This will go away after a couple reboots. The new member will receive it’s OS from the commander



Reference
http://bizsupport2.austin.hp.com/bc/docs/support/SupportManual/c03724590/c03724590.pdf