58 lines
2.2 KiB
Python
58 lines
2.2 KiB
Python
from ZabbixJSON import listofdicts_to_zabbix_json
|
|
|
|
|
|
class Storage(object):
|
|
""" Storage calls can be super slow """
|
|
instances = list()
|
|
|
|
def __init__(self, node, name, total, used, active, enabled, avail, used_fraction):
|
|
self.__class__.instances.append(self)
|
|
self.name = name
|
|
self.node = node.name
|
|
self.total = total
|
|
self.used = used
|
|
self.active = active
|
|
self.enabled = enabled
|
|
self.avail = avail
|
|
self.used_fraction = used_fraction
|
|
|
|
def __repr__(self):
|
|
return '%s' % self.name
|
|
|
|
@classmethod
|
|
def get_storagenames(cls, storagenode, **kwargs):
|
|
"""
|
|
Get Virtual Machine Names for discovery
|
|
:param storagenode: node name with to filter VMs by
|
|
:param kwargs: used to accept command line parameters
|
|
:return: list of dicts in [{'#STORNAME': "$name"}] format
|
|
"""
|
|
name_storagelist = list()
|
|
for c in cls.instances:
|
|
try:
|
|
if kwargs['name'] is None:
|
|
if c.node == storagenode.name:
|
|
name_storagelist.append({'#STORNAME': c.name})
|
|
elif kwargs['name'] is not None and kwargs['listing'] is True:
|
|
if c.node == storagenode.name and c.name == kwargs['name']:
|
|
name_storagelist.append({'#STORNAME': c.name})
|
|
except KeyError:
|
|
return [c.name for c in cls.instances if c.node == storagenode.name]
|
|
return name_storagelist
|
|
|
|
def get_storageinfo(self, parameter=None):
|
|
"""
|
|
Get Virtual Machine data
|
|
:param parameter: Specific VM stat e.g.: CPU Usage, use if you want to get one parameter for Zabbix
|
|
:return: list od dicts with vm params
|
|
"""
|
|
if parameter is not None:
|
|
storage_params = self.__getattribute__(parameter)
|
|
return storage_params
|
|
else:
|
|
storage_params = list()
|
|
for param in vars(self):
|
|
if not param.startswith('__'):
|
|
storage_params.append({'#' + param.upper(): self.__getattribute__(param)})
|
|
return listofdicts_to_zabbix_json(storage_params)
|