Created
April 16, 2019 09:48
-
-
Save jcurry/475bdf5413500d06c7f56759152b57a4 to your computer and use it in GitHub Desktop.
Change zSnmpCommunity for multiple devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Author: Jane Curry | |
# Date October 30th 2012 | |
# Description: Sets local zSnmpCommunity property to NewSnmpCom | |
# Updates: | |
# | |
import sys | |
from optparse import OptionParser | |
import Globals | |
import time | |
from Products.ZenUtils.ZenScriptBase import ZenScriptBase | |
from transaction import commit | |
of = open('/home/zenoss/zSnmpCommunityChange.out', 'w') | |
localtime = time.asctime( time.localtime(time.time()) ) | |
of.write(localtime + "\n\n") | |
# Need noopts=True or it barfs with the script options | |
dmd = ZenScriptBase(connect=True, noopts=True).dmd | |
zSnmpCom = 'NewSnmpCom' | |
for dev in dmd.Devices.getSubDevices(): | |
# You can put in various tests here ...... | |
if dev.manageIp.startswith('192.168'): | |
# Test for a specific device - for testing | |
#if dev.id == 'group-100-r3.class.example.org': | |
# do NOT use the following line ( dev.zSnmpCommunity = zSnmpCom ) to set a local property | |
# as it bypasses the aquisition chain and you end up with "half" a local property such | |
# that Configuration Properyties does not see the change, the deleteZenProperty method | |
# cannot find the property but the new community IS used by SNMP methods - Disaster! | |
#dev.zSnmpCommunity = zSnmpCom | |
dev.setZenProperty('zSnmpCommunity', zSnmpCom ) | |
of.write('Device %s has zSnmpCommunity local property set to %s \n' % (dev.id, dev.zSnmpCommunity)) | |
print 'Device %s has zSnmpCommunity local property set to %s \n' % (dev.id, dev.zSnmpCommunity) | |
commit() | |
of.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment