Difference between revisions of "ZENDMD Tip - Delete Networks"

From Zenoss Wiki
Jump to: navigation, search
(Category, formatting)
 
Line 8: Line 8:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
 
#!/usr/bin/env zendmd
 
#!/usr/bin/env zendmd
 
# Delete all networks except 192.168.10.0
 
# Delete all networks except 192.168.10.0
Line 28: Line 27:
 
   
 
   
 
dmd.Networks.reIndex()
 
dmd.Networks.reIndex()
 
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 37: Line 34:
  
 
Make it executable and run it as the zenoss user.  
 
Make it executable and run it as the zenoss user.  
 
[[User:Jcurry|JaneCurry]] ([[User talk:Jcurry|talk]]) 18:57, 7 August 2013 (UTC)    (with thanks to cluther)
 
  
 
[[Category:Tips]]
 
[[Category:Tips]]
 +
[[Category:ZenDMD]]

Latest revision as of 14:14, 20 November 2013

If you delete lots of devices, the networks discovered that were associated with them never get cleaned up. There's no way in the GUI to select lots of networks and delete them - you can only do them individually.

I wanted to delete all networks except 192.168.10.0. This script deletes ALL IP V4 networks except 192.168.10.0.

Create delete_networks with:

#!/usr/bin/env zendmd
# Delete all networks except 192.168.10.0
# Note that this also deletes all ipaddresses in those networks
# In practise, this means that the IP interface addresses get lost for any interface not in 192.168.10.0;
#   however remodeling devices will re-add those ipaddresses and will also add them and any related
#   networks back to the Networks hierarchy.
#
for netid in dmd.Networks.objectIds(spec="IpNetwork"):
    try:
        print "Deleting network %s" % netid
        if netid == '192.168.10.0':
            print 'Dont delete %s' % (netid)
            continue
        dmd.Networks._delObject(netid)
        commit()
    except Exception, e:
        print "%s: %s" % (netid, str(e))
 
dmd.Networks.reIndex()

Take a zenoss backup (zenbackup) before doing this!

To test, comment out the dmd.Networks._delObject(netid) line.

Make it executable and run it as the zenoss user.