Python script, SolarWinds job of Cisco “show modules” to CSV stdout

This script takes the job output from a SolarWinds report with “show modules” run against Cisco 4500 series switches and turns it into a CSV file with:

switch name, module number, port count, card type, modele, serial number

Output is sent to stdout. Capture and redirect as needed.

Any invalid characters, including ‘,’s, in the original output are replaced with a ‘~’ so as not to throw off the CSV output.

The input file is a single SolarWinds job report containing the response that should look something like this:

SolarWinds Network Configuration Manager
Scheduled Job Notification

___________________________________________________________________________

1/14/2020 4:23:53 PM : Started show modules

Execute Command Script on Devices
33 devices selected

Devices: 33
Errors: 0
___________________________________________________________________________

TEST_SWITCH_01 (192.168.100.1):

show mod
Chassis Type : WS-C4506-E
Power consumed by backplane : 0 Watts
Mod Ports Card Type Model Serial No.
---+-----+--------------------------------------+------------------+-----------
1 6 Sup 7L-E 10GE (SFP+), 1000BaseX (SFP) WS-X45-SUP7L-E CATxxxxxxWx
2 48 10/100/1000BaseT UPOE E Series WS-X4748-UPOE+E CAT2xxxxxxx
3 48 10/100/1000BaseT UPOE E Series WS-X4748-UPOE+E CATxxx9xxxx
4 48 100/1000/2500/5000/10GBaseT UPOE E Ser WS-X4748-12X48U+E CATxxxxxxxA
5 48 100/1000/2500/5000/10GBaseT UPOE E Ser WS-X4748-12X48U+E CATxx5xxxxx
6 48 100/1000/2500/5000/10GBaseT UPOE E Ser WS-X4748-12X48U+E CATx1xxxxxx
M MAC addresses Hw Fw Sw Status
--+--------------------------------+---+------------+----------------+---------
1 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 3.0 15.0(1r)SG10 03.08.06.E Ok
2 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 Ok
3 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 Ok
4 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 0.0 Ok
5 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 0.0 Ok
6 xxxx.xxxx.xxxx to xxxx.xxxx.xxxx 1.1 0.0 Ok
Mod LinecardMode
----+---------------------------------------------------------------------
4 1
5 1
6 1

___________________________________________________________________________

TEST_SWITCH_02 (192.168.100.2):

[...]

___________________________________________________________________________
1/14/2020 4:24:28 PM : Completed show modules
Execution time : 35 seconds
___________________________________________________________________________

Python script, converts Cisco CDP output to csv output

Download python script here: cdp2csv_stdout

# This script takes the output of Cisco's "show cdp neighbors" and
# converts it to a csv formatted output.
#
# Usage:
#
# This script assumes the devices name is located in the first part of
# the filename. i.e. [device_name].[fqdn].[extension]
#
# There are two parts to this script;
# 1) Load the cdp_nei file and parse through it.
# Sometimes data is split in two lines, sometimes it's all on one.
# So we loop through the file, find what we think is valuable, and
# put all data for one neighbor on a single line.
# 2) Loop through the lines of data, pull out the individual parts of
# data elements, print in csv format.

$cdp2csv_stdout.py -h
usage: cdp2csv_stdout.py [-h] [-c] [-n LOCAL_DEV_NAME] [-dv DEBUG_LEVEL] filename

This script converts the results of 'show cdp neighbor' and turns it into csv
output. CSV data is sent to stdout, so redirect or pipe as needed.

positional arguments:
filename The name of the file which contains the output of 'show
cdp neighbor'

optional arguments:
-h, --help show this help message and exit
-c Seperate data elements by a comma (',') rather than a
tab. Tab is default.
-n LOCAL_DEV_NAME Set the local hostname. If this flag is NOT set we assume
the first part of the filename is the local node name.
-dv DEBUG_LEVEL Turn on debug verbosity level. '0' is off (default). This
will invalidate the CSV output structure, but is useful
for troubleshooting.