Created
January 23, 2013 02:34
-
-
Save r-plus/4601357 to your computer and use it in GitHub Desktop.
zabbixのホスト設定をエクスポートしたXMLの全ての監視アイテムのアプリケーション値を設定する。
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
| #!/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