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
create_topology_utils.py 4.2 KiB
Newer Older
thl-cmk's avatar
thl-cmk committed
#!/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  : 2023-10-12
# File  : create_topology_utils.py


from argparse import (
    Namespace as arg_Namespace,
    ArgumentParser,
    RawTextHelpFormatter,
)


def parse_arguments(create_topology_version: str) -> arg_Namespace:
    parser = ArgumentParser(
thl-cmk's avatar
thl-cmk committed
        prog='create_topology_data.py',
        description='This script creates the topology data file needed for the Checkmk "network_visualization" plugin by '
thl-cmk's avatar
thl-cmk committed
                    'Andreas Boesl and schnetz.\n'
thl-cmk's avatar
thl-cmk committed
                    'For more information see https://forum.checkmk.com/t/network-visualization/41680 and '
                    'https://exchange.checkmk.com/p/network-visualization\n'
thl-cmk's avatar
thl-cmk committed
                    '\n'
                    'The inventory data could be created with my inventory plugins:\n'
                    'CDP: https://thl-cmk.hopto.org/gitlab/checkmk/vendor-independent/inventory/inv_cdp_cache\n'
                    'LLDP: https://thl-cmk.hopto.org/gitlab/checkmk/vendor-independent/inventory/inv_lldp_cache\n'
                    '\n'
                    f'\nVersion: {create_topology_version} | Written by: thl-cmk, for more information '
                    f'see: https://thl-cmk.hopto.org',
        formatter_class=RawTextHelpFormatter,
        epilog='Usage:\n'
               'for CDP (the default):\n'
thl-cmk's avatar
thl-cmk committed
               '~/local/bin/network-topology/create_topology_data.py -s "CORE01,CORE02" -m\nor\n'
               '~/local/lib/topology_data/create_topology_data.py -s "CORE01,CORE02" -m '
thl-cmk's avatar
thl-cmk committed
               '-p "networking,cdp_cache" -c "device_id,local_port,device_port"\n\n'
               'for LLDP:\n'
thl-cmk's avatar
thl-cmk committed
               '~/local/lib/topology_data/create_topology.py -s "CORE01,CORE02" -m '
thl-cmk's avatar
thl-cmk committed
               '-p "networking,lldp_cache" -c "system_name,local_port_num,port_id"\n',
    )
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-s', '--seed-devices', type=str,
                        help='List of devices to start the topology discovery from. I.e. "CORE01, CORE02"')
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-v', '--version', default=False, action='store_const', const=True,
                        help='Print version of this script and exit')
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-p', '--path-in-inventory', type=str,
thl-cmk's avatar
thl-cmk committed
                        help='Checkmk inventory path to the topology data. I.e. "networking,cdp_cache"')
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-c', '--inventory-columns', type=str,
thl-cmk's avatar
thl-cmk committed
                        help='Columns used from the inventory data. I.e. "device_id,local_port,device_port"\n'
                             'NOTE: the columns must be in the order: neighbour, local_port, neighbour_port')
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-d', '--data-source', type=str,
                        help='The source from which the topology data originates. I.e. "inv_CDP" '
thl-cmk's avatar
thl-cmk committed
                             'for CDP data from the inventory. NOTE: right now this only an unused label.')
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-t', '--time-format', type=str,
thl-cmk's avatar
thl-cmk committed
                        help='Format string to render the time. (default: %%Y-%%m-%%dT%%H:%%M:%%S.%%m)')
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-o', '--output-directory', type=str,
thl-cmk's avatar
thl-cmk committed
                        help='Directory name where to save the topology data. I.e.: my_topology. '
thl-cmk's avatar
thl-cmk committed
                             'Default is the actual date/time in "--time-format" format.'
                             '\nNOTE: the directory is a sub directory under "~/var/topology_data/"')
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-m', '--make_default', default=False, action='store_const', const=True,
                        help='Set the created topology data as default')
thl-cmk's avatar
thl-cmk committed
    parser.add_argument('-k', '--keep-domain', default=False, action='store_const', const=True,
                        help='Do not remove the domain name from the neighbor name')

    command_group = parser.add_mutually_exclusive_group()
    command_group.add_argument('-u', '--uppercase', default=False, action='store_const', const=True,
                               help='Change neighbour names to all upper case')
    command_group.add_argument('-l', '--lowercase', default=False, action='store_const', const=True,
                               help='Change neighbour names to all lower case')
thl-cmk's avatar
thl-cmk committed
    return parser.parse_args()