11-29-2023 02:49 PM
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?
Solved! Go to Solution.
12-01-2023 04:24 AM
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)
11-29-2023 03:05 PM
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
11-29-2023 03:11 PM - edited 11-29-2023 03:11 PM
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.
11-30-2023 05:55 AM - edited 11-30-2023 05:56 AM
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.
11-30-2023 09:23 AM
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?
11-30-2023 11:50 AM
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?
11-30-2023 01:33 PM
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'
]
}
12-01-2023 04:24 AM
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)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide