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 fab3f1fa authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent 16cac35e
No related branches found
No related tags found
No related merge requests found
......@@ -116,7 +116,7 @@ def parse_arguments() -> arg_Namespace:
parser.add_argument(
'--keep', type=int,
help=f'Number of topologies to keep. The oldest topologies above keep\n'
f'max will be deleted. The minimum value for --keep is 1.\n'
f'max will be deleted.\n'
f'NOTE: The default topologies will be always kept.\n'
)
command_group.add_argument(
......@@ -127,7 +127,6 @@ def parse_arguments() -> arg_Namespace:
'--min-age', type=int,
help=f'The minimum number of days before a topology is deleted\n'
f'by "--keep".\n'
f'NOTE: Topologies that are not older than 1 days are always kept.',
)
parser.add_argument(
'--time-format', type=str,
......
......@@ -17,8 +17,6 @@ from enum import Enum, unique
from create_topology_utils import (
CREATE_TOPOLOGY_VERSION,
PATH_CDP,
COLUMNS_CDP,
LABEL_CDP,
PATH_LLDP,
PATH_INTERFACES,
USER_DATA_FILE,
......@@ -32,12 +30,6 @@ from create_topology_utils import (
)
class TopologyParams(NamedTuple):
path: str
columns: str
label: str
@unique
class CacheSources(Enum):
inventory = 'inventory'
......@@ -50,14 +42,6 @@ class InventoryColumns(NamedTuple):
neighbour_port: str
class Interface(NamedTuple):
host: str
index: str
name: str
description: str
alias: str
class StaticConnection(NamedTuple):
host: str
local_port: str
......@@ -81,9 +65,6 @@ class Settings:
self.__settings = {
'layers': [],
'seed_devices': None,
'path_in_inventory': PATH_CDP,
'inventory_columns': COLUMNS_CDP,
'data_source': LABEL_CDP,
'time_format': '%Y-%m-%dT%H:%M:%S.%m',
'user_data_file': f'{self.__omd_root}/local/bin/topology_data/{USER_DATA_FILE}',
'output_directory': None,
......@@ -118,11 +99,6 @@ class Settings:
print(f'-l/--layers options must be unique. Don~\'t use any layer more than once.')
exit(code=ExitCodes.BAD_OPTION_LIST.value)
def set_topology_param(self, topology: Dict[str, str]):
self.__settings['path_in_inventory'] = topology['path']
self.__settings['inventory_columns'] = topology['columns']
self.__settings['data_source'] = topology['label']
@property
def version(self) -> bool:
return self.__settings['version']
......@@ -134,14 +110,14 @@ class Settings:
@property
def keep(self) -> int | None:
if self.__settings['keep']:
return max(self.__settings['keep'], 1)
return max(self.__settings['keep'], 0)
@property
def min_age(self) -> int:
if self.__settings['min_age']:
return max(self.__settings['min_age'], 1)
return max(self.__settings['min_age'], 0)
else:
return 1
return 0
@property
def check_user_data_only(self) -> bool:
......@@ -191,24 +167,6 @@ class Settings:
def topology_file_name(self) -> str:
return self.__topology_file_name
@property
def path_in_inventory(self) -> List[str]:
return self.__settings['path_in_inventory']
# @property
# def path_to_if_table(self) -> List[str]:
# path = ('Nodes,' + ',Nodes,'.join(self.__path_to_if_table.split(',')) + ',Table,Rows').split(',')
# return path
@property
def inventory_columns(self) -> InventoryColumns:
columns = self.__settings['inventory_columns'].split(',')
return InventoryColumns(
neighbour=columns[0],
local_port=columns[1],
neighbour_port=columns[2],
)
@property
def seed_devices(self) -> List[str]:
if self.__settings['seed_devices']:
......@@ -216,10 +174,6 @@ class Settings:
else:
return []
@property
def data_source(self) -> str:
return self.__settings['data_source']
@property
def output_directory(self) -> str:
if not self.__settings['output_directory']:
......
......@@ -33,6 +33,7 @@
# removed option --data-source, now handled in CUSTOM_LAYERS
# removed option --inventory-columns, now handled in CUSTOM_LAYERS
# removed option --path-in-inventory, now handled in CUSTOM_LAYERS
# removed lower limits for --keep and --min-age
#
# PoC for creating topology_data.json from inventory data
......@@ -139,10 +140,11 @@ def create_device_from_inv(
host: str,
inv_data: List[Dict[str, str]],
inv_columns: InventoryColumns,
data_source: str,
label: str,
debug: bool = False,
) -> Dict[str, Any] | None:
data = {'connections': {}, "interfaces": []}
for topo_neighbour in inv_data:
neighbour = topo_neighbour.get(inv_columns.neighbour)
if not neighbour:
......@@ -175,7 +177,7 @@ def create_device_from_inv(
print(f'neighbour: {neighbour}, neighbour_port {neighbour_port}, _neighbour_port {_neighbour_port}')
if neighbour and local_port and neighbour_port:
data['connections'].update({local_port: [neighbour, neighbour_port, data_source]})
data['connections'].update({local_port: [neighbour, neighbour_port, label]})
if local_port not in data['interfaces']:
data['interfaces'].append(local_port)
......@@ -217,7 +219,7 @@ def create_topology(
seed_devices: List[str],
path_in_inventory: List[str],
inv_columns: InventoryColumns,
data_source: str,
label: str,
debug: bool = False,
) -> Dict:
devices_to_go = list(set(seed_devices)) # remove duplicates
......@@ -247,7 +249,7 @@ def create_topology(
host=device,
inv_data=topo_data,
inv_columns=inv_columns,
data_source=data_source,
label=label,
))
devices_list = get_list_of_devices(topology_data[device]['connections'])
for entry in devices_list:
......@@ -258,9 +260,9 @@ def create_topology(
devices_done.append(device)
devices_to_go.remove(device)
if debug:
print(f'Device done: {device}, source: {data_source}')
print(f'Device done: {device}, source: {label}')
print(f'Devices added: {len(devices_done)}, source {data_source}')
print(f'Devices added: {len(devices_done)}, source {label}')
return topology_data
......@@ -294,12 +296,16 @@ if __name__ == '__main__':
if job == 'STATIC':
topology = create_static_connections(connections=user_data.get('STATIC_CONNECTIONS', []))
else:
SETTINGS.set_topology_param(job)
columns = job['columns'].split(',')
topology = create_topology(
seed_devices=list(set(SETTINGS.seed_devices + user_data.get('SEED_DEVICES', []))),
path_in_inventory=SETTINGS.path_in_inventory,
inv_columns=SETTINGS.inventory_columns,
data_source=SETTINGS.data_source,
path_in_inventory=job['path'],
inv_columns=InventoryColumns(
neighbour=columns[0],
local_port=columns[1],
neighbour_port=columns[2]
),
label=job['label'],
debug=SETTINGS.debug,
)
if topology:
......
No preview for this file type
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