diff --git a/README.md b/README.md index 2f96fdaa7b3b89e1078177627a636d744b650eea..05d21fff09a95f97af71bbdc7551f0bb15cc2b78 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[PACKAGE]: ../../raw/master/mkp/bgp_topology-0.0.3-20240104.mkp "bgp_topology-0.0.3-20240104.mkp" +[PACKAGE]: ../../raw/master/mkp/bgp_topology-0.0.4-20240116.mkp "bgp_topology-0.0.4-20240116.mkp" # BGP Topology This plugin will create a Network Visualization Topology from the Peer relations of your _BGP peer services_ in Checkmk. diff --git a/mkp/bgp_topology-0.0.4-20240116.mkp b/mkp/bgp_topology-0.0.4-20240116.mkp new file mode 100644 index 0000000000000000000000000000000000000000..4f1664b90c10b6cdca31c8bab5f94a06f7510015 Binary files /dev/null and b/mkp/bgp_topology-0.0.4-20240116.mkp differ diff --git a/source/cmk_addons_plugins/bgp_topology/constants.py b/source/cmk_addons_plugins/bgp_topology/constants.py index 950bb41c230d5b9348b607e22731760e48d3979a..0ca394efe4ffcc2398d3780d00662bfde3e7e846 100644 --- a/source/cmk_addons_plugins/bgp_topology/constants.py +++ b/source/cmk_addons_plugins/bgp_topology/constants.py @@ -13,7 +13,7 @@ __AUTHOR__ = 'thl-cmk[at]outlook[dot]com' __URL__ = 'https://thl-cmk.hopto.org/gitlab/checkmk/vendor-independent/bgp_topology' __USAGE__ = '~/local/lib/python3/cmk_addons/plugins/bgp_topology/libexec/check_bgp_topology --make-default --host bgp1' -__VERSION__ = '0.0.3-20250104' +__VERSION__ = '0.0.4-20250116' from typing import Final diff --git a/source/cmk_addons_plugins/bgp_topology/lib/args.py b/source/cmk_addons_plugins/bgp_topology/lib/args.py new file mode 100644 index 0000000000000000000000000000000000000000..4ed36e0fd6ed0199dc6a6432511636cf972ca850 --- /dev/null +++ b/source/cmk_addons_plugins/bgp_topology/lib/args.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# License: GNU General Public License v2 +# +# Author: thl-cmk[at]outlook[dot]com +# URL : https://thl-cmk.hopto.org +# Date : 2024-12-23 +# File : bgp_topology/lib/args.py + + +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from collections.abc import Sequence + +from cmk_addons.plugins.bgp_topology.constants import ( + __AUTHOR__, + __URL__, + __USAGE__, + __VERSION__, + ARG_PARSER_ANCHOR, + ARG_PARSER_ANCHOR_AS, + ARG_PARSER_ANCHOR_BOTH, + ARG_PARSER_ANCHOR_ID, + ARG_PARSER_EMBLEM_AS, + ARG_PARSER_EMBLEM_ID, + ARG_PARSER_HOST, + ARG_PARSER_MAKE_DEFAULT, + ARG_PARSER_NONE, + ARG_PARSER_SITES_EXCLUDE, + ARG_PARSER_SITES_INCLUDE, + ARG_PARSER_DEBUG, + EMBLEM_BGP_AS, + EMBLEM_BGP_ID, +) +from cmk_addons.plugins.bgp_topology.lib.utils import ( + OMD_ROOT, +) + + +class Params(Namespace): + bgp_anchor: str + make_default: bool = False + bgp_emblem_as: str = EMBLEM_BGP_AS + bgp_emblem_id: str = EMBLEM_BGP_ID + include_sites: Sequence[str] | None = None + exclude_sites: Sequence[str] | None = None + host: str = '' + debug: bool = False + + +def parse_arguments(argv: Sequence[str]) -> Params: + parser = ArgumentParser( + prog='bgp_topology', + formatter_class=RawTextHelpFormatter, + description=f"""Create BGP peer network topology for Checkmk""", + epilog=f""" +Example usage: +{__USAGE__} + +Version: {__VERSION__} | Written by {__AUTHOR__} +for more information see: {__URL__} + """ + ) + parser.add_argument( + ARG_PARSER_ANCHOR, + choices=[ + ARG_PARSER_ANCHOR_BOTH, + ARG_PARSER_ANCHOR_AS, + ARG_PARSER_ANCHOR_ID, + ARG_PARSER_NONE, + ], + default=ARG_PARSER_ANCHOR_BOTH, + help='Anchor for external BGP objects (default: %(default)s).', + ) + parser.add_argument( + ARG_PARSER_EMBLEM_AS, + type=str, + default=EMBLEM_BGP_AS, + help='Emblem to use for BGP-AS objects (default: %(default)s).', + ) + parser.add_argument( + ARG_PARSER_EMBLEM_ID, + type=str, + default=EMBLEM_BGP_ID, + help='Emblem to use for BGP-ID objects (default: %(default)s).', + ) + parser.add_argument( + ARG_PARSER_MAKE_DEFAULT, + action='store_const', const=True, + default=False, + help='Make this topology the default (default: %(default)s).', + ) + parser.add_argument( + ARG_PARSER_HOST, + required=True, + type=str, + help="""The name of the Checkmk host to which the plugin is attached. This is set +automatically by Checkmk. If a site filter is active, the host name is +appended to the subdirectory where the topology is stored (“BGP†becomes +“BGP_host_nameâ€). This way we can have more than one BGP topology without +overwriting each other.""", + ) + site_filter = parser.add_mutually_exclusive_group() + site_filter.add_argument( + ARG_PARSER_SITES_INCLUDE, + type=str, + nargs='+', + help=f"""List of Checkmk site names to include in the topology creation. +Can not used together with {ARG_PARSER_SITES_EXCLUDE}""", + ) + site_filter.add_argument( + ARG_PARSER_SITES_EXCLUDE, + type=str, + nargs='+', + help=f"""List of Checkmk site names to exclude from the topology creation. +Can not used together with {ARG_PARSER_SITES_INCLUDE}""", + ) + parser.add_argument( + ARG_PARSER_DEBUG, + action='store_const', const=True, + default=False, + help='enable debug output', + ) + + return parser.parse_args(argv) + diff --git a/source/cmk_addons_plugins/bgp_topology/lib/bgp_topology.py b/source/cmk_addons_plugins/bgp_topology/lib/bgp_topology.py index dbe86242a9c6585f36ffde22ed382401b406db90..4d4222124ca38c2385fce7d83035874e6eefa212 100644 --- a/source/cmk_addons_plugins/bgp_topology/lib/bgp_topology.py +++ b/source/cmk_addons_plugins/bgp_topology/lib/bgp_topology.py @@ -13,6 +13,7 @@ # fixed handling of anchors # changed topology name to be always BGP_{host} # 2025-01-04: changed output directory to host name only +# 2025-0116: fixed missing lib/args.py in MKP package from collections.abc import MutableMapping, MutableSequence, Sequence from dataclasses import dataclass diff --git a/source/packages/bgp_topology b/source/packages/bgp_topology index 41694557ac26ec96a1b2269678af59d966e13053..0635daa1a54f3213f05ac9326ad27d0b98048126 100644 --- a/source/packages/bgp_topology +++ b/source/packages/bgp_topology @@ -29,10 +29,11 @@ 'bgp_topology/libexec/check_bgp_topology', 'bgp_topology/rulesets/bgp_topology.py', 'bgp_topology/server_side_calls/bgp_topology.py', - 'bgp_topology/graphing/bgp_topology.py']}, + 'bgp_topology/graphing/bgp_topology.py', + 'bgp_topology/lib/args.py']}, 'name': 'bgp_topology', 'title': 'BGP peer topology', - 'version': '0.0.3-20240104', + 'version': '0.0.4-20240116', 'version.min_required': '2.3.0b1', 'version.packaged': 'cmk-mkp-tool 0.2.0', 'version.usable_until': '2.4.0b1'}