ZenDMD Tip - Move Devices to Proper Device Class

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

When performing a network discovery using either zendisc on the command line or through the web interface, all discovered devices are placed into the /Discovered device class by default. Oftentimes the minimum modeling done for devices in the /Discovered device class is enough to make a more intelligent choice about where the devices should go. The following zendmd snippets show a couple of these approaches.

Classify on Operating System Name

# Iterage through all devices in the /Discovered device class.
for device in dmd.Devices.Discovered.getSubDevices():
    # Move devices with IOS in their product name to the /Network/Cisco class.
    if "IOS" in device.getOSProductName():
        print "Moving %s to /Network/Cisco." % device.titleOrId()
        device.changeDeviceClass('/Network/Cisco')
    if device.id.startswith('CUCM-'):
        device.changeDeviceClass('/Server/Linux/CallManager')
 
commit()

Classify on SNMP sysObjectID

oidToClassMap = {
    '.1.3.6.1.4.1.8072.3.2.10': '/Server/Linux',
    '.1.3.6.1.4.1.9.1.282': '/Network/Cisco',
    '.1.3.6.1.4.1.9.1.648': '/Network/Cisco/IDS',
    '.1.3.6.1.4.1.9.1.794': '/Network/Cisco',
    '.1.3.6.1.4.1.9.1.914': '/Network/Cisco/ASA',
    '.1.3.6.1.4.1.9.1.923': '/Network/Cisco',
    '.1.3.6.1.4.1.9.12.3.1.3.612': '/Network/Cisco/Nexus',
    }
 
for device in dmd.Devices.Discovered.getSubDevicesGen():
    if device.snmpOid not in oidToClassMap:
        print "No class mapping for %s." % device.titleOrId()
        continue
    new_class = oidToClassMap[device.snmpOid]
    print "Moving %s to %s." % (device.titleOrId(), new_class)
    device.changeDeviceClass(new_class)
    commit()