|
@@ -2,6 +2,7 @@
|
|
# coding: utf-8
|
|
# coding: utf-8
|
|
|
|
|
|
# {{{ Imports
|
|
# {{{ Imports
|
|
|
|
+import os
|
|
import sys
|
|
import sys
|
|
import argparse
|
|
import argparse
|
|
import yaml
|
|
import yaml
|
|
@@ -24,26 +25,28 @@ def main():
|
|
help='Print additional debug informations: traceback, etc. (default: no)')
|
|
help='Print additional debug informations: traceback, etc. (default: no)')
|
|
parser.add_argument('datafile')
|
|
parser.add_argument('datafile')
|
|
options = parser.parse_args()
|
|
options = parser.parse_args()
|
|
- try:
|
|
|
|
- data = {'data': []}
|
|
|
|
- with open(options.datafile) 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)
|
|
|
|
- print(json.dumps(data, indent=4))
|
|
|
|
- except Exception as e:
|
|
|
|
- if not options.debug:
|
|
|
|
- print('Exception raised (use --debug option to get more info): %s' % (unicode(e)))
|
|
|
|
- else:
|
|
|
|
- print('Exception raised: %s' % (e))
|
|
|
|
- traceback.print_exc(file=sys.stderr)
|
|
|
|
- sys.exit(-1)
|
|
|
|
|
|
+ data = {'data': []}
|
|
|
|
+ if os.path.exists(options.datafile):
|
|
|
|
+ try:
|
|
|
|
+ with open(options.datafile) 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))
|
|
# }}}
|
|
# }}}
|
|
|
|
|
|
# {{{ __main__
|
|
# {{{ __main__
|