diff --git a/README.md b/README.md index 53f352ca139a2cc30399691968fc328fcc5e2f10..6a57f2949585f0eed9b0ffc67381f91e76747fff 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[PACKAGE]: ../../raw/master/mkp/vsphere_topo-0.0.3-20240711.mkp "vsphere_topo-0.0.3-20240711.mkp" +[PACKAGE]: ../../raw/master/mkp/vsphere_topo-0.0.4-20240712.mkp "vsphere_topo-0.0.4-20240712.mkp" # vSphere Topology Visualization This plugin uses the data from the _VMware ESX via vSphere_ spezial agent to create a topolofy of the vSphere environment. diff --git a/mkp/vsphere_topo-0.0.4-20240712.mkp b/mkp/vsphere_topo-0.0.4-20240712.mkp new file mode 100644 index 0000000000000000000000000000000000000000..8dbbc8f77a28d3d96f7fc565767ea841b18b7207 Binary files /dev/null and b/mkp/vsphere_topo-0.0.4-20240712.mkp differ diff --git a/source/cmk_addons_plugins/vsphere_topo/agent_based/packages.py b/source/cmk_addons_plugins/vsphere_topo/agent_based/packages.py index 8c70ca95e9df85996d3c7817cc14d19cdd7adffc..63fc3dedc90fde82ce7588832ec4e5aeef2a95d6 100644 --- a/source/cmk_addons_plugins/vsphere_topo/agent_based/packages.py +++ b/source/cmk_addons_plugins/vsphere_topo/agent_based/packages.py @@ -14,6 +14,7 @@ # -> obsoletes 'Add dummy topologies' # added vCenter twice (once as vCenter once as vM) with different object IDs # -> obsoletes 'Don\'t add vCenter as VM' +# 2024-07-12: added support for Queried host is a host system from collections.abc import Mapping, Sequence from pathlib import Path @@ -124,86 +125,86 @@ def check_vsphere_topo( objects = {} connections = [] - raw_vsphere_host: str = host_name().strip() - add_host( - host=raw_vsphere_host, - obj_id_prefix='vc', - # icon='icon_topic_hosts', - icon=get_emblem(ICON_VCENTER, params.get(PARAM_VCENTER)), - ) - vsphere_host = f'vc{raw_vsphere_host}' - - __clusters = { - 'HA': { - 'datacenter': 'datacenter-21', - 'hostsystems': 'esxi01, esxi02', - 'vms': 'vmname01, vmname02, vmname03' + if section_esx_vsphere_clusters is not None: + __clusters = { + 'HA': { + 'datacenter': 'datacenter-21', + 'hostsystems': 'esxi01, esxi02', + 'vms': 'vmname01, vmname02, vmname03' + } } - } - if section_esx_vsphere_clusters is None: - yield Result( - state=State.UNKNOWN, - summary='Found no vSphere data centers/clusters. This service needs the "VMware ESX via vSphere" ' - 'option "Type of query" set to "Queried host is vCenter"' + raw_vsphere_host: str = host_name().strip() + add_host( + host=raw_vsphere_host, + obj_id_prefix='vc', + icon=get_emblem(ICON_VCENTER, params.get(PARAM_VCENTER)), ) - return - - for cluster in section_esx_vsphere_clusters: - data_center: str = section_esx_vsphere_clusters[cluster]['datacenter'].strip() - if objects.get(data_center) is None: + vsphere_host = f'vc{raw_vsphere_host}' + + for cluster in section_esx_vsphere_clusters: + data_center: str = section_esx_vsphere_clusters[cluster]['datacenter'].strip() + if objects.get(data_center) is None: + add_host( + host=data_center, + emblem=get_emblem(EMBLEM_DATA_CENTER, params.get(PARAM_DATA_CENTER)), + link2core=False, + ) + add_connection(data_center, vsphere_host) add_host( - host=data_center, - emblem=get_emblem(EMBLEM_DATA_CENTER, params.get(PARAM_DATA_CENTER)), - link2core=False, + host=cluster, + emblem=get_emblem(EMBLEM_CLUSTER, params.get(PARAM_CLUSTER)), + link2core=False ) - add_connection(data_center, vsphere_host) - add_host( - host=cluster, - emblem=get_emblem(EMBLEM_CLUSTER, params.get(PARAM_CLUSTER)), - link2core=False + add_connection(cluster, data_center) + + host_systems: Sequence[str] = section_esx_vsphere_clusters[cluster].get('hostsystems', '').split(',') + for host_system in host_systems: + esx_name: str = adjust_name(host_system, params.get(PARAM_HOST_SYSTEMS, {})) + add_host(host=esx_name) + add_connection(cluster, esx_name) + yield Result( + state=State.OK, + notice='VMware ESX via vSphere agent type of query: Queried host is the vCenter' + ) + else: # assuming the query type is ESXi host + raw_vsphere_host: str = host_name().strip() + add_host(host=raw_vsphere_host) + vsphere_host = raw_vsphere_host + yield Result( + state=State.OK, + notice='VMware ESX via vSphere agent type of query: Queried host is a host system' ) - add_connection(cluster, data_center) - - host_systems: Sequence[str] = section_esx_vsphere_clusters[cluster].get('hostsystems', '').split(',') - for host_system in host_systems: - esx_name: str = adjust_name(host_system, params.get(PARAM_HOST_SYSTEMS, {})) - add_host(host=esx_name) - add_connection(cluster, esx_name) - - __VMs = [ - { - 'vm_name': 'vmname01', - 'hostsystem': 'esxi01', - 'powerstate': 'poweredOff', - 'guest_os': 'Microsoft Windows Server 2008 R2 (64-bit)', - 'compatibility': 'vmx-10', - 'uuid': '420354bd-bee0-88d5-053c-d4f424106b0f' - }, - { - 'vm_name': 'vmname02', - 'hostsystem': 'esxi02', - 'powerstate': 'poweredOn', - 'guest_os': 'Microsoft Windows Server 2019 (64-bit)', - 'compatibility': 'vmx-19', - 'uuid': '422eba9f-0327-2da0-b546-f5a5e5dfdb68' - }, - { - 'vm_name': 'vmname03', - 'hostsystem': 'esxi01', - 'powerstate': 'poweredOn', - 'guest_os': 'Other 3.x or later Linux (64-bit)', - 'compatibility': 'vmx-11', - 'uuid': '422e3863-b7de-dc55-74f8-6dc9c159b36d' - } - ] if section_esx_vsphere_virtual_machines is not None: + __VMs = [ + { + 'vm_name': 'vmname01', + 'hostsystem': 'esxi01', + 'powerstate': 'poweredOff', + 'guest_os': 'Microsoft Windows Server 2008 R2 (64-bit)', + 'compatibility': 'vmx-10', + 'uuid': '420354bd-bee0-88d5-053c-d4f424106b0f' + }, + { + 'vm_name': 'vmname02', + 'hostsystem': 'esxi02', + 'powerstate': 'poweredOn', + 'guest_os': 'Microsoft Windows Server 2019 (64-bit)', + 'compatibility': 'vmx-19', + 'uuid': '422eba9f-0327-2da0-b546-f5a5e5dfdb68' + }, + { + 'vm_name': 'vmname03', + 'hostsystem': 'esxi01', + 'powerstate': 'poweredOn', + 'guest_os': 'Other 3.x or later Linux (64-bit)', + 'compatibility': 'vmx-11', + 'uuid': '422e3863-b7de-dc55-74f8-6dc9c159b36d' + } + ] for vm in section_esx_vsphere_virtual_machines: vm_name: str = adjust_name(vm['vm_name'], params.get(PARAM_VM_NAMES, {})) - - # if params.get(PARAM_DONT_ADD_VC_AS_VM) is True and vm_name.lower() == vsphere_host.lower(): - # continue host_system: str = adjust_name(vm['hostsystem'], params.get(PARAM_HOST_SYSTEMS, {})) add_host(host=vm_name) add_connection(vm_name, host_system) @@ -256,8 +257,6 @@ def check_vsphere_topo( if (vm_to_data_stores := ls_connection.query(query=query)) is not None: for vm, data_stores in vm_to_data_stores: vm_name: str = adjust_name(vm, params.get(PARAM_VM_NAMES, {})) - # if params.get(PARAM_DONT_ADD_VC_AS_VM) is True and vm_name.lower() == vsphere_host.lower(): - # continue if vm_name in objects: data_stores = data_stores.split(',') for data_store in data_stores: @@ -274,7 +273,6 @@ def check_vsphere_topo( 'version': 1, 'name': 'vSphere', 'objects': dict(sorted(objects.items())), - # 'objects': objects, 'connections': connections, } @@ -282,7 +280,7 @@ def check_vsphere_topo( # workaround for backend is only picking up topologies from default folder path: str = f'{OMD_ROOT}/var/check_mk/topology/data/default' - if Path(path).exists(): + if Path(path).exists() and not Path(f'{path}/data_vsphere.json').exists(): # don't overwrite existing topology dummy_topology = {'version': 1, 'name': 'vSphere', 'objects': {}, 'connections': []} save_data_to_file( data=dummy_topology, @@ -294,6 +292,7 @@ def check_vsphere_topo( for topology in get_topologies(): data_sets.append({'version': 1, 'name': topology, 'objects': {}, 'connections': []}) # end workaround + data_sets.append(data_set_vsphere) path: str = f'{OMD_ROOT}/var/check_mk/topology/data/{raw_vsphere_host}' diff --git a/source/cmk_addons_plugins/vsphere_topo/lib/utils.py b/source/cmk_addons_plugins/vsphere_topo/lib/utils.py index 2e8ca1da73f64ab834e8b2a12cd6750a3d96e66d..c377dca75e34d02892afa60274c3391a45423ea8 100644 --- a/source/cmk_addons_plugins/vsphere_topo/lib/utils.py +++ b/source/cmk_addons_plugins/vsphere_topo/lib/utils.py @@ -39,8 +39,8 @@ PARAM_NO_CHANGE: Final[str] = 'no_change' PARAM_NO_EMBLEM: Final[str] = 'no_emblem' PARAM_PREFIX: Final[str] = 'prefix' PARAM_UPPER: Final[str] = 'upper' -PARAM_VM_NAMES: Final[str] = 'vm_names' PARAM_VCENTER: Final[str] = 'vcenter_icon' +PARAM_VM_NAMES: Final[str] = 'vm_names' PICTURE_TYPE_EMBLEM: Final[str] = 'emblem' PICTURE_TYPE_ICON: Final[str] = 'icon' @@ -127,10 +127,10 @@ def get_topologies() -> Sequence[str | None]: json_loads(Path(file).read_text()).get('name') is not None ] + # # live status # - class LiveStatusConnection(object): def __init__(self): self.sites: SiteConfigurations = SiteConfigurations({}) diff --git a/source/cmk_addons_plugins/vsphere_topo/rulesets/packages.py b/source/cmk_addons_plugins/vsphere_topo/rulesets/packages.py index bcbb4e5a54e51bc3dcb552d56de30c46eb8c16e6..974e6e0b358e14435b77da4bd29dd6c64f2d29d5 100644 --- a/source/cmk_addons_plugins/vsphere_topo/rulesets/packages.py +++ b/source/cmk_addons_plugins/vsphere_topo/rulesets/packages.py @@ -22,13 +22,13 @@ from cmk.rulesets.v1.form_specs import ( SingleChoiceElement, String, ) - from cmk.rulesets.v1.form_specs.validators import LengthInRange from cmk.rulesets.v1.rule_specs import CheckParameters, HostCondition, Topic from cmk_addons.plugins.vsphere_topo.lib.utils import ( EMBLEM_CLUSTER, EMBLEM_DATA_CENTER, EMBLEM_DATA_STORE, + ICON_VCENTER, PARAM_ADD_DUMMY_TOPOLOGIES, PARAM_CHANGE_CASE, PARAM_CLUSTER, @@ -46,12 +46,11 @@ from cmk_addons.plugins.vsphere_topo.lib.utils import ( PARAM_NO_EMBLEM, PARAM_PREFIX, PARAM_UPPER, - PARAM_VM_NAMES, - RULE_SET_NAME_VSPHERE_TOPO, PARAM_VCENTER, - ICON_VCENTER, + PARAM_VM_NAMES, PICTURE_TYPE_EMBLEM, PICTURE_TYPE_ICON, + RULE_SET_NAME_VSPHERE_TOPO, ) adjust_names_elements: Mapping[str, DictElement] = { diff --git a/source/packages/vsphere_topo b/source/packages/vsphere_topo index d74824776f4ca9fcf4b12a46c20c29d2246d7655..b417aa7d1be3b17463b9956bb4dbae566cd995ac 100644 --- a/source/packages/vsphere_topo +++ b/source/packages/vsphere_topo @@ -12,7 +12,7 @@ 'vsphere_topo/graphing/packages.py']}, 'name': 'vsphere_topo', 'title': 'vSphere Topologie', - 'version': '0.0.3-20240711', + 'version': '0.0.4-20240712', 'version.min_required': '2.3.0b1', 'version.packaged': 'cmk-mkp-tool 0.2.0', 'version.usable_until': '2.4.0b1'}