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
___________________________________________________________________________