Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit d6aaf9f5 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent 8e75d919
No related branches found
No related tags found
No related merge requests found
[PACKAGE]: ../../raw/master/mkp/vsphere_topo-0.0.6-20240729.mkp "vsphere_topo-0.0.6-20240729.mkp"
[PACKAGE]: ../../raw/master/mkp/vsphere_topo-0.0.7-20240801.mkp "vsphere_topo-0.0.7-20240801.mkp"
# vSphere Topology Visualization
This plugin uses the data from the _VMware ESX via vSphere_ special agent to create a topology of the vSphere environment.\
......
File added
......@@ -21,6 +21,7 @@
# 2024-07-25: fixed crash if VM has no data store
# 2024-07-29: added option to ignore powered off VMs
# added option to ignore VMs by name (regex)
# 2024-07-31: added option to map vSphere names to CMK/topology names for data center, cluster, hosts and VMs
from collections.abc import Mapping, Sequence
from re import compile as re_compile
......@@ -51,6 +52,7 @@ from cmk_addons.plugins.vsphere_topo.constants import (
PARAM_IGNORE_POWERED_OFF_VMS,
PARAM_IGNORE_VM_NAME_REGEX,
PARAM_MAKE_DEFAULT,
PARAM_MAP_NAMES,
PARAM_VCENTER,
PARAM_VM_NAMES,
RULE_SET_NAME_VSPHERE_TOPO,
......@@ -64,6 +66,7 @@ from cmk_addons.plugins.vsphere_topo.lib.utils import (
add_dummy_topologies,
adjust_name,
get_emblem,
get_name_map,
make_topo_default,
save_topology,
)
......@@ -90,6 +93,9 @@ def check_vsphere_topo(
connections: TopoConnections = TopoConnections()
ignored_powered_off_vms: int = 0
ignored_by_name_vms: int = 0
name_map = get_name_map(params.get(PARAM_MAP_NAMES, []))
if ignore_by_name_str := ')|('.join(params.get(PARAM_IGNORE_VM_NAME_REGEX, [])):
re_ignore_vms = re_compile(f'({ignore_by_name_str})')
else:
......@@ -112,8 +118,9 @@ def check_vsphere_topo(
)
vsphere_host = f'vc{raw_vsphere_host}'
for cluster in section_esx_vsphere_clusters:
data_center: str = section_esx_vsphere_clusters[cluster]['datacenter'].strip()
for raw_cluster in section_esx_vsphere_clusters:
data_center: str = section_esx_vsphere_clusters[raw_cluster]['datacenter'].strip()
data_center = name_map.get(data_center, data_center)
if objects.topo_objects.get(data_center) is None:
objects.add_host(
host=data_center,
......@@ -121,6 +128,7 @@ def check_vsphere_topo(
link2core=False,
)
connections.add_connection(data_center, vsphere_host)
cluster = name_map.get(raw_cluster, raw_cluster)
objects.add_host(
host=cluster,
emblem=get_emblem(EMBLEM_CLUSTER, params.get(PARAM_CLUSTER)),
......@@ -128,9 +136,10 @@ def check_vsphere_topo(
)
connections.add_connection(cluster, data_center)
host_systems: Sequence[str] = section_esx_vsphere_clusters[cluster].get('hostsystems', '').split(',')
host_systems: Sequence[str] = section_esx_vsphere_clusters[raw_cluster].get('hostsystems', '').split(',')
for host_system in host_systems:
esx_name: str = adjust_name(host_system, params.get(PARAM_HOST_SYSTEMS, {}))
esx_name = name_map.get(esx_name, esx_name)
objects.add_host(host=esx_name)
connections.add_connection(cluster, esx_name)
yield Result(
......@@ -177,7 +186,9 @@ def check_vsphere_topo(
if params.get(PARAM_IGNORE_POWERED_OFF_VMS) is not True or vm.get('powerstate') != 'poweredOff':
vm_name: str = adjust_name(vm['vm_name'], params.get(PARAM_VM_NAMES, {}))
if re_ignore_vms is None or re_ignore_vms.match(vm_name) is None:
vm_name = name_map.get(vm_name, vm_name)
host_system: str = adjust_name(vm['hostsystem'], params.get(PARAM_HOST_SYSTEMS, {}))
host_system = name_map.get(host_system, host_system)
objects.add_host(host=vm_name)
connections.add_connection(vm_name, host_system)
else:
......
......@@ -31,6 +31,9 @@ PARAM_IGNORE_VM_NAME_REGEX: Final[str] = 'ignore_vms_by_name'
PARAM_KEEP_DOMAIN: Final[str] = 'keep_domain'
PARAM_LOWER: Final[str] = 'lower'
PARAM_MAKE_DEFAULT: Final[str] = 'make_default'
PARAM_MAP_NAMES: Final[str] = 'map_names'
PARAM_MAP_NAME_CMK: Final[str] = 'name_cmk'
PARAM_MAP_NAME_VSPHERE: Final[str] = 'name_vsphere'
PARAM_NO_CHANGE: Final[str] = 'no_change'
PARAM_NO_EMBLEM: Final[str] = 'no_emblem'
PARAM_PREFIX: Final[str] = 'prefix'
......
......@@ -12,6 +12,7 @@ from collections.abc import Mapping, MutableMapping, MutableSequence, Sequence
from json import dumps as json_dunps, loads as json_loads
from os import environ
from pathlib import Path
from re import compile as re_compile
from typing import Final, Tuple
from livestatus import MultiSiteConnection, SiteConfigurations, SiteId
......@@ -21,6 +22,8 @@ from cmk_addons.plugins.vsphere_topo.constants import (
PARAM_DEFAULT_EMBLEM,
PARAM_KEEP_DOMAIN,
PARAM_LOWER,
PARAM_MAP_NAME_CMK,
PARAM_MAP_NAME_VSPHERE,
PARAM_NO_CHANGE,
PARAM_NO_EMBLEM,
PARAM_PREFIX,
......@@ -31,6 +34,17 @@ OMD_ROOT = environ['OMD_ROOT']
BASE_TOPO_PATH: Final[str] = f'{OMD_ROOT}/var/check_mk/topology/data'
def get_name_map(mappings: Sequence):
re_hostname = re_compile(r'^[0-9a-zA-Z\.\-\_]+$')
name_map = {}
for mapping in mappings:
if re_hostname.match(mapping[PARAM_MAP_NAME_CMK]) is not None:
name_map[mapping[PARAM_MAP_NAME_VSPHERE]] = mapping[PARAM_MAP_NAME_CMK]
return name_map
def adjust_name(name: str, params: Mapping[str, object]) -> str:
class Case:
upper: str = PARAM_UPPER
......
......@@ -11,8 +11,9 @@
# removed PARAM_ADD_DUMMY_TOPOLOGIES and PARAM_DONT_ADD_VC_AS_VM
from collections.abc import Mapping, Sequence
from re import compile as re_compile
from cmk.rulesets.v1 import Help, Label, Title
from cmk.rulesets.v1 import Help, Label, Title, Message
from cmk.rulesets.v1.form_specs import (
CascadingSingleChoice,
CascadingSingleChoiceElement,
......@@ -20,12 +21,12 @@ from cmk.rulesets.v1.form_specs import (
DictElement,
Dictionary,
FixedValue,
List,
SingleChoice,
SingleChoiceElement,
String,
List,
)
from cmk.rulesets.v1.form_specs.validators import LengthInRange
from cmk.rulesets.v1.form_specs.validators import LengthInRange, MatchRegex
from cmk.rulesets.v1.rule_specs import CheckParameters, HostCondition, Topic
from cmk_addons.plugins.vsphere_topo.constants import (
# PARAM_ADD_DUMMY_TOPOLOGIES,
......@@ -47,6 +48,9 @@ from cmk_addons.plugins.vsphere_topo.constants import (
PARAM_KEEP_DOMAIN,
PARAM_LOWER,
PARAM_MAKE_DEFAULT,
PARAM_MAP_NAMES,
PARAM_MAP_NAME_CMK,
PARAM_MAP_NAME_VSPHERE,
PARAM_NO_CHANGE,
PARAM_NO_EMBLEM,
PARAM_PREFIX,
......@@ -194,14 +198,40 @@ def _parameter_form() -> Dictionary:
PARAM_IGNORE_VM_NAME_REGEX: DictElement(
parameter_form=List(
title=Title('Ignore VMs by name (regex)'),
element_template=String(
title=Title('add regex string')
),
element_template=String(),
help_text=Help(
'The regex strings will be applied after the upper/lower case and prefix '
'change to the VM names. If there more than one regex string the will be "OR" connected.'
),
)),
PARAM_MAP_NAMES: DictElement(
parameter_form=List(
title=Title('Map vSphere names to CMK names'),
element_template=Dictionary(
elements={
PARAM_MAP_NAME_VSPHERE: DictElement(
parameter_form=String(
title=Title('vSphere name'),
),
required=True,
),
PARAM_MAP_NAME_CMK: DictElement(
parameter_form=String(
title=Title('Checkmk name'),
custom_validate=(MatchRegex(
regex=r'^[0-9a-zA-Z\.\-\_]+$',
error_msg=Message(
'Your input does not match the required format. '
'Only "0-9a-zA-Z_-." are allowed.'
)
),)
),
required=True,
)
}
),
help_text=Help(''),
)),
# PARAM_DONT_ADD_VC_AS_VM: DictElement(
# render_only=True,
# parameter_form=FixedValue(
......
......@@ -13,7 +13,7 @@
'vsphere_topo/rulesets/vsphere_topo.py']},
'name': 'vsphere_topo',
'title': 'vSphere Topologie',
'version': '0.0.6-20240729',
'version': '0.0.7-20240801',
'version.min_required': '2.3.0b1',
'version.packaged': 'cmk-mkp-tool 0.2.0',
'version.usable_until': '2.4.0b1'}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment