Created
August 14, 2014 01:09
-
-
Save jstanley23/be9c86fcd814f89e9717 to your computer and use it in GitHub Desktop.
zendmd device rename to snmp shortname
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
GO = True | |
log = open('/tmp/ZenDMD_Rename.txt', "w") | |
for d in dmd.Devices.Server.getSubDevices(): | |
new_sysname = ((d.snmpSysName).split(".", 1)[0]).lower() | |
if "@" in new_sysname: | |
new_sysname = new_sysname.split("@", 1)[1] | |
if d.id != new_sysname: | |
newid = new_sysname | |
print >>log, "Device ID: " + d.id | |
print >>log, "Device Title: " + d.title | |
print >>log, "Device SysName: " + d.snmpSysName | |
print >>log, "Device IP: " + d.manageIp | |
print >>log, "New Device Info: " + newid | |
if GO == True: | |
if d.id == newid and d.title == newid: | |
print >>log, "Change not needed." | |
elif len(newid) > 0: | |
try: | |
d.setTitle(newid) | |
print >>log, "Changed Title to: " + newid | |
d.renameDevice(newid) | |
print >>log, "Changed ID to: " + newid | |
commit() | |
except: | |
print >>log, "Unable to rename device. No changes made." | |
else: | |
print >>log, "SysName not set. No changes made." | |
print >>log, '-'*40 | |
log.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment