Compare commits

..

5 Commits

Author SHA1 Message Date
6094f9e4fe added proxmox 2025-11-01 13:46:20 +01:00
85079c9272 added format option 2025-11-01 13:38:31 +01:00
419f7acd4b added more templates 2025-11-01 13:20:40 +01:00
6132cdd879 configure multiple server in config.yml and set with --server 2025-11-01 12:57:32 +01:00
75eb3fc11a ignore vscode files 2025-11-01 12:56:40 +01:00
5 changed files with 83 additions and 38 deletions

1
.gitignore vendored
View File

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

24
.vscode/launch.json vendored
View File

@@ -1,24 +0,0 @@
{
// 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"
}
]
}

View File

@@ -13,14 +13,18 @@ pip install zabbix_utils
* configure Zabbix access in `config.yml` * configure Zabbix access in `config.yml`
``` ```
zabbix: zabbix:
api: servers:
url: https://your.zabbix.example.com foo:
token: abc123 url: https://your.zabbix.example.com
token: abc123
bar:
url: https://other.zabbix.example.com
token: cba321
``` ```
* user must have access to API `template.get` * user must have access to API `template.get`
## usage ## usage
* get an overview of *used* templates: `./main.py --overview` * get an overview of *used* templates: `./main.py --overview --server foo`
``` ```
Borg Backup Passive Borg Backup Passive
Vendor: Vendor:
@@ -37,7 +41,15 @@ FreeBSD by Zabbix agent
router.exmaple.com router.exmaple.com
... ...
``` ```
* check for new versions and download known templates: `./main.py --check` * get an overview of *used* templates in machine readable format: `./main.py --overview --server foo --format machine`
* copy&paste'able into libre calc
```
name vendor version uuid hosts known
Borg Backup Passive 3077e7298167465b96d30503bcff4769 devloop.de,blah.example.com,moep.example.com no
FreeBSD by Zabbix agent Zabbix 7.0-2 a3dc630729e443139f4e608954fa6e19 router.exmaple.com yes
...
```
* check for new versions and download known templates: `./main.py --check --server foo`
``` ```
found update for Template Module Generic SNMPv2 found update for Template Module Generic SNMPv2
found update for Template OS FreeBSD found update for Template OS FreeBSD

47
main.py
View File

@@ -18,14 +18,20 @@ def get_raw_url(api_template):
vendor = templates["vendors"][template["vendor"]] vendor = templates["vendors"][template["vendor"]]
return f"\t{vendor['raw']}{template['path']}?{vendor['qry']}" return f"\t{vendor['raw']}{template['path']}?{vendor['qry']}"
def get_api_templates(): def get_api_templates(server):
api = ZabbixAPI(url=config["zabbix"]["api"]["url"]) api = ZabbixAPI(url=config["zabbix"]["servers"][server]["url"])
api.login(token=config["zabbix"]["api"]["token"]) api.login(token=config["zabbix"]["servers"][server]["token"])
api_templates = api.template.get(selectHosts=["hostid", "name"], sortfield="name") api_templates = api.template.get(selectHosts=["hostid", "name"], sortfield="name")
return [t for t in api_templates if len(t["hosts"]) > 0] return [t for t in api_templates if len(t["hosts"]) > 0]
def overview(): def overview(server, format):
api_templates = get_api_templates() api_templates = get_api_templates(server)
if format == "human":
overview_output_human(api_templates)
elif format == "machine":
overview_output_machine(api_templates)
def overview_output_human(api_templates):
for api_template in api_templates: for api_template in api_templates:
print(api_template["name"]) print(api_template["name"])
print(f"\tVendor: {api_template['vendor_name']}") print(f"\tVendor: {api_template['vendor_name']}")
@@ -37,8 +43,29 @@ def overview():
if not api_template['uuid'] in templates["templates"]: if not api_template['uuid'] in templates["templates"]:
print("\t!!! not found in templates.yml") print("\t!!! not found in templates.yml")
def check(): def overview_output_machine(api_templates):
api_templates = get_api_templates() print("name", end="\t")
print("vendor", end="\t")
print("version", end="\t")
print("uuid", end="\t")
print("hosts", end="\t")
print("known")
for api_template in api_templates:
print(api_template["name"], end="\t")
print(api_template["vendor_name"], end="\t")
print(api_template["vendor_version"], end="\t")
print(api_template["uuid"], end="\t")
for host in api_template["hosts"]:
print(host["name"], end=",")
print("\t", end="")
if api_template['uuid'] in templates["templates"]:
print("yes")
else:
print("no")
def check(server):
api_templates = get_api_templates(server)
for api_template in api_templates: for api_template in api_templates:
if api_template["uuid"] in templates["templates"]: if api_template["uuid"] in templates["templates"]:
raw_url = get_raw_url(api_template) raw_url = get_raw_url(api_template)
@@ -57,12 +84,14 @@ def main():
args_parser = argparse.ArgumentParser() args_parser = argparse.ArgumentParser()
args_parser.add_argument("--overview", action="store_true", help="show overview of used templates") 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_parser.add_argument("--check", action="store_true", help="check known templates for updates")
args_parser.add_argument("--server", type=str, help="server to use from config.yml", required=True)
args_parser.add_argument("--format", type=str, help="output format: machine or human, default to human", default="human")
args = args_parser.parse_args() args = args_parser.parse_args()
if args.overview: if args.overview:
overview() overview(args.server, args.format)
elif args.check: elif args.check:
check() check(args.server)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -1,16 +1,43 @@
templates: templates:
0c94915edb4c41bf8c627dddb4f68f5a:
vendor: Zabbix
path: app/opnsense_snmp/template_app_opnsense_snmp.yaml
13b06904a6bf41cbb795e3193d896340:
vendor: Zabbix
path: os/windows_agent/template_os_windows_agent.yaml
16f281aeb8904d3db8b66dda94611fcc:
vendor: Zabbix
path: app/pfsense_snmp/template_app_pfsense_snmp.yaml
4904f84303c74c5e955b7849730c3155:
vendor: Zabbix
path: db/mysql_agent2/template_db_mysql_agent2.yaml
4958b76448d74ff1b6d7d6280449beee:
vendor: Zabbix
path: app/proxmox/template_app_proxmox.yaml
4cb1aabe2b704b5c882963c2ef87d8f6: 4cb1aabe2b704b5c882963c2ef87d8f6:
vendor: Zabbix vendor: Zabbix
path: net/generic_snmp_snmp/template_module_generic_snmp_snmp.yaml path: net/generic_snmp_snmp/template_module_generic_snmp_snmp.yaml
5630ec1b1baf449abe1bc5521f85fe6c: 5630ec1b1baf449abe1bc5521f85fe6c:
vendor: Zabbix vendor: Zabbix
path: app/certificate_agent2/template_app_certificate_agent2.yaml path: app/certificate_agent2/template_app_certificate_agent2.yaml
5fdd2ca8b8f84962aaea5a218b46ea7d:
vendor: Zabbix
path: os/windows_agent_active/template_os_windows_agent_active.yaml
67332e679035423f85090aa985947c36:
vendor: Zabbix
path: net/generic_snmp/template_net_generic_snmp.yaml
6c235d126c1f4895acfe2156b140a886: 6c235d126c1f4895acfe2156b140a886:
vendor: Zabbix vendor: Zabbix
path: net/ubiquiti_airos_snmp/template_net_ubiquiti_airos_snmp.yaml path: net/ubiquiti_airos_snmp/template_net_ubiquiti_airos_snmp.yaml
90ac276995294a6aa88462c032d2ddaf:
vendor: Zabbix
path: app/systemd/template_app_systemd.yaml
a3dc630729e443139f4e608954fa6e19: a3dc630729e443139f4e608954fa6e19:
vendor: Zabbix vendor: Zabbix
path: os/freebsd/template_os_freebsd.yaml path: os/freebsd/template_os_freebsd.yaml
aa3ce9bd8c1d40a2b0f83f9e642e88ee:
vendor: Zabbix
path: net/cisco/cisco_snmp/template_net_cisco_snmp.yaml
d0ef7d659a8f4beaaabfc4b6134e737a: d0ef7d659a8f4beaaabfc4b6134e737a:
vendor: Zabbix vendor: Zabbix
path: db/postgresql_agent2/template_db_postgresql_agent2.yaml path: db/postgresql_agent2/template_db_postgresql_agent2.yaml