|
@@ -13,7 +13,7 @@ import traceback
|
|
|
# {{{ Constants
|
|
|
_NAME = "yaml2json"
|
|
|
_DESC = "Convert yaml data to zabbix json discovery format"
|
|
|
-_VERSION = "0.1"
|
|
|
+_VERSION = "0.2"
|
|
|
# }}}
|
|
|
|
|
|
# {{{ main()
|
|
@@ -23,29 +23,30 @@ def main():
|
|
|
version='%(prog)s ' + _VERSION)
|
|
|
parser.add_argument('-d', '--debug', dest='debug', default=False, action='store_true',
|
|
|
help='Print additional debug informations: traceback, etc. (default: no)')
|
|
|
- parser.add_argument('datafile')
|
|
|
+ parser.add_argument('datafiles', nargs='+')
|
|
|
options = parser.parse_args()
|
|
|
data = {'data': []}
|
|
|
- if os.path.exists(options.datafile):
|
|
|
- try:
|
|
|
- with open(options.datafile, encoding='utf-8') as f:
|
|
|
- datayml = yaml.safe_load(f)
|
|
|
- if datayml is not None:
|
|
|
- for section in datayml:
|
|
|
- localdata = {
|
|
|
- '{#KEY}': section,
|
|
|
- }
|
|
|
- for k in datayml[section]:
|
|
|
- localdata['{#%s}' % (k.upper())] = datayml[section][k]
|
|
|
- data['data'].append(localdata)
|
|
|
- except Exception as e:
|
|
|
- if not options.debug:
|
|
|
- print('Exception raised (use --debug option to get more info): %s' % (e), file=sys.stderr)
|
|
|
- else:
|
|
|
- print('Exception raised: %s' % (e), file=sys.stderr)
|
|
|
- traceback.print_exc(file=sys.stderr)
|
|
|
- print('ZBX_NOTSUPPORTED')
|
|
|
- sys.exit(-1)
|
|
|
+ for datafile in options.datafiles:
|
|
|
+ if os.path.exists(datafile):
|
|
|
+ try:
|
|
|
+ with open(datafile, encoding='utf-8') as f:
|
|
|
+ datayml = yaml.safe_load(f)
|
|
|
+ if datayml is not None:
|
|
|
+ for section in datayml:
|
|
|
+ localdata = {
|
|
|
+ '{#KEY}': section,
|
|
|
+ }
|
|
|
+ for k in datayml[section]:
|
|
|
+ localdata['{#%s}' % (k.upper())] = datayml[section][k]
|
|
|
+ data['data'].append(localdata)
|
|
|
+ except Exception as e:
|
|
|
+ if not options.debug:
|
|
|
+ print('Exception raised (use --debug option to get more info): %s' % (e), file=sys.stderr)
|
|
|
+ else:
|
|
|
+ print('Exception raised: %s' % (e), file=sys.stderr)
|
|
|
+ traceback.print_exc(file=sys.stderr)
|
|
|
+ print('ZBX_NOTSUPPORTED')
|
|
|
+ sys.exit(-1)
|
|
|
print(json.dumps(data, indent=4))
|
|
|
# }}}
|
|
|
|