Skip to content

Instantly share code, notes, and snippets.

@r-plus
Created January 23, 2013 02:34
Show Gist options
  • Select an option

  • Save r-plus/4601357 to your computer and use it in GitHub Desktop.

Select an option

Save r-plus/4601357 to your computer and use it in GitHub Desktop.
zabbixのホスト設定をエクスポートしたXMLの全ての監視アイテムのアプリケーション値を設定する。
#!/usr/bin/env python
#
# Usage: python hoge.py xmlfile configfile
# configfile format:
# <Prefix of zabbix-key> space separate <application name>
from xml.etree.ElementTree import *
from sys import argv
# reading configuration
confDict = {}
f = open(argv[2])
for line in f:
list = line.split()
confDict[list[0]] = list[1]
f.close()
def modify_applications(item):
for key in confDict.keys():
if item.get("key").startswith(key):
element = Element("application")
element.text = confDict[key]
app = item.find("applications")
app.clear()
app.insert(0, element)
return
tree = parse(argv[1])
root = tree.getroot()
for item in root.findall(".////item"):
modify_applications(item)
tree.write("modified_xml.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment