Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Chapter 7 configuration and Management of templates

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Chapter VII template configuration and Management

We can add not only a lot of indicators (that is, monitoring items) that need to be monitored to the host, but also graphics, triggers, monitoring item groups, display screen, Web scenarios and low-level Discovery. If we add these objects in each host, especially in a large environment, the workload is unimaginable, not to mention that many hosts that need to be monitored have the same monitoring attributes and need to repeat the same configuration work. It is almost impossible to complete these configuration tasks manually. Fortunately, Zabbix provides us with templates that can be applied to any number of hosts by adding monitoring items, triggers, graphics, etc., to different templates. Of course, for special monitoring needs, monitoring items, triggers, graphics and so on can still be added separately in the host computer, and the two can be used together.

Using the template will bring us great convenience. Suppose we need to modify the settings of some monitoring items on all hosts. In the template, we only need to modify it once, and it will take effect on all hosts connected to the template. Therefore, the use of templates can simplify the configuration of Zabbix and greatly reduce the workload of operation and maintenance.

Recently, we have completed the recording and release of the video tutorial "zabbix 4.0", which is based on zabbix 4.2 and provides a comprehensive explanation of Zabbix. Welcome to watch. Course link: https://edu.51cto.com/sd/ce000

7.1 create a template

The content of the template is very similar to the host, including some monitoring items that need to be monitored, as well as triggers, graphics, display screen, Discovery and so on. Each template needs to have a unique name and can belong to one or more host groups. But the difference between the two is that the host can provide a variety of ways to communicate with Zabbix server, such as using one or more ip addresses or DNS hostnames to communicate with Zabbix server. The host, as a monitoring object, submits data to Zabbix server through agent, SNMP, JMX or IPME interfaces. Templates do not have any access interfaces, so Zabbix server does not collect data through templates.

Creating a template is very simple. In the Configuration-- > Templates page, click the Create template button in the upper right corner. Then we can see that there are three different tags in the template configuration page, namely Template, LinkedTemplates and Macros, of which the LinkedTemplates tag and the Macros tag we will describe later in this chapter, you can not configure the parameters in the LinkedTemplates and Macros tags in a basic template.

In fact, you only need to configure a name to configure the most basic template. You can add a template to one or more host groups, or you can assign a template directly to a host. Let's take a look at the template configuration page, as shown in figure 7-1 below.

Figure 7-1

The parameters in the Template tag page have the following meanings:

Template name: unique template name.

Visible name: after setting the name, the name will be displayed in the page list, topology diagram, etc. This parameter supports UTF-8, where you can set the Chinese name.

Groups: the host group or template group to which the template belongs.

New group: create a group to which the template belongs while creating the template.

Hosts/Templates: a list of hosts or templates linked to the template.

Description: description of the template.

7.2 add monitoring items to the template

The method of adding monitoring items to the template is almost the same as adding it to the host. You cannot specify any type of IP or interface when adding monitoring items. Zabbix automatically collects interface information when the template is linked to a host that needs to be monitored. When you need to add triggers, graphics, and other projects, you must reference the monitoring items that have been created. Here, you need to make sure that the referenced monitoring items already exist in the template.

We can add the following to the template:

Monitoring item

Trigger

Graphics

Monitoring item group

Display screen

Low-level Discovery rules

Web scenarios

7.3 Macro variables used in templates 7.3.1 {HOST.*} Macro variables

You will often use the following host-related macro variables in the template.

{HOST.CONN}: refers to the host name or IP address of the host. The options based on the host configuration are equivalent to {HOST.IP} or {HOST.DNS}.

{HOST.DNS}: the host name that references the host. Must be the full domain name (FQDN) set in the DNS server.

{HOST.HOST}: the Host name (host name) that references the host defined in Zabbix. This is the primary host identifier, and it must be unique in Zabbix server. If you use agent in a host, you must set the same host name in the agent configuration file.

{HOST.IP}: refers to the IP address of the host. A host may have multiple IP addresses. You can use {HOST.IP1}, {HOST.IP2}, … {HOST.IP9} .

{HOST.NAME}: the visible name that references the host defined in Zabbix. The name is displayed in the list of pages, topology diagrams, and so on.

The host-related macro variables mentioned above can be understood more clearly through the figure below. This is shown in figure 7-2 below.

Figure 7-2

In figure 7-2 above, {HOST.HOST} resolves to example host name, {HOST.NAME} to example visible name, {HOST.IP} to 127.0.0.1, {HOST.DNS} to zabbix.example.com, and {HOST.CONN} to 127.0.0.1 based on the options of Connect to.

These macro variables are often used in triggers and drawing names. when using the drawing name as the title, you can dynamically match the actual host information through the reference of the macro variable and distinguish the graphics of the same type but different hosts. Especially when it's displayed on the screen at the same time.

These macro variables are rarely used in the definition of Key, but in Externalchecks monitoring items, {HOST.CONN}, {HOST.IP} and so on are often used as parameters of script files, so that scripts can be executed on multiple hosts at the same time to accomplish the same task.

7.3.2 Custom Macro variables

Macro variables can be customized at the template and host level, and we can configure macro variables in the Macros tab on the template configuration page. This is shown in figure 7-3 below.

Figure 7-3

To define macro variables in a template, the common use is to set common thresholds for use in triggers. When monitoring items or triggers in a template use custom macro variables, it is also best to set this macro variable in the template, so as to avoid the problem of whether the relevant macro variables are correctly configured when the template is exported to other Zabbix systems.

7.4 Link template to host

In the Template tab of the template configuration page, you can select the host to which the template is linked, or you can select the template you want to link to in the Template tab of the host configuration page, either way.

When the template is linked to the host, the host inherits all the monitoring items, triggers, macro variables added to the template, and will be overwritten if there are previously configured monitoring items, triggers, etc. on the host with the same name. Monitoring items, triggers, and so on that are not defined in the template will be retained.

If you modify the configuration of monitoring items, triggers, etc., in the template, the results of the changes will immediately take effect in all linked hosts. If you only modify the configuration inherited from the template in a host, it will only take effect on that host and will not affect the configuration in the template. It is not recommended to modify the configuration inherited from the template on the host, because there are few configuration parameters you can modify, only individual options can be modified, such as the Update interval property in the monitoring item.

When you Unlink a template from a host, unlinking does not delete monitoring items, triggers, and so on inherited from the template from the host. If you use Unlink and clear, unlinking removes all monitoring items, triggers, and so on inherited from the template, which may make the historical and trend data of all monitoring items unavailable. Therefore, it is recommended to use the Unlink method to unconnect the template, and then disable all unused monitoring items and triggers on the host, so that all their historical data can be retained at the same time.

7.5 nested templates

In Zabbix, we can link templates to hosts, or we can link one template to other templates. This is equivalent to linking an existing template to the host. We can add a link to the Linked templates tab of the template configuration page, as shown in figure 7-4 below.

Figure 7-4

Enter the name of the template in Link new templates or click the Select button to select the template you want to link from the pop-up template list page, and then click the Add button to add.

If you want to delete a linked template, click Unlink or Unlink and clear in the ACTION column to the right of the corresponding template name in Linked templates.

Let's take a look at the use of nested templates.

More flexible definition of macro variables

Because the template inherits the configuration from all link templates, including macro variables, we can set more flexible and generic macro variables. For example, we create a template named Template Macros and configure a {$PFREE} macro variable that uses the value of this macro as a threshold to monitor the percentage of remaining disk space, free memory, and so on. This template can be linked to TemplateOS Linux and TemplateOS Windows templates and use {$PFREE} in these templates. If you need to modify the threshold that monitors the percentage of remaining disk space or the remaining available memory, you only need to modify it in the Template Macros template, and the new threshold will take effect on the host through the linked template.

Define multi-level templates

In the real environment, we will use a large number of servers of the same brand or even the same configuration, but install different operating systems (such as Linux, Windows) or different versions, and complete different functions such as database server, file server, web server and so on. You can create several separate templates, such as monitoring hardware templates, monitoring operating system templates, monitoring specific application templates, and so on. Templates for monitoring hardware can be linked to multiple templates for monitoring operating systems, while templates for monitoring operating systems can be linked to templates for monitoring specific applications. The advantage of this is that the newly created host only needs to link to a template. You have the flexibility to create new templates and nest them, and when you need to modify them, you only need to modify them in one place to take effect in the entire nested template chain.

7.6 Import and export templates

Zabbix not only provides import and export functions for templates, but also imports and exports the following objects:

Templates: includes all monitoring items, triggers, graphics, display screens, discovery rules, and template links that are added directly to the template.

Host: includes all directly added monitoring items, triggers, graphics, display screens, discovery rules and template links.

Topology diagram: includes all relevant p_w_picpaths.

Image

Display screen

Value mapping

Host group (only through ZabbixAPI)

It is easy to export a template. Select the template you want to export on the template list page and click the Export button, as shown in figure 7-5 below.

Figure 7-5

Zabbix exports all supported objects to a file. Monitoring items and triggers in hosts or nested templates will not be exported, and monitoring items and triggers in nested templates will be recreated when imported. Triggers that create or rely on low-leveldiscovery projects through low-leveldiscovery are not exported. Triggers and graphics that use web monitoring items are also not exported.

Click the Import button in the upper right corner of the Configuration-- > Templates page to enter the import page, as shown in figure 7-6 below.

Figure 7-6

On the import page, select the template file that you want to import in the Import file field. In Rules, we can see three columns: UPDATE EXISTING, CREATE NEW, and DELETE MISSING. Let's take a look at what these three columns mean:

Update existing: force an update if the imported object already exists and can be used to update or simply add missing objects.

Create new: create a new object.

Delete missing: objects that do not exist in the import file will be deleted.

This article is from http://ustogether.blog.51cto.com/8236854/1928287. If you need to reprint it, please contact the author.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report