Created
February 14, 2018 12:48
-
-
Save Sam-Martin/0b9c7b83139647a838d4c469dd6283b2 to your computer and use it in GitHub Desktop.
Update Zabbix hosts to report to proxies based on IPs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyzabbix import ZabbixAPI | |
import os | |
import json | |
import logging, sys | |
from pprint import pprint | |
# | |
# | |
# WARNING | |
# THIS | |
# SCRIPT | |
# IS NOT | |
# IDEMPOTENT!!! | |
# | |
# | |
#print "logging in as %s" % os.environ['ZABBIX_USERNAME'] | |
proxies = { | |
"ofc": { | |
"id": "11244", | |
"subnet": "10.120" | |
}, | |
"gs2":{ | |
"id": "11241", | |
"subnet": "10.108" | |
}, | |
"ctr": { | |
"id": "11243", | |
"subnet": "10.112" | |
} | |
} | |
zapi = ZabbixAPI("http://edamame-zabbix-development.uwapzzpmas.eu-west-2.elasticbeanstalk.com/") | |
zapi.login(os.environ['ZABBIX_USERNAME'], os.environ['ZABBIX_PASSWORD']) | |
#print("Connected to Zabbix API Version %s" % zapi.api_version()) | |
for datacenter in proxies: | |
hosts_to_add = [] | |
for host in zapi.hostinterface.get(output='extend',search={"ip":proxies[datacenter]['subnet']}): | |
#pprint(host) | |
hosts_to_add.append(host['hostid']) | |
pprint (hosts_to_add) | |
print ("Updating %s proxy server" % (datacenter)) | |
zapi.proxy.update(proxyid = proxies[datacenter]['id'], hosts = hosts_to_add, ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment