PVE-Zabbix/ZabbixJSON.py

19 lines
509 B
Python

import json
def listofdicts_to_zabbix_json(dlist):
"""
Converts list of dicts to JSON an wraps around 'data'
:param dlist: list of dicts you want to convert
:return: JSON string for zabbix-get
"""
newdlist = list()
for d in dlist:
for k, v in d.iteritems():
k = '{' + k + '}'
newdict = {k: v}
newdlist.append(newdict)
newdlist = {"data": newdlist}
zabbixjson = json.dumps(newdlist, separators=(',', ':'))
return zabbixjson