Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Created February 14, 2018 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sam-Martin/0b9c7b83139647a838d4c469dd6283b2 to your computer and use it in GitHub Desktop.
Save Sam-Martin/0b9c7b83139647a838d4c469dd6283b2 to your computer and use it in GitHub Desktop.
Update Zabbix hosts to report to proxies based on IPs
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