Diving into the Device Model
This page explores the Zenoss Device model using zendmd. It also shows how settings in modeler plugins end up affecting the device model. To start out get a device.
$ zendmd
>>> device = dmd.Devices.deviceSearch.searchResults()[0].getObject()
>>> device
<Device at /zport/dmd/Devices/Server/Linux/devices/test-cent4-64-2.zenoss.loc>
Import modules and define a function for later use. This is similar to the grepdir function that is built-in to zendmd, but it takes out attributes that start with ''.
>>> import re
>>> def findAttrs(object, pattern=''):
... """Find attribtues of object that match pattern"""
... for attribute in dir(object):
... if not attribute.startswith('__') and re.search(pattern, attribute, re.I):
... print attribute
...
>>>
Modeling using Properties and Setters directly on Device
An example of a modeler plugin that models properties and setters directly on a device object is uname_a.py. Note that is sets
compname = ''
and doesn't specify relname nor modname. The process method creates an ObjectMap using the objectMap method. That method uses the class attribute compname to create the ObjectMap instance. zenmodeler sends the ObjectMap to zenhub which decodes it as being intended to model attributes and setter methods on a Device object in ApplyDataMap.py. Back in the process method of the uname_a plugin, you'll notice that is sets two attributes on the ObjectMap 'snmpSysName' and 'setOSProductKey'. Where did these values come from? What other valid values are available?
snmpSysName is a property on Device. You can use the propertyIds method in zendmd to list all the property IDs.
>>> for propertyId in device.propertyIds(): propertyId
...
'snmpindex'
'monitor'
'manageIp'
'productionState'
'preMWProductionState'
'snmpAgent'
'snmpDescr'
'snmpOid'
'snmpContact'
'snmpSysName'
'snmpLocation'
'snmpLastCollection'
'snmpAgent'
'rackSlot'
'comments'
'sysedgeLicenseMode'
'priority'
'zSnmpVer'
Most of these pertain to modeling the device. Many of these show up in the device status page deviceStatus.pt.
setOSProductKey is a setter method on device. Here are the other setters.
>>> findAttrs(device, '^set.*[^_]$')
setAdminLocalRoles
setGroups
setHWProduct
setHWProductKey
setHWSerialNumber
setHWTag
setLastChange
setLastPollSnmpUpTime
setLocation
setManageIp
setOSProduct
setOSProductKey
setPerformanceMonitor
setPriority
setProdState
setSendEventWhenBlockedFlag
setSnmpLastCollection
setSystems
setTerminalServer
setZenProperty
Not all setter methods apply to modeling.