This commit is contained in:
2025-10-31 22:23:47 +01:00
parent 7f088bc538
commit 810df5157c
5 changed files with 106 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/.venv
/config.yml
/downloads/*.yml

24
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "overview",
"type": "debugpy",
"request": "launch",
"program": "main.py",
"console": "integratedTerminal",
"args": "--overview"
},
{
"name": "check",
"type": "debugpy",
"request": "launch",
"program": "main.py",
"console": "integratedTerminal",
"args": "--check"
}
]
}

0
downloads/.keep Normal file
View File

68
main.py Normal file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env python3
# https://www.zabbix.com/documentation/current/en/manual/api/reference
from zabbix_utils import ZabbixAPI
import yaml
import requests
import argparse
with (open("config.yml")) as y:
config = yaml.safe_load(y)
with (open("templates.yml")) as y:
templates = yaml.safe_load(y)
def get_raw_url(api_template):
template = templates["templates"][api_template["uuid"]]
vendor = templates["vendors"][template["vendor"]]
return f"\t{vendor['raw']}{template['path']}?{vendor['qry']}"
def get_api_templates():
api = ZabbixAPI(url=config["zabbix"]["api"]["url"])
api.login(token=config["zabbix"]["api"]["token"])
api_templates = api.template.get(selectHosts=["hostid", "name"], sortfield="name")
return [t for t in api_templates if len(t["hosts"]) > 0]
def overview():
api_templates = get_api_templates()
for api_template in api_templates:
print(api_template["name"])
print(f"\tVendor: {api_template['vendor_name']}")
print(f"\tVersion: {api_template['vendor_version']}")
print(f"\tUUID: {api_template['uuid']}")
print("\tused by hosts:")
for host in api_template["hosts"]:
print(f"\t\t{host['name']}")
if not api_template['uuid'] in templates["templates"]:
print("\t!!! not found in templates.yml")
def check():
api_templates = get_api_templates()
for api_template in api_templates:
if api_template["uuid"] in templates["templates"]:
raw_url = get_raw_url(api_template)
resp = requests.get(raw_url)
resp.raise_for_status()
remote_templates = yaml.safe_load(resp.text)
for remote_template in remote_templates["zabbix_export"]["templates"]:
if remote_template["uuid"] == api_template["uuid"]:
if remote_template["vendor"]["version"] != api_template["vendor_version"]:
with open(f"downloads/{api_template["name"]}.yml", "w") as lt:
lt.write(resp.text)
print(f"found update for {api_template["name"]}")
def main():
args_parser = argparse.ArgumentParser()
args_parser.add_argument("--overview", action="store_true", help="show overview of used templates")
args_parser.add_argument("--check", action="store_true", help="check known templates for updates")
args = args_parser.parse_args()
if args.overview:
overview()
elif args.check:
check()
if __name__ == "__main__":
main()

11
templates.yml Normal file
View File

@@ -0,0 +1,11 @@
templates:
a3dc630729e443139f4e608954fa6e19:
vendor: Zabbix
path: os/freebsd/template_os_freebsd.yaml
5630ec1b1baf449abe1bc5521f85fe6c:
vendor: Zabbix
path: app/certificate_agent2/template_app_certificate_agent2.yaml
vendors:
Zabbix:
raw: https://git.zabbix.com/projects/ZBX/repos/zabbix/raw/templates/
qry: at=refs%2Fheads%2Frelease%2F7.0