- Zenoss 4.x
- Zenoss 3.x
- Zenoss 2.5.x
The zendmd command provides an interactive session that connects to the ZODB database (that means it doesn't go through the zenhub daemon). Because the ZODB is an object-oriented database, this means that you can invoke method calls on the objects to perform actions and view the contents. The previous comments are really a polite warning that it is possible to seriously damage a Zenoss system by performing activities.
Before using zendmd command:
- Back up the ZODB using the zenbackup command.
- Run any commands on a test system first.
- Don't use the commit() function unless you really, really mean it and have done the above.
If the ZODB gets messed up, you will be asked to use the last backup to restore it to a known working state.
The zendmd command is actually a Python interpreter session with Zenoss-specific objects and utilities loaded into it. You will need to have some familiarity with Python in order to use this tool.
The zendmd command can be started only as the zenoss user. To start, type zendmd
zendmd Welcome to the Zenoss dmd command shell! 'dmd' is bound to the DataRoot. 'zhelp()' to get a list of commands. Use TAB-TAB to see a list of zendmd related commands. Tab completion also works for objects -- hit tab after an object name and '.' (eg dmd. + tab-key). >>>
Typing the zhelp() function returns a list of available functions:
>>> zhelp() app cleandir commit devices dmd edit find getFacade grepdir history login logout lookupGuid me pprint printNets reindex setLogLevel sh shell_stderr shell_stdout socket sync version zhelp zport
The zendmd command supports command-line history (even across sessions) and tab-completion of object variables and methods. All Python builtin functions are available, so to see the methods and attributes for the dmd object, we can use the dir() function:
>>> dir(dmd) [ ... huge listing avoided here ... ]
To view the help for a function, including hints on how to invoke it, use the help() function:
>>> help(dmd.Devices.getSubDevices) Help on method getSubDevices in module Products.ZenModel.DeviceOrganizer: getSubDevices(self, devfilter=None) method of Products.ZenModel.DeviceClass.DeviceClass instance Get all the devices under an instance of a DeviceOrganizer @param devfilter: Filter function applied to returned list @type devfilter: function @return: Devices @rtype: list
Here are the primary objects, which are the back-end objects in the ZODB referenced through the Zenoss GUI.
- zport This is the base object for all of Zenoss.
- dmd The base object for items in the Device Management Database. This is a shortcut for zport.dmd
- devices This is object at dmd.Devices provided for convenience in typing.
- app The Zope application object, provided only for completeness.
We can follow a path from one object to another by converting the breadcrumbs to an object to its Python representation. For instance, the breadcrumb:
is actually the Python object:
Any name that contains a space in it cannot be directly referenced in this fashion, so we need to use the Python built in function getattr() to retrieve it:
getattr(devices.Server.Linux, "Organizer with spaces in the name")
Changes to the ZODB
There are some changes that can be done by invoking methods on objects, and this will affect things out side of the ZODB (such as unlinking a file, opening a socket, creating a directory). As a general rule, changes made in a zendmd session are NOT written to disk, and only exist in memory. To save the changes, use the commit() method:
Yes you may not have to make a backup, depending on the operation and what methods have been invoked, but make a backup anyway because there is no other way to recover from deleting objects etc.
Additionally, note that changes made by Zenoss since the zendmd session started will not be reflected in the zendmd session. To bring the current session in sync with the actual state of the ZODD, use the sync() function:
Example: Print all of the Device Names in an Organizer
for dev in dmd.Devices.Server.Linux.getSubDevices(): print dev.id
Scripting zendmd Commands
A history of all commands typed into the zendmd is available in the $ZENHOME/.pyhistory file. By copying this file into a new file and editing it, it is easy to take any exploration inside of zendmd and turn it into a handy script.
If you create a script containing zendmd commands, the script can be processed by zendmd by using the --script flag:
zendmd --help Usage: zendmd.py [options] Options: -h, --help show this help message and exit --host=HOST Hostname of ZEO server --port=PORT Port of ZEO server --script=SCRIPT Name of file to execute --commit Run commit() at end of script?