Have you recently updated your Zabbix environment but are still wondering – why haven’t the templates been updated? Where can I obtain the latest official Zabbix templates, and how should I update them? In this blog post, we will discuss why it is vital to keep your templates up to date and how we the template update process looks like.

Updating your templates

“Will updating Zabbix also update my templates?” is a question that I receive quite often. The answer to that question is – no changes are made to your templates whenever you update your Zabbix instance – be it a minor or a major update. The reasoning behind that is quite simple – we always recommend that you tune the out-of-the-box templates as per your particular requirements. That may consist of changing update intervals, disabling items/triggers, or even changing the existing trigger expressions or adding whole new entities to the template.

This is where the current behavior with template updates starts to make more sense. If Zabbix were to automatically update your templates, there could be a chance of overwriting your custom changes and could potentially disrupt the monitoring of your environment. That is something that we definitely wish to avoid.

The question still stands – Then how am I supposed to update my templates?

The answer – you can find the latest official Zabbix templates on our official git page – https://git.zabbix.com/

First, navigate to the Zabbix repository and open the Templates folder. Then, select the release branch that matches your Zabbix instance version. Here you can find all of our official templates and also the official media types under the media folder. All you have to do now is open the template up and download the raw template file.

Zabbix 5.4 release git templates/db folder

Once that is done, we can import the template into our Zabbix environment

Template template_db_oracle_agent2 import

Don’t forget to back up your existing templates, especially if you have made some custom changes to them! Ideally – add a prefix to their names, so the new and old templates can live side by side, and you can then manually copy over the changes from the latest official template to your custom template.

The benefits of keeping templates up to date

But what is the point of updating your templates – what do you get out of it? Well, that varies on the specific fixes or improvements we make to the particular template over time. Sometimes the updated template will provide improved trigger expressions or preprocessing logic. Other times the updated template will provide extra value to your monitoring with completely new items and triggers. In the case of Webhook media types – the updates usually contain fixes or improvements for some particular use cases, for example – fixing a compatibility issue for a specific OS.

You can always track these changes either in the release notes of a particular Zabbix version or by looking up a specific bug or a feature request in our bug tracker – https://support.zabbix.com

Some of the template changes in Zabbix 5.4 major update

Zabbix self-monitoring templates

Another key aspect of why it’s important to keep your templates up to date is so you can implement the changes made to the Zabbix self-monitoring templates. For example, if we compare Zabbix 5.0 to Zabbix 5.4, there are multiple new Zabbix processes and caches added to Zabbix 5.4, such as report writer/manager process, availability manager process, trend function caches, and other new components.

Zabbix server health template version 5.0 and 5.4 difference in the number of entities

So, if you update from Zabbix 5.0 to 5.4 (or Zabbix 6.0 if you’re sticking with LTS versions), you WILL NOT be monitoring these processes and caches if you don’t update your Zabbix server and Zabbix proxy templates to the current Zabbix versions. This means that you will be completely unaware of any potential performance issues related to these processes or caches.

Tracking template changes

With Zabbix 5.4 and later, you will notice some great improvements to the template import process. If you’re wondering what has changed when comparing an older template version with a newer one, you will now be able to see the changes during the import process. The added and removed elements will be highlighted in red or green accordingly.

Preview of the changes made during the template import process

How often should you update the templates? Ideally, you would follow the Zabbix update release notes and take note of any changes made to the templates that are of use in your environment. At the very least – definitely check for changes in the self-monitoring templates when moving to a newer major version of Zabbix. Otherwise, you risk losing track of potential issues in your Zabbix environment.

Now that you know the answer to the question “How can I update my Zabbix templates?” try and think back to when you last updated your Zabbix instance to a new version – did you also check the official templates for updates? If not, then don’t hesitate and visit https://git.zabbix.com/ to find the latest templates for your Zabbix version. Chances are that you will be pleasantly surprised with a set of new and updated templates for your monitoring endpoints and new webhook media types to help you integrate Zabbix with your existing systems.

Subscribe
Notify of
5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
scumm78
scumm78
3 years ago

This is good to update one single template but how do we update all of them?

A medium environment might uses like dozen and dozen of different templates and now the templates are also split in modules so that is even more difficult.

Why not have a feature in zabbix to upgrade templates directly from the git repository?

Dirk
3 years ago

Thank you for this article which reminded me that my templates are very old.

Don’t forget to back up your existing templates, especially if you have made some custom changes to them! Ideally – add a prefix to their names, so the new and old templates can live side by side, and you can then manually copy over the changes from the latest official template to your custom template.

How am I able to do this? When I rename an existing old template and import the new one, the new one still replaces the existing one. I assume this is done via the uuid. Should I change the uuid in the imported yaml?? And how am I able to “copy over the changes”?

I am afraid of loosing 1. changes in the templates and 2. historical data (e.g. because I changed the trend values).

Thank you again for your help.

ArtursL
ArtursL
3 years ago
Reply to  Dirk

You are correct about UUID as the reason for overwrites!
I suggest simply “Exporting” the old templates out and storing them in a backup folder – backing them up that way.

Trashcan4UD
Trashcan4U
2 years ago

This is really nice, but why the templates can’t have a origin URL and system can try to check (manually or automatically) for updates automatically and report if there are updates?

As others pointed out, it is very cumbersome to download many templates one by one and import. Especially the templates which are linked to many others.

Andrei Mihai
Andrei Mihai
29 days ago

Ansible is a great tool for automating tasks like updating Zabbix templates.

You can use the zabbix_template module from the community.zabbix collection to manage Zabbix templates via the API.

Here’s how you can achieve this:

1. Prerequisites

  • Install Ansible Collection: Install the community.zabbix collection if not already installed:
ansible-galaxy collection install community.zabbix
  • Zabbix API Credentials: Ensure you have API access with a user that has sufficient privileges to manage templates.
  • Template Directory: Organize the .xml files for version 7.0 templates in a directory (e.g., zabbix_templates_7.0).

2. Ansible Playbook for Updating Zabbix TemplatesCreate an Ansible playbook to upload and update the templates:

Playbook File: update_zabbix_templates.yml

---
- name: Update Zabbix templates
  hosts: localhost
  gather_facts: false

  vars:
    zabbix_url: "http://your-zabbix-server/zabbix"
    zabbix_user: "api_user"
    zabbix_password: "api_password"
    template_directory: "zabbix_templates_7.0"

  tasks:
    - name: Ensure Zabbix templates are updated
      community.zabbix.zabbix_template:
        server_url: "{{ zabbix_url }}"
        login_user: "{{ zabbix_user }}"
        login_password: "{{ zabbix_password }}"
        state: present
        src: "{{ item }}"
        validate_certs: false
      loop: "{{ lookup('fileglob', template_directory + '/*.xml') }}"
      loop_control:
        label: "{{ item | basename }}"

3. Steps in the Playbook

  1. API Connection:
  • The playbook uses server_url, login_user, and login_password to authenticate with the Zabbix API.
  1. Template Directory:
  • The fileglob lookup dynamically finds all .xml files in the template_directory.
  1. Upload Templates:
  • The zabbix_template module uploads or updates each template, ensuring existing ones are updated and new ones are created.
  1. Error Handling:
  • Ansible’s task output will highlight any failures during the update process.

4. Run the PlaybookRun the playbook to update the templates:

ansible-playbook update_zabbix_templates.yml

5. VerificationAfter running the playbook:

  • Check the Zabbix web interface to confirm the templates were updated.
  • Validate that linked hosts are working as expected.

6. Advanced Considerations

  • Idempotency: The playbook ensures that templates are only updated if they differ from the current ones.
  • Error Logging: For better error tracking, you can add handlers or log errors to a file.
  • CI/CD Integration: Include the playbook in your CI/CD pipeline to automate template updates during deployments, or when you upgrade your Zabbix environment.

#######################

Alternatively, we can use a python script to achieve similar results:

To programmatically update all your Zabbix templates from version 6.0 or 6.4, which is our case to version 7.0, you can follow these steps:

1. Review Changes in Templates

  • Visit the Zabbix Templates Repository to compare the templates for version 6.x with version 7.0. Identify templates that need to be updated or replaced.

2. Download Updated Templates

  • Navigate to the version 7.0 templates in the repository and download the .xml files for the required templates.
  • Organize the new templates in a local directory (e.g., zabbix_templates_7.0).

3. Update Templates Using the Zabbix APIThe Zabbix API provides a method to update existing templates: template.update. Below is a Python example using the pyzabbix library:

Install pyzabbix if not already installed:

pip install py-zabbix

Python Script to Update Templates:

from pyzabbix import ZabbixAPI
import os

# Zabbix API details
zabbix_url = "http://your-zabbix-server/zabbix"
zabbix_user = "api_user"
zabbix_password = "api_password"

# Directory with updated templates
template_directory = "zabbix_templates_7.0"

# Connect to the Zabbix API
zapi = ZabbixAPI(zabbix_url)
zapi.login(zabbix_user, zabbix_password)
print(f"Connected to Zabbix API (Version: {zapi.api_version()})")

# Upload and update templates
for template_file in os.listdir(template_directory):
    if template_file.endswith(".xml"):
        template_path = os.path.join(template_directory, template_file)

        # Read the template XML
        with open(template_path, 'r') as f:
            template_xml = f.read()

        try:
            # Import the template
            zapi.confimport(
                format='xml',
                rules={
                    'templates': {
                        "createMissing": True,
                        "updateExisting": True
                    },
                    'templateLinkage': {
                        "createMissing": True,
                        "deleteMissing": False
                    },
                    'items': {
                        "createMissing": True,
                        "updateExisting": True,
                        "deleteMissing": False
                    },
                    'triggers': {
                        "createMissing": True,
                        "updateExisting": True,
                        "deleteMissing": False
                    },
                    'graphs': {
                        "createMissing": True,
                        "updateExisting": True,
                        "deleteMissing": False
                    },
                    'discoveryRules': {
                        "createMissing": True,
                        "updateExisting": True,
                        "deleteMissing": False
                    },
                    'httptests': {
                        "createMissing": True,
                        "updateExisting": True,
                        "deleteMissing": False
                    }
                },
                source=template_xml
            )
            print(f"Successfully updated template: {template_file}")
        except Exception as e:
            print(f"Failed to update template {template_file}: {e}")

# Logout
zapi.logout()

4. Steps in the Script
Connect to Zabbix API:

  • Provide your Zabbix URL and API credentials.

Read Updated Template Files:

  • The script iterates through .xml files in the specified directory.

Import Templates via confimport:

  • Use the confimport method with rules to ensure existing templates are updated, missing templates are created, and specific elements (items, triggers, graphs, etc.) are preserved where needed.

Handle Errors:

  • If any template fails to update, the error is logged for troubleshooting.

5. Verify the Updates

  • Log into the Zabbix web interface and confirm the templates have been updated.
  • Check linked hosts to ensure they are functioning as expected.

6. Automation

  • Schedule this script to run periodically or as part of your CI/CD pipeline to keep templates updated.

Note: These are mock solutions based on stuff we’ve already built and are using ourselves.
The working solution needs to be adapted to your own environment.

Text, code and explanation is generated by ChatGPT, based on curated content. I.E. playbook and script examples that were heavily modified and simplified, for this purpose, along with steps explanation all added into a notion writer prompt.

5
0
Would love your thoughts, please comment.x
()
x