diff --git a/README.md b/README.md index 7c6b30a7a3f880eaaaa5e13aaa6ab6be0a4272b2..ac6a28b9963b0718f5a6a3a8536333a7b2256ffb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[PACKAGE]: ../../raw/master/mkp/nvdct-0.8.10-20240614.mkp "nvdct-0.8.10-20240614.mkp" +[PACKAGE]: ../../raw/master/mkp/nvdct-0.8.12-20240618.mkp "nvdct-0.8.12-20240618.mkp" # Network Visualization Data Creation Tool (NVDCT) This script creates the topology data file needed for the [Checkmk Exchange Network visualization](https://exchange.checkmk.com/p/network-visualization) plugin by Andreas Boesl and [schnetz](https://exchange.checkmk.com/u/schnetz).\ diff --git a/mkp/nvdct-0.8.12-20240618.mkp b/mkp/nvdct-0.8.12-20240618.mkp new file mode 100644 index 0000000000000000000000000000000000000000..7edee5d97ebb4aba0909d2abaf77ab34b2c70684 Binary files /dev/null and b/mkp/nvdct-0.8.12-20240618.mkp differ diff --git a/source/bin/nvdct/lib/backends.py b/source/bin/nvdct/lib/backends.py index 5500c6884a6a34674ab7a733bef02eedb563ddbd..0d3e454a5e1e2e82d1646c7ffc8872287b40de4e 100755 --- a/source/bin/nvdct/lib/backends.py +++ b/source/bin/nvdct/lib/backends.py @@ -8,6 +8,8 @@ # Date : 2023-10-12 # File : nvdct/lib/backends.py +# 2024-06-18: fixed host_exist returns always True if host was in host_cache, even with host=None + from _collections_abc import Mapping, Sequence from abc import abstractmethod from ast import literal_eval @@ -279,7 +281,7 @@ class HostCacheLiveStatus(HostCache): 'OutputFormat: python3\n' f'Filter: host_name = {host}\n' ) - if host in self.cache: + if self.cache.get(host) is not None: return True # if self.pre_fetch: # LOGGER.warning(f'{self.backend} pre_fetch host not found in cache {host}') @@ -287,6 +289,7 @@ class HostCacheLiveStatus(HostCache): data: Sequence[Sequence[str]] = self.get_raw_data(query=query) LOGGER.debug(f'{self.backend} data for host {host}: {data}') if [host] in data: + LOGGER.debug(f'{self.backend} Host {host} found in CMK') return True LOGGER.warning(f'{self.backend} Host {host} not found in CMK') @@ -347,6 +350,8 @@ class HostCacheMultiSite(HostCacheLiveStatus): self.pre_fetch_hosts() def get_sites(self): + # see: https://github.com/Checkmk/checkmk/blob/master/packages/cmk-livestatus-client/example_multisite.py + sites_mk = Path(f'{OMD_ROOT}/etc/check_mk/multisite.d/sites.mk') socket_path = f'unix:{OMD_ROOT}/tmp/run/live' if sites_mk.exists(): @@ -505,7 +510,7 @@ class HostCacheRestApi(HostCache): def host_exists(self, host: str) -> bool: LOGGER.debug(f'{self.backend} host_exists {host}') - if host in self.cache: + if self.cache.get(host) is not None: LOGGER.debug(f'{self.backend} host found in cache {host}') return True # if self.pre_fetch: @@ -657,7 +662,7 @@ class HostCacheFileSystem(HostCache): def host_exists(self, host: str) -> bool: # always True, don't works in distributed environments as autocheck files # are only locally available - return True + return False def get_hosts_by_label(self, label: str) -> List[str] | None: # not implemented, no (good) way to get a list of hosts from file system diff --git a/source/bin/nvdct/lib/settings.py b/source/bin/nvdct/lib/settings.py index c1a60b28262e7757419ef1d973e043f3006bf1d5..610abdc61e0a40aea07ba4e51053713aa5e3764b 100755 --- a/source/bin/nvdct/lib/settings.py +++ b/source/bin/nvdct/lib/settings.py @@ -8,6 +8,8 @@ # Date : 2023-10-12 # File : nvdct/lib/settings.py +# fixed path to default user data file + from _collections_abc import Mapping from ipaddress import AddressValueError, IPv4Address, IPv4Network, NetmaskValueError from logging import CRITICAL, FATAL, ERROR, WARNING, INFO, DEBUG @@ -96,7 +98,7 @@ class Settings: 'skip_l3_ip': False, 'time_format': TIME_FORMAT, 'uppercase': False, - 'user_data_file': f'{self.omd_root}/local/bin/nvdct/{USER_DATA_FILE}', + 'user_data_file': f'{self.omd_root}/local/bin/nvdct/conf/{USER_DATA_FILE}', 'version': False, } # args in the form {'s, __seed_devices': 'CORE01', 'p, __path_in_inventory': None, ... }} diff --git a/source/bin/nvdct/lib/topologies.py b/source/bin/nvdct/lib/topologies.py index a275815ce370362aa340dd651a20665e0745bfbb..712fb332c40881e9fe81edc6784cf7d8e32ded2f 100755 --- a/source/bin/nvdct/lib/topologies.py +++ b/source/bin/nvdct/lib/topologies.py @@ -30,7 +30,9 @@ class NvObjects: if host not in self.nv_objects: link: Dict = {} metadata: Dict = {} - if host_cache.host_exists(host=host): + # LOGGER.debug(f'host: {host}, {host_cache.host_exists(host=host)}') + if host_cache.host_exists(host=host) is True: + LOGGER.debug(f'host: {host} exists') link = {'core': host} else: if emblem is not None: @@ -49,6 +51,7 @@ class NvObjects: 'link': link, 'metadata': metadata, } + LOGGER.debug(f'host: {host}, link: {link}, metadata: {metadata}') def add_service_object( self, diff --git a/source/bin/nvdct/lib/utils.py b/source/bin/nvdct/lib/utils.py index a244981729fe1d189ba434508c48ecf7a80f4807..bf130f0ab6471e907f7df57b6ec9b15062b32c3e 100755 --- a/source/bin/nvdct/lib/utils.py +++ b/source/bin/nvdct/lib/utils.py @@ -23,7 +23,7 @@ from time import time as now_time from tomllib import loads as toml_loads, TOMLDecodeError from typing import List, Dict, TextIO -NVDCT_VERSION = '0.8.11-20240617' +NVDCT_VERSION = '0.8.12-20240618' @unique diff --git a/source/packages/nvdct b/source/packages/nvdct index 4811221eaa06723eceb86713f6dbf03dd19ef581..d4fb20c772cebfff8371f9be4cf91be15e5af5dd 100644 --- a/source/packages/nvdct +++ b/source/packages/nvdct @@ -58,7 +58,7 @@ 'htdocs/images/icons/location_80.png']}, 'name': 'nvdct', 'title': 'Network Visualization Data Creation Tool (NVDCT)', - 'version': '0.8.10-20240614', + 'version': '0.8.12-20240618', 'version.min_required': '2.2.0b1', 'version.packaged': 'cmk-mkp-tool 0.2.0', 'version.usable_until': '2.4.0p1'}