added brackets in JSON output

This commit is contained in:
osiu97 2019-01-10 11:33:14 +00:00
parent 00f714cc27
commit bfcc4bdc39
3 changed files with 9 additions and 4 deletions

13
PVE-Zabbix.py Normal file → Executable file
View File

@ -5,7 +5,6 @@ import json
USERNAME = "zabbix@pve"
PASSWORD = "zabbix"
HOST = "172.16.3.11:8006"
NODE = 'h1'
conn = PVEApi(HOST, USERNAME, PASSWORD)
@ -15,7 +14,7 @@ parser.add_argument("type", choices=['vm', 'cluster', 'node'], help='categories'
parser.add_argument("-l", "--list", dest='listing', action='store_true')
parser.add_argument("-n", "--name", dest='name')
args = parser.parse_args()
NODE = args.node
def get_vmnames(vmlist, node, **kwargs):
"""
@ -56,8 +55,14 @@ def listofdicts_to_zabbix_json(dlist):
:param dlist: list of dicts you want to convert
:return: JSON string for zabbix-get
"""
dlist = {"data": dlist}
zabbixjson = json.dumps(dlist)
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)
return zabbixjson

0
PVEApi.py Normal file → Executable file
View File

0
VM.py Normal file → Executable file
View File