简体   繁体   English

Zabbix 模板触发器表达式引用另一个模板中的项目

[英]Zabbix template trigger expression referencing a item from another template

I'm having trouble thinking and implementing a way to do the following:我在思考和实施以下方法时遇到了麻烦:

I have a systemd monitoring template which has 2 main triggers for any given discovered service.我有一个 systemd 监控模板,它有 2 个主要触发器用于任何给定的发现服务。 "The service has restarted" or "The service is not running". “服务已重新启动”或“服务未运行”。 When a given host restarts, every single service trigger kicks off with an alert saying "service has restarted".当给定的主机重新启动时,每个服务触发器都会以“服务已重新启动”的警报开始。 This makes sense, the host restarts, so do the services.这是有道理的,主机重新启动,服务也重新启动。

My goal is to prevent the service trigger alerts from being generated if the host uptime is less than 10 minutes (the default timer for the "host restarted" trigger).我的目标是防止在主机正常运行时间少于 10 分钟时生成服务触发器警报(“主机重新启动”触发器的默认计时器)。 In other words, "Service has restarted" trigger should only be generated when the host uptime is more than 10 minutes.换言之,“服务已重新启动”触发器应仅在主机正常运行时间超过 10 分钟时生成。

So my initial thoughts were to use trigger dependencies, but those only create a dependency off another trigger.所以我最初的想法是使用触发器依赖项,但那些只会创建另一个触发器的依赖项。 So I wouldn't want my "service has restarted" trigger to activate if the "host has restarted" trigger was also activated (thats the opposite of what I want).因此,如果“主机已重新启动”触发器也被激活(这与我想要的相反),我不希望我的“服务已重新启动”触发器激活。 And as far as I am aware, the trigger dependencies do not have a "negate" or "not" function/operator built into them.据我所知,触发器依赖项没有内置的“否定”或“非”函数/运算符。 So I couldn't say something like: "This trigger can only activate if this other trigger is currently inactive."所以我不能说这样的话:“这个触发器只有在另一个触发器当前不活动时才能激活。”

So my next thought was to edit the template discovery trigger prototype expression and change it from the following: last(/Systemd by Zabbix agent 2/systemd.service.uptime["{#UNIT.NAME}"])<10m to something like last(system.uptime)>10m AND last(/Systemd by Zabbix agent 2/systemd.service.uptime["{#UNIT.NAME}"])<10m .所以我的下一个想法是编辑模板发现触发器原型表达式并将其从以下内容更改: last(/Systemd by Zabbix agent 2/systemd.service.uptime["{#UNIT.NAME}"])<10m到类似last(system.uptime)>10m AND last(/Systemd by Zabbix agent 2/systemd.service.uptime["{#UNIT.NAME}"])<10m This isn't exact syntax, just the rough idea of what I was thinking of.这不是确切的语法,只是我在想什么的粗略概念。

The problem is when I try to do the expression editor and include the item from another template, is errors out with:问题是当我尝试执行表达式编辑器并包含另一个模板中的项目时,是否会出现以下错误:

Trigger prototype "{#UNIT.NAME}: has been restarted" belongs to templates with different linkages.

I assume that it wont let me link a prototype trigger with another templates item?我假设它不会让我将原型触发器与另一个模板项链接起来?

I am using the default "Linux Generic by Zabbix Agent" Template, and the following template for systemd: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/app/systemd?at=release/6.0我正在使用默认的“Linux Generic by Zabbix Agent”模板,以及 systemd 的以下模板: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/app/systemd?at=release /6.0

Overall, I definitely don't want to be going around to every host and creating custom triggers for every single service that compares the host uptime with the systemd service uptime.总体而言,我绝对不想绕过每个主机并为每个服务创建自定义触发器,将主机正常运行时间与 systemd 服务正常运行时间进行比较。 Maybe I could move the system.uptime template item from the "Generic Linux Template" to the Systemd template, but thats rather brute force.也许我可以将 system.uptime 模板项从“通用 Linux 模板”移动到 Systemd 模板,但那是相当蛮力的。

Anyone got an ideas for what to do here?有人对在这里做什么有想法吗? Any better ways to solve my problem?有没有更好的方法来解决我的问题?

You may use items from different templates in triggers that are in another template.您可以在另一个模板中的触发器中使用来自不同模板的项目。 BUT the item templates need to be linked to the trigger template.但是项目模板需要链接到触发器模板。

So in your case, you should do:所以在你的情况下,你应该这样做:

  • create a new, empty XYZ Template创建一个新的空 XYZ 模板
  • link Generic Linux Template and Systemd Template to your XYZ template将通用 Linux 模板和 Systemd 模板链接到您的 XYZ 模板
  • now you can create triggers in your XYZ template that utilizes items from Generic Linux Template and Systemd Template现在您可以在 XYZ 模板中创建触发器,该模板利用 Generic Linux 模板和 Systemd 模板中的项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM