Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
code:python:home [2023/06/19 15:15] – [Good links] gerardorourkecode:python:home [2024/06/13 17:30] (current) – [CUCM Example to get number of members of each Device pool] gerardorourke
Line 64: Line 64:
   - Install as follows:   - Install as follows:
 <code>pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse  </code> <code>pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse  </code>
 +
 +<alert type="info">Note - run Command Windows as an admin user if pip install for all users</alert>
  
 ==== Previous How to ==== ==== Previous How to ====
Line 236: Line 238:
   *https://matthew-brett.github.io/teaching/string_formatting.html   *https://matthew-brett.github.io/teaching/string_formatting.html
   *https://docs.python.org/3/library/xml.etree.elementtree.html   *https://docs.python.org/3/library/xml.etree.elementtree.html
 +
 +
 +===== CUCM Example to get number of members of each Device pool =====
 +
 +<code python>
 +# Author: Gerry O'Rourke
 +# Date: 13/06/2024
 +# Simple Script to Gather Which Device Pools have how many members
 +
 +# Import the requests module
 +import requests
 +from requests.auth import HTTPBasicAuth
 +import urllib3  #
 +urllib3.disable_warnings()  # Suppress cert warnings
 +
 +# Define the URL to which the request is made
 +
 +# Example Header 
 +# Cookie: JSESSIONID=E6A763744109DDB05AF4053919B8D201; com.cisco.ccm.admin.servlets.RequestToken.REQUEST_TOKEN_KEY=4968301074955380751; JSESSIONIDSSO=39E11835B1D6C61323D98040B9190D91
 +
 +# Login into CUCM from a Browser and get the below cookie value
 +cookie_value = "JSESSIONID=AE300DB52D11CDCCDDFC36E236EBC941; com.cisco.ccm.admin.servlets.RequestToken.REQUEST_TOKEN_KEY=-3398037942865486169; JSESSIONIDSSO=A367EF12F888597FA470F56A6D70A19F"
 +cucmHeaders = {"Cookie": cookie_value}
 +
 +# Make the GET request with basic authentication and ignoring SSL certificate verification
 +# To get the Device IDs run the command 'run sql select name,pkid from devicepool' on the CUCM Server
 +
 +DevicePoolNames = ["DP-1", "DP-2"]
 +DevicePoolIDs = ["0584f54e-f28b-2e4d-981d-332d7175a84e", "06913808-0226-399e-2ad3-29954e660a64"]
 +
 +for idx, DevicePoolID in enumerate(DevicePoolIDs) :
 +    url = "https://cucm-pub.example.com/ccmadmin/devicePoolEdit.do?key=" + DevicePoolID
 +    response = requests.get(url, headers=cucmHeaders, verify=False)
 +    # Check if the request was successful
 +    if response.status_code == 200:
 +        # Process the response content
 +        # data = response.json()  # Assuming the response is in JSON format
 +        data = response.text  
 +        #print("Success:", data)
 +
 +        for line in data.splitlines():
 +            if "<title>Cisco Unified CM Console</title>" in line:
 +                print("Refresh Cookie!")
 +                exit(0)
 +            elif "not found in the database" in line:
 +                print("ID Invalid! Exiting!")
 +                exit(0)
 +            elif "members**)" in line:
 +                print (DevicePoolNames[idx], end="")
 +                print(line)
 +
 +    else:
 +        # Handle errors
 +        print("Failed to retrieve data. Status code:", response.status_code)
 +        print("Response:", response.text)
 +</code>
  • code/python/home.1687184119.txt.gz
  • Last modified: 2023/06/19 15:15
  • by gerardorourke