From 862dc722ecf373db0ca95ace6da188bff677c66d Mon Sep 17 00:00:00 2001 From: osiu97 Date: Wed, 9 Jan 2019 15:59:39 +0100 Subject: [PATCH] vmnames getter --- PVE-Zabbix.py | 16 +++++++++++++--- PVEApi.py | 1 - VM.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/PVE-Zabbix.py b/PVE-Zabbix.py index 2a00a01..6df2514 100644 --- a/PVE-Zabbix.py +++ b/PVE-Zabbix.py @@ -1,11 +1,21 @@ from PVEApi import PVEApi +import json USERNAME = "zabbix@pve" PASSWORD = "zabbix" HOST = "172.16.3.11:8006" +NODE='h1' conn = PVEApi(HOST, USERNAME, PASSWORD) -print conn.get_node_list() -for vm in conn.get_cluster_vmlist(): - print vm.node, vm.name, vm.vmid, vm.cpus + +def get_vmnames(vmlist): + name_vmlist = [{"#VMNAME": vm.name} for vm in vmlist] + return name_vmlist + +def listofdicts_to_zabbix_json(list): + # TODO wrap in "data:[]" + zabbixjson=json.dumps(list) + return zabbixjson + +print listofdicts_to_zabbix_json(get_vmnames(conn.get_cluster_vmlist())) \ No newline at end of file diff --git a/PVEApi.py b/PVEApi.py index 91b413a..b767ccd 100644 --- a/PVEApi.py +++ b/PVEApi.py @@ -43,7 +43,6 @@ class PVEApi(object): url = self.url + '/nodes/' + node + '/qemu' response = json.load(urllib2.urlopen(self.get_request(url), context=ssl._create_unverified_context())) resources = response['data'] - print resources for machine in resources: name = machine[u'name'] status = machine[u'status'] diff --git a/VM.py b/VM.py index 05a792d..a550797 100644 --- a/VM.py +++ b/VM.py @@ -20,4 +20,4 @@ class VM(object): self.maxmem = maxmem def __repr__(self): - return "<%s:%s>" % (self.node, self.name) + return "<%s-%s:%s>" % (self.node,self.vmid, self.name)