Scripting around the export

While manually making a single change to an exported file can be handy, it's the large changes that expose the benefit of this approach best. As the most simple approach to creating an XML file, we can use shell scripts.

For example, if we had to add a lot of similar items, we could script an XML file with them all and import them in one go. The easiest approach would be to create some items in the frontend, export that host, and write a quick script that loops over these item definitions and creates the remaining items. The same can be done for triggers and custom graphs as well. Again, it's best to create all data for a single element, export it, and examine it to find out how it should be put back together.

Unless individual entities are to be modifiable, consider using a custom Low-Level Discovery (LLD) rule, as covered in Chapter 11, Automating Configuration.

Other larger-scale problems that can be solved by an XML round-trip are the following:

  • Adding lots of devices: If you're given a large list of switches with IP addresses, adding them all through the interface is a monstrous task. With XML, it becomes a very easy and quick one instead. To do that, simply create a single host, linked against the previously created template or several ones, and then export it to get some sort of a template. In this export, you'll basically have to change a couple of values only—notably, the connection details in the <interfaces> element. Then, just proceed to create a loop that creates new <host> entries with the corresponding IP and hostname data. Note that it's enough to only specify host information in this file—all items, triggers, graphs, and other entities will be attached based on the information that's contained in the template or templates specified in the <templates> block.
  • Creating many graphs with lots of arbitrary items: Sometimes, it might be required to create not only one graph per port, but also graphs grouping items from several devices and other arbitrary collections. Export an example host and script graph items in a loop. These are located in the <graph_elements> block.
A graph with a huge number of items can soon become unreadable. Don't overdo items on a single graph.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.186.164