Hello,
I’m new to the forum, and I’d like to thank you in advance for your support.
On my Zabbix server (version 6.0 LTS), I need to modify several hosts to replace an existing template with a new/different one.
Given the large number of hosts and the need to make additional changes, I decided to use a Python script. I based my script on the official documentation, specifically this page:
Problem:
When I execute the host.update request with the templates_clear parameter to unlink and clear a specific template, all templates associated with the host are removed, not just the one specified.
Here’s the code I’m using:
Question:
Has anyone encountered a similar issue? Am I using the API correctly, or am I missing something?
Thank you very much for your support!
I’m new to the forum, and I’d like to thank you in advance for your support.
On my Zabbix server (version 6.0 LTS), I need to modify several hosts to replace an existing template with a new/different one.
Given the large number of hosts and the need to make additional changes, I decided to use a Python script. I based my script on the official documentation, specifically this page:
Problem:
When I execute the host.update request with the templates_clear parameter to unlink and clear a specific template, all templates associated with the host are removed, not just the one specified.
Here’s the code I’m using:
Code:
def remove_template(auth_result, hostid, templateid_to_change):
auth_token = auth_result["result"]
host_update = {
"jsonrpc": "2.0",
"method": "host.update",
"params": {
"hostid": hostid,
"templates_clear": [
{
"templateid": templateid_to_change
}
]
},
"auth": auth_token,
"id": 1
}
response = requests.post(zabbix_api_url, data=json.dumps(host_update), headers=headers, verify=False)
create_result = response.json()
return create_result
Has anyone encountered a similar issue? Am I using the API correctly, or am I missing something?
Thank you very much for your support!
Comment