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
README.md 6.07 KiB
Newer Older
thl-cmk's avatar
thl-cmk committed
[PACKAGE]: ../../raw/master/create_topology_data-0.0.2-20231012.mkp "create_topology_data-0.0.2-20231012.mkp"
thl-cmk's avatar
thl-cmk committed
# PoC for creating topology_data.json from inventory data
thl-cmk's avatar
thl-cmk committed

thl-cmk's avatar
thl-cmk committed
This script creates the topology data file needed for the [Checkmk Exchange Network visualization](https://forum.checkmk.com/u/schnetz) plugin by Andreas Boesl and [schnetz](https://exchange.checkmk.com/u/schnetz). For more information see [Checkmk forum Network Visualization](https://forum.checkmk.com/t/network-visualization/41680). 
thl-cmk's avatar
thl-cmk committed

thl-cmk's avatar
thl-cmk committed
The network topology data is read from the Checkmk HW/SW inventory. The necessary inventory data can be created with my CDP/LLDP inventory plugins.
thl-cmk's avatar
thl-cmk committed

thl-cmk's avatar
thl-cmk committed
CDP: [CDP inventory plugin](https://thl-cmk.hopto.org/gitlab/checkmk/vendor-independent/inventory/inv_cdp_cache/)\
CDP path-in-inventory: `"networking,cdp_cache"`\
CDP inventory-columns: `"device_id,local_port,device_port"`

thl-cmk's avatar
thl-cmk committed
LLDP: [LLDP inventory plugin](https://thl-cmk.hopto.org/gitlab/checkmk/vendor-independent/inventory/inv_lldp_cache/)\
thl-cmk's avatar
thl-cmk committed
LLDP path-in-inventory: `"networking,lldp_cache"`\
LLDP inventory-columns: `"system_name,local_port_num,port_id"`

thl-cmk's avatar
thl-cmk committed
Usage with CDP (this is the default):
thl-cmk's avatar
thl-cmk committed
```
~/local/lib/topology_data/create_topology_data.py -s CORE01 -m
```

thl-cmk's avatar
thl-cmk committed
Usage with LLDP:
thl-cmk's avatar
thl-cmk committed
```
thl-cmk's avatar
thl-cmk committed
~/local/lib/topology_data/create_topology_data.py -s CORE01 -m -p "networking,lldp_cache" -c "system_name,local_port_num,port_id" -d inv_LLDP
thl-cmk's avatar
thl-cmk committed
```
thl-cmk's avatar
thl-cmk committed

---
### Download
* [Download latest mkp file][PACKAGE]
                        
---
### Installation

You can install the package by uploading it to your CheckMK site and as site user run 
```
mkp add PAKAGE_NAME.mkp
mkp enable PAKAGE_NAME VERSION
```

In the Enterprise/Free/Cloud edition of CheckMK you can use the GUI to install the package (_Setup_ -> _Extension Packages_ -> _Upload package_)

---
### Want to Contribute?

Nice ;-) Have a look at the [contribution guidelines](CONTRIBUTING.md "Contributing")

thl-cmk's avatar
thl-cmk committed
---
### Usage

```
thl-cmk's avatar
thl-cmk committed
OMD[build]:~$ ./local/bin/topology_data/create_topology_data.py -h
thl-cmk's avatar
thl-cmk committed
usage: create_topology_data.py [-h] [-s SEED_DEVICES [SEED_DEVICES ...]] [-v] [-p PATH_IN_INVENTORY [PATH_IN_INVENTORY ...]] [-c INVENTORY_COLUMNS] [-d DATA_SOURCE] [-t TIME_FORMAT] [-o OUTPUT_DIRECTORY] [-m] [-k] [-u | -l]
thl-cmk's avatar
thl-cmk committed

This script creates the topology data file needed for the Checkmk "network_visualization" plugin by Andreas Boesl and schnetz.
For more information see https://forum.checkmk.com/t/network-visualization/41680 and https://exchange.checkmk.com/p/network-visualization

The inventory data could be created with my inventory plugins:
CDP: https://thl-cmk.hopto.org/gitlab/checkmk/vendor-independent/inventory/inv_cdp_cache
LLDP: https://thl-cmk.hopto.org/gitlab/checkmk/vendor-independent/inventory/inv_lldp_cache

Version: 0.0.2-20231012 | Written by: thl-cmk, for more information see: https://thl-cmk.hopto.org

options:
  -h, --help            show this help message and exit
thl-cmk's avatar
thl-cmk committed
  -s SEED_DEVICES [SEED_DEVICES ...], --seed-devices SEED_DEVICES [SEED_DEVICES ...]
                        List of devices to start the topology discovery from. I.e. Core01 Core02
thl-cmk's avatar
thl-cmk committed
  -v, --version         Print version of this script and exit
thl-cmk's avatar
thl-cmk committed
  -p PATH_IN_INVENTORY [PATH_IN_INVENTORY ...], --path-in-inventory PATH_IN_INVENTORY [PATH_IN_INVENTORY ...]
thl-cmk's avatar
thl-cmk committed
                        Checkmk inventory path to the topology data. I.e. "networking,cdp_cache"
thl-cmk's avatar
thl-cmk committed
  -c INVENTORY_COLUMNS, --inventory-columns INVENTORY_COLUMNS
thl-cmk's avatar
thl-cmk committed
                        Columns used from the inventory data. I.e. "device_id,local_port,device_port"
                        NOTE: the columns must be in the order: neighbour, local_port, neighbour_port
thl-cmk's avatar
thl-cmk committed
  -d DATA_SOURCE, --data-source DATA_SOURCE
thl-cmk's avatar
thl-cmk committed
                        The source from which the topology data originates. I.e. inv_CDP for CDP data from the inventory. NOTE: right now this only an unused label.
thl-cmk's avatar
thl-cmk committed
  -t TIME_FORMAT, --time-format TIME_FORMAT
thl-cmk's avatar
thl-cmk committed
                        Format string to render the time. (default: %Y-%m-%dT%H:%M:%S.%m)
thl-cmk's avatar
thl-cmk committed
  -o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY
thl-cmk's avatar
thl-cmk committed
                        Directory name where to save the topology data. I.e.: my_topology. Default is the actual date/time in "--time-format" format.
                        NOTE: the directory is a sub directory under "~/var/topology_data/"
thl-cmk's avatar
thl-cmk committed
  -m, --make-default    Set the created topology data as default
thl-cmk's avatar
thl-cmk committed
  -k, --keep-domain     Do not remove the domain name from the neighbor name
  -u, --uppercase       Change neighbour names to all upper case
  -l, --lowercase       Change neighbour names to all lower case
thl-cmk's avatar
thl-cmk committed

Usage:
for CDP (the default):
thl-cmk's avatar
thl-cmk committed
~/local/bin/network-topology/create_topology_data.py -s Core01 Core02 -m
thl-cmk's avatar
thl-cmk committed
or
thl-cmk's avatar
thl-cmk committed
~/local/bin/network-topology/create_topology_data.py -s Core01 Core02 -m -p "networking,cdp_cache" -c "device_id,local_port,device_port" -d inv_CDP
thl-cmk's avatar
thl-cmk committed

for LLDP:
thl-cmk's avatar
thl-cmk committed
~/local/bin/network-topology/create_topology_data.py -s Core01 Core02 -m -p "networking,lldp_cache" -c "system_name,local_port_num,port_id" -d inv_LLDP
thl-cmk's avatar
thl-cmk committed
```

thl-cmk's avatar
thl-cmk committed
---
### Limitations

- neighbour names in CD/LLDP data have to match the host names in Checkmk
- local/neighbour interface names have to match the service names in Checkmk

thl-cmk's avatar
thl-cmk committed
If neighbour names in CD/LLDP data and Checkmk host names don't match, you can configure a mapping in the `create_topology_data.py` file. I.e.:
thl-cmk's avatar
thl-cmk committed

```
thl-cmk's avatar
thl-cmk committed
# map inventory neighbour name to CMK host name
thl-cmk's avatar
thl-cmk committed
HOST_MAP = {
thl-cmk's avatar
thl-cmk committed
    'neighbour': 'cmk_host',,
thl-cmk's avatar
thl-cmk committed
    'nexus01': 'NX01',
    'nexus02': 'NX02',
    'nexus03': 'NX03',
}
```
thl-cmk's avatar
thl-cmk committed
**NOTE**: the script will automatically remove the domain name form the neighbour names. See Usage option `-k` / `--keep-domain`
thl-cmk's avatar
thl-cmk committed

At the same place you can exclude invalid hosts from the topology data
```
thl-cmk's avatar
thl-cmk committed
# drop neighbours with invalid names
thl-cmk's avatar
thl-cmk committed
DROP_HOSTS = [
    'not advertised',
]
```

thl-cmk's avatar
thl-cmk committed
---
### Sample Output

Sample output

thl-cmk's avatar
thl-cmk committed
```
OMD[build]:~$ ~/local/bin/topology_data/create_topology_data.py -s C9540-7-1 -m
Start time: 2023-10-12T16:31:32.10
Device: lr-cos-ap-010: not found in auto checks path!
Device: lr-cos-ap-010: interface (Gi0) not found in services
Devices added: 56, source inv_CDP
time taken: 0.532150752/s
End time: 2023-10-12T16:31:33.10
OMD[build]:~$ 
```
thl-cmk's avatar
thl-cmk committed

thl-cmk's avatar
thl-cmk committed
Sample network topology
thl-cmk's avatar
thl-cmk committed

![sample output details](/img/sample-details.png?raw=true "sample output details")