diff --git a/lib/check/guests.py b/lib/check/guests.py index 3eda4ef..9b8a6af 100644 --- a/lib/check/guests.py +++ b/lib/check/guests.py @@ -37,21 +37,8 @@ async def check_guests( guests = [{ 'name': str(d['vmid']), # str - 'status': d['status'], # ??? - 'vmid': d['vmid'], # ??? - 'cpu': d.get('cpu'), # ??? - 'cpus': d.get('cpus'), # ??? - 'disk': d.get('disk'), # ??? - 'diskread': d.get('diskread'), # ??? - 'diskwrite': d.get('diskwrite'), # ??? - 'maxdisk': d.get('maxdisk'), # ??? - 'maxmem': d.get('maxmem'), # ??? - 'mem': d.get('mem'), # ??? - 'netin': d.get('netin'), # ??? - 'netout': d.get('netout'), # ??? - 'pid': d.get('pid'), # ??? - 'uptime': d.get('uptime'), # ??? - 'vmname': d.get('name'), # ??? + 'status': d['status'], # str + 'vm_name': d.get('name'), # str } for d in data['data']] return { 'guests': guests diff --git a/lib/check/network.py b/lib/check/network.py index c650eb3..0a9776f 100644 --- a/lib/check/network.py +++ b/lib/check/network.py @@ -1,6 +1,8 @@ import aiohttp +from typing import Optional from libprobe.asset import Asset from libprobe.exceptions import CheckException +from ..utils import to_bool DEFAULT_PORT = 8006 @@ -37,22 +39,21 @@ async def check_network( network = [{ 'name': d['iface'], # str - 'active': d.get('active'), # ???, optional - 'address': d.get('address'), # str, optional - 'autostart': d.get('autostart'), # ???, optional - 'bridge_fd': d.get('bridge_fd'), # ???, optional - 'bridge_ports': d.get('bridge_ports'), # ???, optional - 'bridge_stp': d.get('bridge_stp'), # ???, optional - 'cdir': d.get('cdir'), # ???, optional - 'exists': d.get('exists'), # ???, optional - 'families': d.get('families'), # ??? - 'gateway': d.get('gateway'), # ???, optional - 'method': d.get('method'), # ??? - 'method6': d.get('method6'), # ??? - 'netmask': d.get('netmask'), # ??? optional - 'priority': d.get('priority'), # ??? - 'type': d.get('type'), # ??? - + 'active': d.get('active'), # int/optional + 'address': d.get('address'), # str/optional + 'autostart': to_bool(d.get('autostart')), # int/optional + 'bridge_fd': d.get('bridge_fd'), # str/optional + 'bridge_ports': d.get('bridge_ports'), # str/ optional + 'bridge_stp': d.get('bridge_stp'), # str/optional + 'cdir': d.get('cdir'), # str/optional + 'exists': to_bool(d.get('exists')), # int/optional + 'families': d.get('families'), # liststr/optional + 'gateway': d.get('gateway'), # str/optional + 'method': d.get('method'), # str + 'method6': d.get('method6'), # str + 'netmask': d.get('netmask'), # str/optional + 'priority': d.get('priority'), # int + 'type': d.get('type'), # str } for d in data['data']] return { 'network': network diff --git a/lib/check/storage.py b/lib/check/storage.py index a187951..fe6a849 100644 --- a/lib/check/storage.py +++ b/lib/check/storage.py @@ -1,6 +1,7 @@ import aiohttp from libprobe.asset import Asset from libprobe.exceptions import CheckException +from ..utils import to_bool, to_list_str DEFAULT_PORT = 8006 @@ -36,17 +37,16 @@ async def check_storage( data = await resp.json() storage = [{ - 'name': d['storage'], # ??? - 'content': d['content'], # ??? - 'type': d['type'], # ??? - 'active': d.get('active'), # ??? - 'avail': d.get('avail'), # ??? - 'enabled': d.get('enabled'), # ??? - # 'format': d.get('format'), # ??? - 'shared': d.get('shared'), # ??? - 'total': d.get('total'), # ??? - 'used': d.get('used'), # ??? - 'used_fraction': d.get('used_fraction'), # ??? + 'name': d['storage'], # str + 'content': to_list_str(d['content']), # liststr + 'type': d['type'], # str + 'active': to_bool(d.get('active')), # bool + 'avail': d.get('avail'), # int + 'enabled': to_bool(d.get('enabled')), # bool + 'shared': to_bool(d.get('shared')), # bool + 'total': d.get('total'), # int + 'used': d.get('used'), # int + 'used_fraction': d.get('used_fraction'), # int } for d in data['data']] return { 'storage': storage diff --git a/lib/utils.py b/lib/utils.py new file mode 100644 index 0000000..d1bbbb1 --- /dev/null +++ b/lib/utils.py @@ -0,0 +1,13 @@ +from typing import Optional, List + + +def to_bool(val: Optional[int]) -> bool: + if val is None: + return + return bool(val) + + +def to_list_str(val: Optional[str]) -> List[str]: + if val is None or not isinstance(val, str): + return + return val.split(',')