Difference between revisions of "ZenDMD Tips"
Chet Luther (Talk | contribs) m (Fix link to ZenDMD category.) |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
zendmd is a command line tool that can either be used as a [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] for Zenoss, or as an interpreter to run scripts. It is installed by Zenoss to $ZENHOME/bin/zendmd. | zendmd is a command line tool that can either be used as a [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] for Zenoss, or as an interpreter to run scripts. It is installed by Zenoss to $ZENHOME/bin/zendmd. | ||
− | You can do a lot of powerful things from <tt>zendmd</tt>. | + | You can do a lot of powerful things from <tt>zendmd</tt>. The best thing to start would be to review some of the examples linked from this page to see how it works. There is also a bit of reference on the usage of the language [https://support.zenoss.com/hc/en-us/articles/202946755-An-Introduction-to-zendmd here] and a very nice quick start [http://www.ryanisroot.net/zenoss:zendmd here] and [https://zindilis.com/docs/zenoss/zendmd-get-devices.html here] |
+ | |||
+ | |||
+ | You can use zendmd in two different modes | ||
== Using as a REPL == | == Using as a REPL == | ||
Line 21: | Line 24: | ||
zendmd can be used as a script interpreter as of Zenoss 4.2. For example, create a file called ''example.zendmd''. The extension doesn't matter, but is a good convention. Add the following contents. | zendmd can be used as a script interpreter as of Zenoss 4.2. For example, create a file called ''example.zendmd''. The extension doesn't matter, but is a good convention. Add the following contents. | ||
− | <syntaxhighlight lang= | + | <syntaxhighlight lang=python> |
#!/usr/bin/env zendmd | #!/usr/bin/env zendmd | ||
Line 40: | Line 43: | ||
See the examples in in the [[:Category:ZenDMD|ZenDMD]] category that have been contributed to demonstrate the kinds of things that can be done using zendmd. They are applicable either to the REPL or interpreter modes. | See the examples in in the [[:Category:ZenDMD|ZenDMD]] category that have been contributed to demonstrate the kinds of things that can be done using zendmd. They are applicable either to the REPL or interpreter modes. | ||
+ | |||
+ | {{#ask: [[Category:ZenDMD]] | ||
+ | |format=category | ||
+ | |limit=500 | ||
+ | }} | ||
+ | __NOCACHE__ | ||
+ | |||
+ | == ZenDMD configuration file == | ||
+ | If you often have to access some objects in zendmd, or write shortcut functions or test data, you could create script that does this for you, and then runs interactive bpython or ipython session like this: | ||
+ | |||
+ | <syntaxhighlight lang=python> | ||
+ | try: | ||
+ | # try to do some imports | ||
+ | from ZenPacks.zenoss.Layer2.connections_catalog import CatalogAPI | ||
+ | |||
+ | # create some objects | ||
+ | cat = CatalogAPI(zport) | ||
+ | |||
+ | # create some shortcuts | ||
+ | def gc(x): | ||
+ | ''' get entities connected to entity x ''' | ||
+ | return list(cat.get_connected(x)) | ||
+ | |||
+ | except ImportError, e: | ||
+ | print e | ||
+ | |||
+ | # initialize some variables | ||
+ | devices = dmd.Devices.getSubDevices() | ||
+ | |||
+ | import bpython; bpython.embed(locals()) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Save this file for example in <code>~/bzendmd.py</code> and add following alias in <code>.bashrc</code>: | ||
+ | |||
+ | <syntaxhighlight lang=bash> | ||
+ | alias dmd="zendmd --script=/home/zenoss/bzendmd.py" | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Now you could start your custom interactive environment using command <code>dmd</code>. | ||
[[Category:ZenDMD]] | [[Category:ZenDMD]] | ||
[[Category:Tips]] | [[Category:Tips]] |
Latest revision as of 16:52, 5 February 2016
zendmd is a command line tool that can either be used as a REPL for Zenoss, or as an interpreter to run scripts. It is installed by Zenoss to $ZENHOME/bin/zendmd.
You can do a lot of powerful things from zendmd. The best thing to start would be to review some of the examples linked from this page to see how it works. There is also a bit of reference on the usage of the language here and a very nice quick start here and here
You can use zendmd in two different modes
Contents
Using as a REPL
To use in REPL mode, execute zendmd as the zenoss user.
$ 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).
>>>
Using as an Interpreter
zendmd can be used as a script interpreter as of Zenoss 4.2. For example, create a file called example.zendmd. The extension doesn't matter, but is a good convention. Add the following contents.
#!/usr/bin/env zendmd for device in dmd.Devices.getSubDevicesGen(): print "%s (%s)" % (device.titleOrId(), device.manageIp)
You can then make example.zendmd executable, and execute it by running the following commands. As the zenoss user.
$ chmod 0755 example.zendmd $ ./example.zendmd
You should see the name and management IP address of each device in your system printed.
ZenDMD Tips - Don't work hard, work smart!
See the examples in in the ZenDMD category that have been contributed to demonstrate the kinds of things that can be done using zendmd. They are applicable either to the REPL or interpreter modes.
- ZENDMD Tip - Delete Networks
- ZenDMD -Adding Devices in Bulk
- ZenDMD TIP - List Decomissioned devices
- ZenDMD Tip - Add Roles to Users in a jiffy
- ZenDMD Tip - Audit Transforms
- ZenDMD Tip - Audit Triggers and Notifications
- ZenDMD Tip - Audit Users
- ZenDMD Tip - Bulk Device Removal
- ZenDMD Tip - Change Interface Speed
- ZenDMD Tip - Check and Repair Device Objects with Missing DeviceClass
- ZenDMD Tip - Create Users in a Jiffy
- ZenDMD Tip - Dump zProperties values for a Device
- ZenDMD Tip - Fix Broken Graph Report Elements
- ZenDMD Tip - Fix Broken Muiltigraph Collections
- ZenDMD Tip - Fix Duplicate Property Refs
- ZenDMD Tip - Manipulate Events
- ZenDMD Tip - Move Devices to Proper Device Class
- ZenDMD Tip - Move Products to Proper Manufacturer
- ZenDMD Tip - Quickly Audit Enterprise Collectors
- ZenDMD Tip - Recreate Device Rels
- ZenDMD Tip - Refresh DeviceSearch Catalog
- ZenDMD Tip - Remove Invalid Devices from Collectors
- ZenDMD Tip - Remove all MIBS
- ZenDMD Tip - Removing Local Templates
- ZenDMD Tip - Rename Devices
- ZenDMD Tip - Replace modeler plugin programmatically
- ZenDMD Tip - Set Titles via Reverse Lookup (PTR record)
- ZenDMD Tip - ShowAllTransforms
- ZenDMD Tip - ShowEventMappingsAndTransforms
- ZenDMD Tip - Test & Delete Overrides
- ZenDMD Tip - Zet manageIp via Host Lookup (A record)
- ZenDMD Tip Renaming Modifying Device Properties
- ZenDMD Tips
- ZenDMD Tips - Impact
ZenDMD configuration file
If you often have to access some objects in zendmd, or write shortcut functions or test data, you could create script that does this for you, and then runs interactive bpython or ipython session like this:
try: # try to do some imports from ZenPacks.zenoss.Layer2.connections_catalog import CatalogAPI # create some objects cat = CatalogAPI(zport) # create some shortcuts def gc(x): ''' get entities connected to entity x ''' return list(cat.get_connected(x)) except ImportError, e: print e # initialize some variables devices = dmd.Devices.getSubDevices() import bpython; bpython.embed(locals())
Save this file for example in ~/bzendmd.py
and add following alias in .bashrc
:
alias dmd="zendmd --script=/home/zenoss/bzendmd.py"
Now you could start your custom interactive environment using command dmd
.