Compare commits
7 Commits
8d4a1d16f9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6094f9e4fe | |||
| 85079c9272 | |||
| 419f7acd4b | |||
| 6132cdd879 | |||
| 75eb3fc11a | |||
| 690ba2a23b | |||
| 76b0972ab6 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/.venv
|
/.venv
|
||||||
|
/.vscode
|
||||||
/config.yml
|
/config.yml
|
||||||
/downloads/*.yml
|
/downloads/*.yml
|
||||||
|
|||||||
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
77
README.md
77
README.md
@@ -1,3 +1,78 @@
|
|||||||
# zuplates
|
# zuplates
|
||||||
|
|
||||||
help updating zabbix templates
|
help updating zabbix templates
|
||||||
|
|
||||||
|
## install
|
||||||
|
* consider using venv
|
||||||
|
* install depdencies
|
||||||
|
```bash
|
||||||
|
pip install pyyaml
|
||||||
|
pip install requests
|
||||||
|
pip install zabbix_utils
|
||||||
|
```
|
||||||
|
* configure Zabbix access in `config.yml`
|
||||||
|
```
|
||||||
|
zabbix:
|
||||||
|
servers:
|
||||||
|
foo:
|
||||||
|
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`
|
||||||
|
|
||||||
|
## usage
|
||||||
|
* get an overview of *used* templates: `./main.py --overview --server foo`
|
||||||
|
```
|
||||||
|
Borg Backup Passive
|
||||||
|
Vendor:
|
||||||
|
Version:
|
||||||
|
UUID: 3077e7298167465b96d30503bcff4769
|
||||||
|
used by hosts:
|
||||||
|
devloop.de
|
||||||
|
!!! not found in templates.yml
|
||||||
|
FreeBSD by Zabbix agent
|
||||||
|
Vendor: Zabbix
|
||||||
|
Version: 7.0-2
|
||||||
|
UUID: a3dc630729e443139f4e608954fa6e19
|
||||||
|
used by hosts:
|
||||||
|
router.exmaple.com
|
||||||
|
...
|
||||||
|
```
|
||||||
|
* 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 OS FreeBSD
|
||||||
|
found update for Ubiquiti AirOS by SNMP
|
||||||
|
found update for Website certificate by Zabbix agent 2
|
||||||
|
found update for Zabbix proxy health
|
||||||
|
found update for Zabbix server health
|
||||||
|
```
|
||||||
|
* new template versions saved in `downloads`
|
||||||
|
* manually import into zabbix
|
||||||
|
|
||||||
|
## known templates
|
||||||
|
* templates are looked up in `templates.yml`
|
||||||
|
* structure is like:
|
||||||
|
```yml
|
||||||
|
templates:
|
||||||
|
<uuid of template>:
|
||||||
|
vendor: <reference to vendors/vendor name>
|
||||||
|
path: <added to raw from vendor>
|
||||||
|
...
|
||||||
|
vendors:
|
||||||
|
<vendor name>:
|
||||||
|
raw: <generic part of vendor url for downloading yml template>
|
||||||
|
qry: <query to add to url>
|
||||||
|
```
|
||||||
|
* template download URL will be the concatination of `raw`, `path` and `qry`
|
||||||
47
main.py
47
main.py
@@ -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()
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
certifi==2025.10.5
|
|
||||||
charset-normalizer==3.4.4
|
|
||||||
idna==3.11
|
|
||||||
PyYAML==6.0.3
|
|
||||||
requests==2.32.5
|
|
||||||
urllib3==2.5.0
|
|
||||||
zabbix-utils==2.0.3
|
|
||||||
@@ -1,10 +1,61 @@
|
|||||||
templates:
|
templates:
|
||||||
a3dc630729e443139f4e608954fa6e19:
|
0c94915edb4c41bf8c627dddb4f68f5a:
|
||||||
vendor: Zabbix
|
vendor: Zabbix
|
||||||
path: os/freebsd/template_os_freebsd.yaml
|
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:
|
||||||
|
vendor: Zabbix
|
||||||
|
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:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: net/ubiquiti_airos_snmp/template_net_ubiquiti_airos_snmp.yaml
|
||||||
|
90ac276995294a6aa88462c032d2ddaf:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: app/systemd/template_app_systemd.yaml
|
||||||
|
a3dc630729e443139f4e608954fa6e19:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: os/freebsd/template_os_freebsd.yaml
|
||||||
|
aa3ce9bd8c1d40a2b0f83f9e642e88ee:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: net/cisco/cisco_snmp/template_net_cisco_snmp.yaml
|
||||||
|
d0ef7d659a8f4beaaabfc4b6134e737a:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: db/postgresql_agent2/template_db_postgresql_agent2.yaml
|
||||||
|
dd114bf0fb2f46bc84840f1bb24e2b23:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: app/zabbix_proxy/template_app_zabbix_proxy.yaml
|
||||||
|
e2307c94f1744af7a8f1f458a67af424:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: os/linux_active/template_os_linux_active.yaml
|
||||||
|
e2d2b4e4ac28483996cc11fe42823d57:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: app/zabbix_server/template_app_zabbix_server.yaml
|
||||||
|
e518b1340ce44d7389d2cc7c304a97b4:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: server/smart_agent2_active/template_module_smart_agent2_active.yaml
|
||||||
|
f8f7908280354f2abeed07dc788c3747:
|
||||||
|
vendor: Zabbix
|
||||||
|
path: os/linux/template_os_linux.yaml
|
||||||
vendors:
|
vendors:
|
||||||
Zabbix:
|
Zabbix:
|
||||||
raw: https://git.zabbix.com/projects/ZBX/repos/zabbix/raw/templates/
|
raw: https://git.zabbix.com/projects/ZBX/repos/zabbix/raw/templates/
|
||||||
|
|||||||
Reference in New Issue
Block a user