cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
561
Views
0
Helpful
7
Replies

CUCM - Add SNMP community string via API

My Google-foo is failing me. I am looking for a way to add SNMP community strings to CUCM (versions 10.5 and 12.5) via an API. This is to support a multiple cluster CER deployment, so I want to automate it avoid missing and of the 24 source IP's involved. I have tried several different search terms, but come up empty. Is there a way to do this via API?

1 Accepted Solution

Accepted Solutions

OMG, I can't believe how much time this cost me. The biggest problem was that I was calling AddSNMPCommunityString (note first capital letter) which failed with not very helpful messages. What I should have been doing was calling addSNMPCommunityString (note first lower case letter). Argh! Here is what (finally) worked.

            # version 2
            SNMP_new = {
                'communityName': snmp_val,
                'accessPrivilege': SNMP_privilege,
                'ArrayOfHosts': {
                    'item': allowedhostarray
                }
            }

            if not ReadOnly:
                try:
                    retval = source_axl.addSNMPCommunityString(CommunityString=SNMP_new)
                except Fault as err:
                    print('Fault',err)

View solution in original post

7 Replies 7

dstaudt
Cisco Employee
Cisco Employee

Unfortunately this is not possible via API.

You may be able to automate the configuration via SSH/CLI scraping/scripting.  This isn't really an officially blessed mechanism - and can be hit-or-miss/unreliable - but I understand it's common enough in practice.  There are several community maintained tools focused on SSH/CLI automation out there.

I've personally worked on a sample that includes a Python-based library (using the Netmiko SSH/CLI automation library) for Ansible to do CUCM CLI-related automation - you might find it an interesting basis for doing some scripting: https://github.com/CiscoDevNet/axl-ansible-examples

After some further searching I did find references to AddSNMPCommunity in the AXL API guide, but wasn't seeing how I needed to format the "ArrayOfHosts" element in AddSNMPCommunityStringReq/CommunityString. I see that referenced in the xsd files, but not in the wsdl ones.

I was able to retrieve an SNMP community this way.

 

ssnmp_val = source_axl.getSNMPCommunityString(communityName=snmp_val)

 

 Here is the output of a community name that has restrictions on the host IP addresses that may use it.

 

ssnmp_val {
    'return': {
        'SNMPCommunityString': {
            'communityName': 'cce-SNMP01!',
            'version': 'both',
            'accessPrivilege': 'ReadOnly',
            'ArrayOfHosts': {
                'item': [
                    '10.236.12.35',
                    '10.236.13.35'
                ]
            }
        }
    },
    'sequence': None
}

 

I am going to guess that I should be able to do it like this:

 

newcomm = 'Test Community'
newpriv = 'ReadOnly'
newhosts = [ '10.236.12.35', '10.236.13.35' ]
retval = source_axl.AddSNMPCommunityString(communityName=newcomm,accessPrivilege=newpriv,ArrayOfHosts=newhosts)

 

 I guess we'll know soon enough. I don't see an option to apply to all hosts which exists in the GUI. I'll assume I need to add it to each CUCM host individually.

Clearly I am not formatting something correctly, but I am not able to figure out what is intended from the AXL schema. Here are two different ways I have to to format this.

# version 1
SNMP_new = {
        'CommunityString': {
                'communityName': snmp_val,
                #'version': SNMP_version,
                'accessPrivilege': SNMP_privilege,
                'ArrayOfHosts': {
                        'item': allowedhostarray
                }
        }
}
# version 2
SNMP_new = {
        'communityName': snmp_val,
        #'version': SNMP_version,
        'accessPrivilege': SNMP_privilege,
        'ArrayOfHosts': {
                'item': allowedhostarray
        }
}
if Debug:
        print('SNMP_new',SNMP_new)

if not ReadOnly:
        retval = source_axl.AddSNMPCommunityString(CommunityString=SNMP_new)

Regardless of how I create the variable SNMP_new, I get this error.

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/zeep/proxy.py", line 97, in __getitem__
    return self._operations[key]
KeyError: 'AddSNMPCommunityString'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/home/ebd/CLAUTO/CUCM/./add_snmp.py", line 139, in <module>
    main()
  File "/usr/home/ebd/CLAUTO/CUCM/./add_snmp.py", line 128, in main
    retval = source_axl.AddSNMPCommunityString(CommunityString=SNMP_new)
  File "/usr/local/lib/python3.9/site-packages/zeep/proxy.py", line 88, in __getattr__
    return self[key]
  File "/usr/local/lib/python3.9/site-packages/zeep/proxy.py", line 99, in __getitem__
    raise AttributeError("Service has no operation %r" % key)
AttributeError: Service has no operation 'AddSNMPCommunityString'

Any suggestions?

 

Still really struggling with this. I notice that the return value from getSNMPCommunityString is a type "zeep.objects.GetSNMPCommunityStringRes", but the object SNMP_new I am building is a type 'dict'. I see in the xsd file that there is a type of 'AddSNMPCommunityStringReq' which is what I need. How do I build an object and force it to be of that type?

I am giving up for today. I am still mostly getting the same error.

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/zeep/proxy.py", line 97, in __getitem__
    return self._operations[key]
KeyError: 'AddSNMPCommunityString'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/home/ebd/CLAUTO/CUCM/./add_snmp.py", line 180, in <module>
    main()
  File "/usr/home/ebd/CLAUTO/CUCM/./add_snmp.py", line 166, in main
    retval = source_axl.AddSNMPCommunityString(CommunityString=ofoo)
  File "/usr/local/lib/python3.9/site-packages/zeep/proxy.py", line 88, in __getattr__
    return self[key]
  File "/usr/local/lib/python3.9/site-packages/zeep/proxy.py", line 99, in __getitem__
    raise AttributeError("Service has no operation %r" % key)
AttributeError: Service has no operation 'AddSNMPCommunityString'

I got past some of the data typing issues this way.

            zfoo = source_client.get_type('ns0:AddSNMPCommunityStringReq')
            zfoo2 = source_client.get_type('ns0:RCommunityString')
            zfoo3 = source_client.get_type('ns0:RArrayOfHosts')

            ofoo3 = zfoo3(item=allowedhostarray)
            ofoo2 = zfoo2(communityName=snmp_val,accessPrivilege=SNMP_privilege,
ArrayOfHosts=ofoo3)
            ofoo = zfoo(CommunityString=ofoo2,sequence=1)

It sure does look like I have built the data elements correctly based on the debug output.

class of ofoo <class 'zeep.objects.AddSNMPCommunityStringReq'>
ofoo {
    'CommunityString': {
        'communityName': 'foo',
        'accessPrivilege': 'ReadOnly',
        'ArrayOfHosts': {
            'item': [
                '10.236.13.57',
                '10.93.199.22'
            ]
        }
    },
    'sequence': 1
}
class of ofoo2 <class 'zeep.objects.RCommunityString'>
ofoo2 {
    'communityName': 'foo',
    'accessPrivilege': 'ReadOnly',
    'ArrayOfHosts': {
        'item': [
            '10.236.13.57',
            '10.93.199.22'
        ]
    }
}
class of ofoo3 <class 'zeep.objects.RArrayOfHosts'>
ofoo3 {
    'item': [
        '10.236.13.57',
        '10.93.199.22'
    ]
}

OMG, I can't believe how much time this cost me. The biggest problem was that I was calling AddSNMPCommunityString (note first capital letter) which failed with not very helpful messages. What I should have been doing was calling addSNMPCommunityString (note first lower case letter). Argh! Here is what (finally) worked.

            # version 2
            SNMP_new = {
                'communityName': snmp_val,
                'accessPrivilege': SNMP_privilege,
                'ArrayOfHosts': {
                    'item': allowedhostarray
                }
            }

            if not ReadOnly:
                try:
                    retval = source_axl.addSNMPCommunityString(CommunityString=SNMP_new)
                except Fault as err:
                    print('Fault',err)