There are limitations on the values that can be configured via Cisco Unified Communications Manager Administration for Cisco Video Conference devices. For example, In order to configure SNMP monitoring you would need to login to the endpoint and configure the settings manually which can can take a considerable amount of time for a large number of endpoints.
The following code demonstrates how you can configure the appropriate settings using the Collaboration Endpoint Api.
Full Code
- from requests import Session
- import requests
- requests.packages.urllib3.disable_warnings()
- import xmltodict
- # Define the Api user credential
- user = "apiuser"
- # Define the Api Password Credential
- pwd = "apipass"
- # Define the url for the put request
- put_xml = "/putxml"
- # HTTP Content Header
- headers = {"Content-Type": "text/xml"}
- # Define the first SNMP Server
- snmp_server_1 = "10.10.10.1"
- # Define the second SNMP Server
- snmp_server_2 = "10.10.10.2"
- # Define the Syslog Server
- syslog_server= "10.10.10.3"
- # Define the Syslog Port
- syslog_port = "514"
- # Define the SNMP Read Only Community
- snmp_ro_community = "mysnmpstring"
- # Define the SNMP Mode
- snmp_mode = "ReadOnly"
- # Define our Logging Structure to hold the parameters
- logging = {
- "Configuration": {
- "Logging": {
- # The Configuration Section for external logging
- "External": {
- # Select mode ON
- "Mode": "On",
- # Use standard Syslog / no TLS
- "Protocol": "Syslog",
- # Disable TlsVerify for cosmetic purposes
- "TlsVerify": "Off",
- # Configure the Server Address and the Port
- "Server": {
- "Address": syslog_server,
- "Port": syslog_port
- }
- }
- }
- }
- }
- # Define our Snmp Structure to hold the parameters
- snmp = {
- "Configuration": {
- "NetworkServices": {
- "SNMP": {
- # Configure the SNMP Read Only Community
- "CommunityName": snmp_ro_community,
- # Configure the SNMP hosts that can talk to the device
- "Host 1 Address": snmp_server_1,
- "Host 2 Address": snmp_server_2,
- # Configure the SNMP Mode
- "Mode": snmp_mode,
- }
- }
- }
- }
- # Define a function to configure the logging parameters
- def configure_logging(vc):
- # Build the url
- url = "https://" + vc + put_xml
- # Make the POST request
- r = requests.post(
- # Build the url
- url=url,
- # Add the Content Headers
- headers=headers,
- # Disable certificate validation
- verify=False,
- # Provide the Basic auth credentials
- auth=(user, pwd),
- # Parse the dictionary structure and add the generate XML Body to the request
- data=xmltodict.unparse(logging)
- )
- # Print the output
- print(r.status_code, r.text)
- # Define a function to configure the logging parameters
- def configure_snmp(vc):
- # Build the url
- url = "https://" + vc + put_xml
- # Make the POST request
- r = requests.post(
- # Build the url
- url=url,
- # Add the Content Headers
- headers=headers,
- # Disable certificate validation
- verify=False,
- # Provide the Basic auth credentials
- auth=(user, pwd),
- # Parse the dictionary structure and add the generate XML Body to the request
- data=xmltodict.unparse(snmp)
- )
- # Print the output
- print(r.status_code, r.text)
- def main():
- # Define the input filename of ip addresses
- file_name = "vc1.txt"
- # Open the input file
- print("Opening input file .. {}".format(file_name))
- vc_hosts = open(file_name, "r").read().split("\n")
- # Iterate through our Hosts
- for vc in vc_hosts:
- print("#" * 100)
- # Create a Try & Accept Loop To Catch non responsive devices
- try:
- print("Configuring SNMP & Syslog on device ....'{}'".format(vc))
- # Call the Configure Logging & Syslog Functions
- configure_logging(vc)
- configure_snmp(vc)
- except Exception as e:
- print(str(e))
- else:
- # When we have a compatible session
- print("Configuration completed successfully...")
- if __name__ == "__main__":
- main()