Wiki do Tiozão do Linux

Interesting Zabbix Templates

Some templates that I use frequently

Here are some Zabbix templates that I use

TCP Port Monitoring (DNS, LDAP, HTTP, etc.)

Although it is very simple to monitor ports using simple_checks as per the official documentation (https://www.zabbix.com/documentation/current/en/manual/config/items/itemtypes/simple_checks), I prefer to have a template that simplifies monitoring, simply by adding the template to the host.

Checks if a service is running and accepting TCP connections. Checks the performance of a TCP service.
Advantages - use of MACROS ( SERVICE.NAME DEFAULT.PORT MAX.COUNT ) which facilitate configurations.

Steps:
(1) Create the check-tcp-port-template.yml file with the template content bellow
(2) Import it into Zabbix (Data Collection -> Templates -> Import).
(3) Create a host and associate it with the template.

cat << '_EOF_' > check-tcp-port-template.yml
zabbix_export:
  version: '7.0'
  template_groups:
    - uuid: 7df96b18c230490a9a0a9e2307226338
      name: Templates
  templates:
    - uuid: f1fe24ae65bd4a1dbf6d03a6897f5199
      template: '-- Check TCP Port'
      name: '-- Check TCP Port'
      description: 'Check {$SERVICE.NAME} service using https://www.zabbix.com/documentation/current/en/manual/config/items/itemtypes/simple_checks'
      groups:
        - name: Templates
      items:
        - uuid: 87eced0e6b684d07a5c9add57c9621c4
          name: 'Check {$SERVICE.NAME} Performance'
          type: SIMPLE
          key: 'net.tcp.service.perf[tcp,{HOST.HOST},{$DEFAULT.PORT}]'
          history: 90d
          value_type: FLOAT
          tags:
            - tag: component
              value: tcp
        - uuid: 5a5ba1d675494e79aa43f8dfa5b21698
          name: 'Check {$SERVICE.NAME} Service'
          type: SIMPLE
          key: 'net.tcp.service[tcp,{HOST.HOST},{$DEFAULT.PORT}]'
          history: 90d
          valuemap:
            name: Status
          tags:
            - tag: component
              value: tcp
          triggers:
            - uuid: e8669b9252f042ada105b429c59e419b
              expression: 'sum(/-- Check TCP Port/net.tcp.service[tcp,{HOST.HOST},{$DEFAULT.PORT}],{$MAX.COUNT})=0'
              name: 'Service {$SERVICE.NAME} failed ( in the last {$MAX.COUNT} checks )'
              priority: HIGH
              description: 'Connection to {$SERVICE.NAME}  server failed in the last {$MAX.COUNT} checks'
              tags:
                - tag: component
                  value: '{$SERVICE.NAME}'
      tags:
        - tag: component
          value: tcp
      macros:
        - macro: '{$DEFAULT.PORT}'
          value: '80'
          description: 'Default TCP Port'
        - macro: '{$MAX.COUNT}'
          value: '#1'
          description: 'How many checks failed before alert is issued'
        - macro: '{$SERVICE.NAME}'
          value: HTTP
          description: 'Name of Service (HTTP|DNS|LDAP)'
      valuemaps:
        - uuid: 06aafce65d7743ab9289590daa460e15
          name: Status
          mappings:
            - value: '1'
              newvalue: 'ON'
            - type: DEFAULT
              newvalue: 'OFF'
  graphs:
    - uuid: 51f9f2dd20b7423581520ecfe9d08cf3
      name: 'Performance {$SERVICE.NAME}'
      graph_items:
        - color: 1A7C11
          calc_fnc: ALL
          item:
            host: '-- Check TCP Port'
            key: 'net.tcp.service.perf[tcp,{HOST.HOST},{$DEFAULT.PORT}]'
_EOF_

Search IP Address of FQDN

Useful for identifying when an FQDN has its IP address changed.

Steps:
(1) Save the script on your Zabbix Server (make sure you are logged in as root)
(2) Create the ip-address-template.yml file with the template content bellow
(3) Import it into Zabbix (Data Collection -> Templates -> Import).
(4) Create a host and associate it with the template.

cat << '_EOF_' > /usr/lib/zabbix/externalscripts/what-is-ip-address-using-host.sh
#!/bin/bash
# Search IP address of fqdn using:
#	Google:     8.8.8.8 8.8.4.4
#	Cloudflare: 1.1.1.1 1.0.0.1
#	Quad9:		  9.9.9.9 149.112.112.112
#	AdGuard:	  94.140.14.14 94.140.14.15
#
# 31/Ago/2024 - jarbas.junior@gmail.com - Initial implementation
# 24/Out/2025 - add second parameter

if [ $# -ne 2 ]; then
        echo "usage: $0 fqdn ip.public.dns.host"
        exit 1
fi

host "$1" "$2" | awk '/has address|has IPv6 address/ {print $NF}' | sort -Vu
_EOF_
cat << '_EOF_' > ip-address-template.yml
zabbix_export:
  version: '7.0'
  template_groups:
    - uuid: 7df96b18c230490a9a0a9e2307226338
      name: Templates
  templates:
    - uuid: e0e83bbd7adb416e85aa68cbcc933291
      template: '-- IP Address of the FQDN'
      name: '-- IP Address of the FQDN'
      description: |
        Search from  {HOST.HOST} using Public DNS
        
        May be:
        
        Google: 8.8.8.8 8.8.4.4
        Cloudflare: 1.1.1.1 1.0.0.1
        Quad9: 9.9.9.9 149.112.112.112
        AdGuard: 94.140.14.14 94.140.14.15
      groups:
        - name: Templates
      items:
        - uuid: 6c1bfe00824c4ad8baff52fb92a48d02
          name: 'Get IPs of the FQDN'
          type: EXTERNAL
          key: 'what-is-ip-address-using-host.sh[{HOST.HOST},{$PUBLIC_DNS_SERVER}]'
          history: 1d
          value_type: CHAR
          trends: '0'
          preprocessing:
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1d
          tags:
            - tag: component
              value: 'public dns'
          triggers:
            - uuid: e1d0dbbf64b64fae81514c370af8ad42
              expression: |
                last(/-- IP Address of the FQDN/what-is-ip-address-using-host.sh[{HOST.HOST},{$PUBLIC_DNS_SERVER}],#1)
                <>
                last(/-- IP Address of the FQDN/what-is-ip-address-using-host.sh[{HOST.HOST},{$PUBLIC_DNS_SERVER}],#2)
              recovery_mode: NONE
              name: 'IP Changed - Was {FUNCTION.VALUE2}'
              opdata: 'Now: {ITEM.LASTVALUE}'
              priority: INFO
              description: 'IP returned by Public DNS {$PUBLIC_DNS_SERVER}'
              manual_close: 'YES'
              tags:
                - tag: 'ip by public dns'
                  value: '{$PUBLIC_DNS_SERVER}'
      tags:
        - tag: component
          value: 'public dns'
      macros:
        - macro: '{$PUBLIC_DNS_SERVER}'
          value: 8.8.8.8
          description: 'Public DNS Server'
_EOF_

Monitoring HTTP Services

Zabbix Web Scenarios allow you to test web applications by executing sequential HTTP requests. It tracks response times, download speeds, and HTTP response

Although it is very simple to monitor as official documentation https://www.zabbix.com/documentation/current/en/manual/web_monitoring, I prefer to have a template that simplifies monitoring, simply by adding the template to the host.

Advantages - use of MACROS which facilitate configurations:

MACRO Default Value Description
{$MAX_FAILURES} 2 Maximum number of consecutive failures
{$MAX_RESPONSE_TIME} 2.000 Values in milliseconds
{$TIME_PERIOD} 5m Values in minutes
{$WEB_DEFAULT_PORT} 80 Default port used
{$WEB_DEFAULT_PROTOCOL} http:// Default protocol used

Steps:
(1) Create the monitoring-http-template.yml file with the template content bellow
(2) Import it into Zabbix (Data Collection -> Templates -> Import).
(3) Create a host and associate it with the template.

cat << '_EOF_' > monitoring-http-template.yml
zabbix_export:
  version: '7.0'
  template_groups:
    - uuid: 566a463e6dd2432380b5101d8288899d
      name: SITES
  templates:
    - uuid: 9904c3dbb30146e8a38e257375cb2f13
      template: '-- Web Monitoring'
      name: '-- Web Monitoring'
      description: |
        Monitoring HTTP Services
        
        Status codes: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
      groups:
        - name: SITES
      httptests:
        - uuid: 9cef93b90c12443caca941dd7f9a5a10
          name: 'Website Availability'
          attempts: '3'
          agent: 'Zabbix da Imagetech - https://www.grupoimagetech.com.br'
          steps:
            - name: 'Home Page'
              url: '{$WEB_DEFAULT_PROTOCOL}{HOST.HOST}:{$WEB_DEFAULT_PORT}'
              status_codes: '200,403'
          tags:
            - tag: component
              value: web
      tags:
        - tag: component
          value: monitoring
        - tag: component
          value: web
      macros:
        - macro: '{$MAX_FAILURES}'
          value: '2'
          description: 'Maximum number of consecutive failures'
        - macro: '{$MAX_RESPONSE_TIME}'
          value: '2.000'
          description: 'Values ​​in milliseconds'
        - macro: '{$TIME_PERIOD}'
          value: 5m
          description: 'Values ​​in minutes'
        - macro: '{$WEB_DEFAULT_PORT}'
          value: '80'
          description: 'Default port used'
        - macro: '{$WEB_DEFAULT_PROTOCOL}'
          value: 'http://'
          description: 'Default protocol used'
      valuemaps:
        - uuid: b904e9844fbf43d9a0a01be00bcc5136
          name: 'response code'
          mappings:
            - value: '0'
              newvalue: 'On'
            - type: GREATER_OR_EQUAL
              value: '1'
              newvalue: Down
  triggers:
    - uuid: 16bccfda06ce4f7a9cb1d6e3459035e2
      expression: 'avg(/-- Web Monitoring/web.test.time[Website Availability,Home Page,resp],{$TIME_PERIOD})>{$MAX_RESPONSE_TIME}'
      name: 'Accessing the website is slow'
      event_name: 'Website {HOST.HOST} is slow for {$TIME_PERIOD}'
      opdata: 'Problem: {ITEM.VALUE1} Now: {ITEM.LASTVALUE}'
      priority: WARNING
      description: 'Access to the website is slow'
      manual_close: 'YES'
      dependencies:
        - name: 'Accessing the website is VERY slow'
          expression: 'avg(/-- Web Monitoring/web.test.time[Website Availability,Home Page,resp],{$TIME_PERIOD})>3*{$MAX_RESPONSE_TIME}'
    - uuid: 0b473201809b492eafd2d661034e1f13
      expression: 'avg(/-- Web Monitoring/web.test.time[Website Availability,Home Page,resp],{$TIME_PERIOD})>3*{$MAX_RESPONSE_TIME}'
      name: 'Accessing the website is VERY slow'
      event_name: 'Website {HOST.HOST} is VERY slow for {$TIME_PERIOD}'
      opdata: 'Problem: {ITEM.VALUE1} Now: {ITEM.LASTVALUE}'
      priority: AVERAGE
      description: 'Accessing the website is VERY slow'
      manual_close: 'YES'
      dependencies:
        - name: 'Access to the website FAILED'
          expression: 'sum(/-- Web Monitoring/web.test.fail[Website Availability],{$TIME_PERIOD})>={$MAX_FAILURES}'
    - uuid: c63b0624536f4e1abfe233116aab42d7
      expression: 'sum(/-- Web Monitoring/web.test.fail[Website Availability],{$TIME_PERIOD})>={$MAX_FAILURES}'
      name: 'Access to the website FAILED'
      event_name: 'Website {HOST.HOST} failed {$MAX_FAILURES} times in {$TIME_PERIOD}'
      priority: DISASTER
      description: 'Access to the website FAILED {$MAX_FAILURES} times'
      manual_close: 'YES'
_EOF_

References

  1. DNS Monitoring in Zabbix 7.0 - https://youtu.be/ADl4ZqMh35A?si=0swBKkguM9ZM7wEX&t=431
  2. net.dns - https://www.zabbix.com/documentation/7.4/en/manual/config/items/itemtypes/zabbix_agent#net.dns
  3. net.dns.perf - https://www.zabbix.com/documentation/7.4/en/manual/config/items/itemtypes/zabbix_agent#net.dns.perf
  4. net.dns.record - https://www.zabbix.com/documentation/7.4/en/manual/config/items/itemtypes/zabbix_agent#net.dns.record
  5. net.dns.get - https://www.zabbix.com/documentation/7.4/en/manual/config/items/itemtypes/zabbix_agent/zabbix_agent2?hl=net.dns.record#net.dns.get
  6. Triggers - https://www.zabbix.com/documentation/current/en/manual/config/triggers/trigger
  7. Macros - https://www.zabbix.com/documentation/current/en/manual/appendix/macros/supported_by_location