Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- from pyzabbix import ZabbixAPI, ZabbixAPIException
- import sys
- import yaml
- #TODO: Sollte anderen Admin benutzen
- server="http://localhost/zabbix"
- username="myuser"
- password="secret"
- zapi = ZabbixAPI(server)
- zapi.session.auth = (username, password)
- zapi.timeout = 15
- zapi.login(username)
- # Gather hosts and their host groups
- try:
- hosts = zapi.host.get(output=["host"], selectGroups=True)
- except ZabbixAPIException as e:
- print(e)
- sys.exit()
- if hosts:
- result = dict()
- for host in hosts:
- result[host["host"]] = list()
- for group in host["groups"]:
- result[host["host"]].append(group["name"])
- with open('/etc/logstash/dicts/zabbix_hosts_hostgroups.yaml', 'w') as f:
- yaml.dump(result, f)
- else:
- print("No hosts found; keeping the old YAML file!")
- ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement