Compare commits
2 Commits
690ba2a23b
...
6132cdd879
| Author | SHA1 | Date | |
|---|---|---|---|
| 6132cdd879 | |||
| 75eb3fc11a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
/.venv
|
||||
/.vscode
|
||||
/config.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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -13,9 +13,13 @@ pip install zabbix_utils
|
||||
* configure Zabbix access in `config.yml`
|
||||
```
|
||||
zabbix:
|
||||
api:
|
||||
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`
|
||||
|
||||
|
||||
19
main.py
19
main.py
@@ -18,14 +18,14 @@ def get_raw_url(api_template):
|
||||
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"])
|
||||
def get_api_templates(server):
|
||||
api = ZabbixAPI(url=config["zabbix"]["servers"][server]["url"])
|
||||
api.login(token=config["zabbix"]["servers"][server]["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()
|
||||
def overview(server):
|
||||
api_templates = get_api_templates(server)
|
||||
for api_template in api_templates:
|
||||
print(api_template["name"])
|
||||
print(f"\tVendor: {api_template['vendor_name']}")
|
||||
@@ -37,8 +37,8 @@ def overview():
|
||||
if not api_template['uuid'] in templates["templates"]:
|
||||
print("\t!!! not found in templates.yml")
|
||||
|
||||
def check():
|
||||
api_templates = get_api_templates()
|
||||
def check(server):
|
||||
api_templates = get_api_templates(server)
|
||||
for api_template in api_templates:
|
||||
if api_template["uuid"] in templates["templates"]:
|
||||
raw_url = get_raw_url(api_template)
|
||||
@@ -57,12 +57,13 @@ 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_parser.add_argument("--server", type=str, help="server to use from config.yml", required=True)
|
||||
args = args_parser.parse_args()
|
||||
|
||||
if args.overview:
|
||||
overview()
|
||||
overview(args.server)
|
||||
elif args.check:
|
||||
check()
|
||||
check(args.server)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user