Using multiple templates

There are two monitored hosts now, both having some services monitored and linked to the same template. Suddenly the situation changes and one of the hosts gets the responsibility of being an e-mail server removed. Our options from the Zabbix viewpoint include simply disabling e-mail related items for that host or creating a separate template for it and removing e-mail server related entities from the main template, instead leaving them on the other server. There's a better approach, though—splitting e-mail server related entities into a separate template.

Navigate to Configuration | Templates, then click on the Create template button. Enter C_Template_Email in the Template name field, mark Custom templates in the Other groups box, click on the

Using multiple templates

button, then click on Add:

Using multiple templates

Now let's populate this template—select Custom templates in the Group dropdown and click on Items next to C_Template_Linux. Mark the checkboxes next to SMTP server status and Testfile in the NAME column, then click on the Copy button at the bottom. In the next screen, select Templates in the Target type dropdown, and Custom templates in the Group dropdown, mark the checkbox next to C_Template_Email, then click on Copy.

That deals with the items, but there's still the triggers left. Click on Triggers in the navigation bar above the Items list, mark the checkboxes next to SMTP service is down and Testfile is missing in the NAME column, then click on the Copy button. In the next screen, again select Templates in the Target type dropdown, Custom templates in the Group dropdown and mark the checkbox next to C_Template_Email, then click on Copy.

Tip

We also have to pull in our test file item and trigger, as the SMTP trigger depends on the test file trigger. We could not copy the SMTP trigger as that would leave an unsatisfied dependency.

We now have a simple dedicated e-mail server template that we can link to the hosts. It has the same item and trigger regarding the SMTP service as our custom Linux template. There's a problem though—as they both have an item with the same key, we cannot link these templates to the same host, it would fail. Attempting to do so would probably result in a message like this:

Using multiple templates

We will perform some steps to change the template linkage:

  • Unlink C_Template_Linux from "A test host" and "Another host"
  • Remove SMTP related items and triggers from C_Template_Linux
  • Link C_Template_Email to them both
  • Link C_Template_Linux back to both hosts

This way SMTP related items and triggers will become templated from the e-mail template, while preserving all collected data. If we deleted those items from the Linux template and then linked in the e-mail template, we would also remove all collected values for those items.

Go to Configuration | Hosts, mark the checkboxes next to A test host and Another host, then click on Mass update. Switch to the Templates tab and mark the Link templates checkbox and the Replace checkbox. This will unlink the linked templates, but keep the previously templated entities as directly attached ones:

Using multiple templates

Tip

We will discuss host mass update in more detail later in this chapter.

Click on Update. Now we will modify the Linux template to remove SMTP related items and triggers. Navigate to Configuration | Templates, click on Items for C_Template_Linux and mark the checkboxes next to SMTP server status and Testfile exists in the NAME column. At the bottom, click on the Delete button and confirm the popup. If you expand the details, you will see that the triggers that were depending on these items got deleted, too—we did not have to delete them manually:

Using multiple templates

Now we are ready to link in our new e-mail template, and link back the modified Linux template. We can even do that in one step and we will again use the mass update function to do that. Go to Configuration | Hosts, mark the checkboxes next to A test host and Another host, then click on Mass update. Switch to the Templates tab, mark the Link templates checkbox, and type "C_" in the input field. Both of our templates will show up—click on one of them, then type "C_" again and click on the other template:

Using multiple templates

Click on the Update button. Take a look at the template linkage list in Configuration | Templates after this operation. Each of the custom templates now has two hosts linked:

Using multiple templates

A single host can be linked against multiple templates. This allows for a modular configuration where each template only provides a subset of entities, thus a server can be configured to have any combination of basic Linux, e-mail server, web server, file server, and any other templates.

Of course, with a single item and trigger this process seems too complex, but usually the e-mail server would have more parameters, such as mail server process counts, SMTP, IMAP, POP3 service status, spam and virus filter status, queue length, and many others. At that point the ability to quickly make a collection of metrics monitored on a machine with a couple of clicks is more than welcome.

Tip

The method with unlinking, redesigning and linking back is a common and suggested approach to changing template configuration. Just be careful not to change item keys while templates are unlinked or deleting items while they are linked.

Unlinking templates from hosts

But we talked about one server losing the e-mail server duties, and linking both templates to both hosts was not the correct operation, actually. Let's deal with that now. Open Configuration | Hosts and choose Linux servers in the Group dropdown. Our first test host will not be serving SMTP any more, so click on A test host in the NAME column and switch to the Templates tab:

Unlinking templates from hosts

This section properly lists two linked templates. We now want to unlink C_Template_Email, but there are two possible actions—Unlink and Unlink and clear. What's the difference then? Let's try it out and start with the one that looks safer—click on Unlink next to C_Template_Email, then click on Update. Expand the Details link to see what happened:

Unlinking templates from hosts

Both item and trigger got unlinked, so it seems. Was that what we wanted? Let's see. Click on Items next to A test host:

Unlinking templates from hosts

Well, not quite—SMTP related items are still there. So a simple unlink does unlinking only, and leaves a copy of the items on the previously linked host. That is handy if we want to create a different item or leave an item on the host to keep data for historical reasons, but not this time. To solve the current situation, we can manually delete both triggers and items, but that wouldn't be so easy if the host additionally had a bunch of directly attached entities. In that case, one would have to manually hunt them down and remove, which allows for mistakes to be made. Instead, let's try a different route—relink this template, then remove it without a trace.

Click on A test host in the navigation header and switch to the Templates tab. Start typing "C_" in the Link new templates field, then click on C_Template_Email. Carefully click on the small Add control just below it and then click on Update. Expanding the details will show the SMTP item and trigger getting linked to the template again. We are now back at our starting point with two templates linked—time to unlink again. Click on A test host in the NAME column and switch to the Templates tab. Click on Unlink and clear next to C_Template_Email in the Linked templates block and click on Update, then expand Details:

Unlinking templates from hosts

And now it's done. Both items and triggers are actually deleted. Look at the host list; notice how the TEMPLATES column again offers a quick overview—that comes in handy when you might want to quickly verify a template linkage for all the hosts in a particular group:

Unlinking templates from hosts
..................Content has been hidden....................

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