Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from pyzabbix import ZabbixAPI, ZabbixAPIException
  4. import sys
  5. import yaml
  6.  
  7. #TODO: Sollte anderen Admin benutzen
  8. server="http://localhost/zabbix"
  9. username="myuser"
  10. password="secret"
  11.  
  12. zapi = ZabbixAPI(server)
  13. zapi.session.auth = (username, password)
  14. zapi.timeout = 15
  15. zapi.login(username)
  16.  
  17. # Gather hosts and their host groups
  18. try:
  19. hosts = zapi.host.get(output=["host"], selectGroups=True)
  20. except ZabbixAPIException as e:
  21. print(e)
  22. sys.exit()
  23.  
  24. if hosts:
  25. result = dict()
  26. for host in hosts:
  27. result[host["host"]] = list()
  28. for group in host["groups"]:
  29. result[host["host"]].append(group["name"])
  30.  
  31. with open('/etc/logstash/dicts/zabbix_hosts_hostgroups.yaml', 'w') as f:
  32. yaml.dump(result, f)
  33. else:
  34. print("No hosts found; keeping the old YAML file!")
  35. ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement