Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| code:python:home [2023/06/19 15:15] – [Good links] gerardorourke | code: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: | ||
| < | < | ||
| + | |||
| + | <alert type=" | ||
| ==== Previous How to ==== | ==== Previous How to ==== | ||
| Line 236: | Line 238: | ||
| *https:// | *https:// | ||
| *https:// | *https:// | ||
| + | |||
| + | |||
| + | ===== CUCM Example to get number of members of each Device pool ===== | ||
| + | |||
| + | <code python> | ||
| + | # Author: Gerry O' | ||
| + | # 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() | ||
| + | |||
| + | # Define the URL to which the request is made | ||
| + | |||
| + | # Example Header | ||
| + | # Cookie: JSESSIONID=E6A763744109DDB05AF4053919B8D201; | ||
| + | |||
| + | # Login into CUCM from a Browser and get the below cookie value | ||
| + | cookie_value = " | ||
| + | cucmHeaders = {" | ||
| + | |||
| + | # 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' | ||
| + | |||
| + | DevicePoolNames = [" | ||
| + | DevicePoolIDs = [" | ||
| + | |||
| + | for idx, DevicePoolID in enumerate(DevicePoolIDs) : | ||
| + | url = " | ||
| + | response = requests.get(url, | ||
| + | # Check if the request was successful | ||
| + | if response.status_code == 200: | ||
| + | # Process the response content | ||
| + | # data = response.json() | ||
| + | data = response.text | ||
| + | # | ||
| + | |||
| + | for line in data.splitlines(): | ||
| + | if "< | ||
| + | print(" | ||
| + | exit(0) | ||
| + | elif "not found in the database" | ||
| + | print(" | ||
| + | exit(0) | ||
| + | elif " | ||
| + | print (DevicePoolNames[idx], | ||
| + | print(line) | ||
| + | |||
| + | else: | ||
| + | # Handle errors | ||
| + | print(" | ||
| + | print(" | ||
| + | </ | ||