diff --git a/app/zabbix.py b/app/zabbix.py index 30a837e..67caf99 100644 --- a/app/zabbix.py +++ b/app/zabbix.py @@ -120,7 +120,16 @@ class ZabbixClient: # ------------------------------------------------------------------ templates def get_template_id(self, name): - result = self._call('template.get', {'filter': {'host': name}, 'output': ['templateid']}) + # Search by technical name (host field) — case-insensitive search with exactMatch fallback + result = self._call('template.get', { + 'output': ['templateid', 'host'], + 'search': {'host': name}, + 'searchByAny': True, + }) + # Exact match from search results + for t in result: + if t['host'] == name: + return t['templateid'] return result[0]['templateid'] if result else None def link_template(self, hostid, templateid): @@ -197,7 +206,9 @@ def sync_to_zabbix(players, add_log_fn): groupid = zbx.ensure_hostgroup(ZABBIX_HOST_GROUP) template_id = zbx.get_template_id(ZABBIX_TEMPLATE) if ZABBIX_TEMPLATE else None if ZABBIX_TEMPLATE and not template_id: - log.warning("Template '%s' not found in Zabbix — import zabbix_template.yaml first", ZABBIX_TEMPLATE) + msg = f"Template '{ZABBIX_TEMPLATE}' not found in Zabbix — import zabbix_template.yaml first" + log.warning(msg) + add_log_fn('error', msg) existing = {h['host']: h for h in zbx.get_hosts_in_group(groupid)} created = updated = skipped = 0