4 在信息中使用宏

4 Using macros in messages

概述

Overview

在消息主题和消息文本中,您可以使用宏来更有效的问题报告。

In message subjects and message text you can use macros for more efficient problem reporting.

由Zabbix提供支持完整的宏列表

A full list of macros supported by Zabbix is available.

示例

Examples

这里的例子说明了如何在消息中使用宏。

Examples here illustrate how you can use macros in messages.

示例 1

Message subject:

  1. {TRIGGER.NAME}: {TRIGGER.STATUS}
Example 1

Message subject:

  1. Problem: {TRIGGER.NAME}

收到消息后,消息主题将被替换为:

When you receive the message, the message subject will be replaced by something like:

  1. zabbix.zabbix.com服务器上的处理器负载太高: PROBLEM
  2. Problem: Processor load is too high on Zabbix server
示例 2

Message:

  1. Processor load is: {zabbix.zabbix.com:system.cpu.load[,avg1].last()}

收到消息后,消息主题将被替换为:

  1. Processor load is: 1.45
Example 2

Message:

  1. Processor load is: {zabbix.zabbix.com:system.cpu.load[,avg1].last()}

When you receive the message, the message will be replaced by something like:

  1. Processor load is: 1.45
示例E 3

Message:

  1. Latest value: {{HOST.HOST}:{ITEM.KEY}.last()}
  2. MAX for 15 minutes: {{HOST.HOST}:{ITEM.KEY}.max(900)}
  3. MIN for 15 minutes: {{HOST.HOST}:{ITEM.KEY}.min(900)}
Example 3

Message:

  1. Latest value: {{HOST.HOST}:{ITEM.KEY}.last()}
  2. MAX for 15 minutes: {{HOST.HOST}:{ITEM.KEY}.max(900)}
  3. MIN for 15 minutes: {{HOST.HOST}:{ITEM.KEY}.min(900)}

收到消息时,消息将被替换为:

When you receive the message, the message will be replaced by something like:

  1. Latest value: 1.45
  2. MAX for 15 minutes: 2.33
  3. MIN for 15 minutes: 1.01
  4. Latest value: 1.45
  5. MAX for 15 minutes: 2.33
  6. MIN for 15 minutes: 1.01
示例 4

Message:

  1. http://<server_ip_or_name>/zabbix/events.php?triggerid={TRIGGER.ID}&filter_set=1
Example 4

Message:

  1. http://<server_ip_or_name>/zabbix/events.php?triggerid={TRIGGER.ID}&filter_set=1

收到消息时,它将包含一个有所有问题触发的事情的链接。

When you receive the message, it will contain a link to all events of the problem trigger.

示例 5

Informing about values from several hosts in a trigger expression.

Message:

  1. Trigger: {TRIGGER.NAME}
  2. Trigger expression: {TRIGGER.EXPRESSION}
  3. 1. Item value on {HOST.NAME1}: {ITEM.VALUE1} ({ITEM.NAME1})
  4. 2. Item value on {HOST.NAME2}: {ITEM.VALUE2} ({ITEM.NAME2})
Example 5

Informing about values from several hosts in a trigger expression.

Message:

  1. Problem name: {TRIGGER.NAME}
  2. Trigger expression: {TRIGGER.EXPRESSION}
  3. 1. Item value on {HOST.NAME1}: {ITEM.VALUE1} ({ITEM.NAME1})
  4. 2. Item value on {HOST.NAME2}: {ITEM.VALUE2} ({ITEM.NAME2})

收到消息时,消息将被替换为:

When you receive the message, the message will be replaced by something like:

  1. Problem name: Processor load is too high on a local host
  2. Trigger expression: {Myhost:system.cpu.load[percpu,avg1].last()}>5 | {Myotherhost:system.cpu.load[percpu,avg1].last()}>5
  3. 1. Item value on Myhost: 0.83 (Processor load (1 min average per core))
  4. 2. Item value on Myotherhost: 5.125 (Processor load (1 min average per core))
  5. Problem name: Processor load is too high on a local host
  6. Trigger expression: {Myhost:system.cpu.load[percpu,avg1].last()}>5 | {Myotherhost:system.cpu.load[percpu,avg1].last()}>5
  7. 1. Item value on Myhost: 0.83 (Processor load (1 min average per core))
  8. 2. Item value on Myotherhost: 5.125 (Processor load (1 min average per core))
示例6

Receiving details of both the problem event and recovery event in a recovery message:

Message:

  1. Problem:
  2. Event ID: {EVENT.ID}
  3. Event value: {EVENT.VALUE}
  4. Event status: {EVENT.STATUS}
  5. Event time: {EVENT.TIME}
  6. Event date: {EVENT.DATE}
  7. Event age: {EVENT.AGE}
  8. Event acknowledgement: {EVENT.ACK.STATUS}
  9. Event acknowledgement history: {EVENT.ACK.HISTORY}
  10. Recovery:
  11. Event ID: {EVENT.RECOVERY.ID}
  12. Event value: {EVENT.RECOVERY.VALUE}
  13. Event status: {EVENT.RECOVERY.STATUS}
  14. Event time: {EVENT.RECOVERY.TIME}
  15. Event date: {EVENT.RECOVERY.DATE}
Example 6

Receiving details of both the problem event and recovery event in a recovery message:

Message:

  1. Problem:
  2. Event ID: {EVENT.ID}
  3. Event value: {EVENT.VALUE}
  4. Event status: {EVENT.STATUS}
  5. Event time: {EVENT.TIME}
  6. Event date: {EVENT.DATE}
  7. Event age: {EVENT.AGE}
  8. Event acknowledgement: {EVENT.ACK.STATUS}
  9. Event update history: {EVENT.UPDATE.HISTORY}
  10. Recovery:
  11. Event ID: {EVENT.RECOVERY.ID}
  12. Event value: {EVENT.RECOVERY.VALUE}
  13. Event status: {EVENT.RECOVERY.STATUS}
  14. Event time: {EVENT.RECOVERY.TIME}
  15. Event date: {EVENT.RECOVERY.DATE}

收到消息时,消息将被替换为:

When you receive the message, the macros will be replaced by something like:

  1. Problem:
  2. Event ID: 21874
  3. Event value: 1
  4. Event status: PROBLEM
  5. Event time: 13:04:30
  6. Event date: 2018.01.02
  7. Event age: 5m
  8. Event acknowledgement: Yes
  9. Event update history: 2018.01.02 13:05:51 "John Smith (Admin)"
  10. Actions: acknowledged.
  11. Recovery:
  12. Event ID: 21896
  13. Event value: 0
  14. Event status: OK
  15. Event time: 13:10:07
  16. Event date: 2018.01.02
  17. Problem:
  18. Event ID: 21874
  19. Event value: 1
  20. Event status: PROBLEM
  21. Event time: 13:04:30
  22. Event date: 2018.01.02
  23. Event age: 5m
  24. Event acknowledgement: Yes
  25. Event update history: 2018.01.02 13:05:51 "John Smith (Admin)"
  26. Actions: acknowledged.
  27. Recovery:
  28. Event ID: 21896
  29. Event value: 0
  30. Event status: OK
  31. Event time: 13:10:07
  32. Event date: 2018.01.02

Zabbix 2.2.0之后支持把原始问题事件和恢复事件使用的通知宏分离开。

Separate notification macros for the original problem event and recovery event are supported since Zabbix 2.2.0.