Ad Widget

Collapse

Template importing correctly through web interface but not through API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmansfie
    Junior Member
    • Apr 2026
    • 3

    #1

    Template importing correctly through web interface but not through API

    Hi!
    I'm managing a Zabbix server via the API, and having trouble using the configuration import endpoint to load in templates. After some troubleshooting, I've simplified it down to this: I have a simple template (see attached) which imports correctly when using the web interface, but imports without its discovery rule when imported via the API. Below is the template, my API testing code, and screenshots of the results.

    I'm on Zabbix server 7.0.25 (happy to try newer versions, but if this is a known bug I was unable to find it). I couldn't find anything in the Zabbix server logs about the attempted configuration, let alone any errors, even when the debug level was at maximum.

    Here's the template YAML file:
    Code:
    zabbix_export:
      version: '7.0'
      template_groups:
        - uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6
          name: Templates/Applications
      templates:
        - uuid: aa15021bf5e04380bfff52fbeda29a84
          template: 'NRPE by Zabbix agent 2 user parameters'
          name: 'NRPE by Zabbix agent 2 user parameters'
          groups:
            - name: Templates/Applications
          discovery_rules:
            - uuid: a7d2d2fd1d9045dbb9f020db7da32c20
              name: 'NRPE discovery'
              key: nrpe.discovery
              delay: 1h
              item_prototypes:
                - uuid: f53fed58623649efbe1e6eea83585ef0
                  name: '{#NRPE_NAME}'
                  key: 'nrpe.query[{#NRPE_SCRIPT}]'
                  value_type: TEXT
                  trends: '0'
    The python code I'm using to test the API:
    Code:
    import zabbix_utils
    import socket
    import yaml
    
    api = zabbix_utils.ZabbixAPI(url="https://" + socket.getfqdn())
    api.login(user="Admin", password=[REDACTED])
    
    # load the desired Zabbix configuration
    with open("test.yaml","r") as config_file:
    template = yaml.load(config_file, Loader=yaml.Loader)
    
    source = yaml.dump(template)
    message = { "format": "yaml", "rules": { "templates": { "createMissing": True, "updateExisting": True }}, "source": source}
    print(message)
    print(api.configuration.import_(message))​
    I've confirmed with the output of this that the YAML parsing is correct and the API endpoint returns good.

    Here's a screenshot of the template when imported with the web interface:
    Click image for larger version

Name:	Screenshot From 2026-05-13 16-13-47.png
Views:	2
Size:	26.7 KB
ID:	513528
    And when imported with the API:
    Click image for larger version

Name:	Screenshot From 2026-05-13 16-13-21.png
Views:	1
Size:	26.2 KB
ID:	513529
    I've also confirmed that exporting it after importing it via the API similarly shows the discovery rule missing.

    Would appreciate any help on this. Thanks!
Working...