2021-02-04 17:13:01 +01:00
|
|
|
#!/usr/bin/env python3
|
2023-02-08 13:17:09 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2021-06-30 00:03:31 +02:00
|
|
|
#
|
|
|
|
# Copyright (c) 2021, LabN Consulting, L.L.C.
|
|
|
|
#
|
2019-08-13 23:53:08 +02:00
|
|
|
|
FRR: Python script to generate support bundle for FRR
This has a python script that helps in collecting various CLI show command outputs in an automated way.
This commit has two files.
1.Text Configuration file: support_bundle_commands.conf - This file has list of CLI show commands to be executed. This file will be in tools/etc/frr/ directory. On executing command "sudo install -m 644 tools/etc/frr/ support_bundle_commands.conf /etc/frr/support_bundle_commands.conf", as part of FRR installation, this file will be copied into /etc/frr directory.
2.Python script file: generate_support_bundle.py - This file has the python code that has the below functionality.
* It reads the support_bundle_commands.conf file. For each process present in the conf file, it creates a support_bundle file. For example, it creates bgp_support_bundle.log file for BGP and zebra_support_bundle.log file for Zebra. These files will be created in /var/log/frr/ directory. This is where regular FRR log files are also stored currently.
* The script reads the CLI command specified between CLI_START and CLI_END key words for each process. It will execute the commands one by one.
* For each such command, the script also appends the current time stamp at which the CLI command is executed.
* In case of successful execution of the CLI command, it will copy the CLI output into the above support bundle file.
* In case of CLI command failure, it will capture the error thrown and the error is also written into the same file.
* A small snippet of the output file is as below.
>>[2019-01-02 13:55:23.318987]show bgp summary
IPv4 Unicast Summary:
BGP router identifier 203.0.113.1, local AS number 65000 vrf-id 0
BGP table version 4
RIB entries 7, using 1176 bytes of memory
Peers 1, using 21 KiB of memory
Peer groups 1, using 64 bytes of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
203.0.113.2 4 65001 34 34 0 0 0 00:29:47 2
Total number of neighbors 1
>>[2019-01-02 13:55:23.619953]show ip bgp
BGP table version is 4, local router ID is 203.0.113.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Signed-off-by: Sri Mohana Singamsetty <msingamsetty@vmware.com>
2019-02-20 20:56:22 +01:00
|
|
|
########################################################
|
|
|
|
### Python Script to generate the FRR support bundle ###
|
|
|
|
########################################################
|
2021-06-30 00:03:31 +02:00
|
|
|
import argparse
|
|
|
|
import logging
|
FRR: Python script to generate support bundle for FRR
This has a python script that helps in collecting various CLI show command outputs in an automated way.
This commit has two files.
1.Text Configuration file: support_bundle_commands.conf - This file has list of CLI show commands to be executed. This file will be in tools/etc/frr/ directory. On executing command "sudo install -m 644 tools/etc/frr/ support_bundle_commands.conf /etc/frr/support_bundle_commands.conf", as part of FRR installation, this file will be copied into /etc/frr directory.
2.Python script file: generate_support_bundle.py - This file has the python code that has the below functionality.
* It reads the support_bundle_commands.conf file. For each process present in the conf file, it creates a support_bundle file. For example, it creates bgp_support_bundle.log file for BGP and zebra_support_bundle.log file for Zebra. These files will be created in /var/log/frr/ directory. This is where regular FRR log files are also stored currently.
* The script reads the CLI command specified between CLI_START and CLI_END key words for each process. It will execute the commands one by one.
* For each such command, the script also appends the current time stamp at which the CLI command is executed.
* In case of successful execution of the CLI command, it will copy the CLI output into the above support bundle file.
* In case of CLI command failure, it will capture the error thrown and the error is also written into the same file.
* A small snippet of the output file is as below.
>>[2019-01-02 13:55:23.318987]show bgp summary
IPv4 Unicast Summary:
BGP router identifier 203.0.113.1, local AS number 65000 vrf-id 0
BGP table version 4
RIB entries 7, using 1176 bytes of memory
Peers 1, using 21 KiB of memory
Peer groups 1, using 64 bytes of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
203.0.113.2 4 65001 34 34 0 0 0 00:29:47 2
Total number of neighbors 1
>>[2019-01-02 13:55:23.619953]show ip bgp
BGP table version is 4, local router ID is 203.0.113.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Signed-off-by: Sri Mohana Singamsetty <msingamsetty@vmware.com>
2019-02-20 20:56:22 +01:00
|
|
|
import os
|
|
|
|
import subprocess
|
2021-06-30 00:03:31 +02:00
|
|
|
import tempfile
|
|
|
|
|
2022-01-06 14:18:30 +01:00
|
|
|
|
2021-06-30 00:03:31 +02:00
|
|
|
def open_with_backup(path):
|
|
|
|
if os.path.exists(path):
|
|
|
|
print("Making backup of " + path)
|
tools: fix backing up previous logs in generate_support_bundle.py
subprocess.check_call needs to be called with shell=True, else it will
interpret the string as a single path to execute instead of a command
with arguments:
Fixes the following error:
$ /usr/lib/frr/generate_support_bundle.py
Making backup of /var/log/frr/bgp_support_bundle.log
Traceback (most recent call last):
File "/usr/lib/frr/generate_support_bundle.py", line 89, in <module>
main()
File "/usr/lib/frr/generate_support_bundle.py", line 80, in main
stdout=open_with_backup(ofn),
File "/usr/lib/frr/generate_support_bundle.py", line 32, in open_with_backup
subprocess.check_call("mv {0} {0}.prev".format(path))
File "/usr/lib/python3.8/subprocess.py", line 359, in check_call
retcode = call(*popenargs, **kwargs)
File "/usr/lib/python3.8/subprocess.py", line 340, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'mv /var/log/frr/bgp_support_bundle.log /var/log/frr/bgp_support_bundle.log.prev'
Fixes: 5417cc2de ("tests: collect support bundle data in parallel, fix bugs")
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
2021-12-15 10:33:33 +01:00
|
|
|
subprocess.check_call("mv {0} {0}.prev".format(path), shell=True)
|
2021-06-30 00:03:31 +02:00
|
|
|
return open(path, "w")
|
|
|
|
|
2022-01-06 14:18:30 +01:00
|
|
|
|
2021-06-30 00:03:31 +02:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
2022-01-06 14:18:30 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-c",
|
|
|
|
"--config",
|
|
|
|
default="/etc/frr/support_bundle_commands.conf",
|
|
|
|
help="input config",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-l", "--log-dir", default="/var/log/frr", help="directory for logfiles"
|
|
|
|
)
|
2025-04-10 15:58:44 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"-N", "--pathspace", help="Insert prefix into config & socket paths"
|
|
|
|
)
|
2021-06-30 00:03:31 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2022-01-06 14:18:30 +01:00
|
|
|
collecting = False # file format has sentinels (seem superfluous)
|
2021-06-30 00:03:31 +02:00
|
|
|
proc_cmds = {}
|
|
|
|
proc = None
|
|
|
|
temp = None
|
|
|
|
|
|
|
|
# Collect all the commands for each daemon
|
FRR: Python script to generate support bundle for FRR
This has a python script that helps in collecting various CLI show command outputs in an automated way.
This commit has two files.
1.Text Configuration file: support_bundle_commands.conf - This file has list of CLI show commands to be executed. This file will be in tools/etc/frr/ directory. On executing command "sudo install -m 644 tools/etc/frr/ support_bundle_commands.conf /etc/frr/support_bundle_commands.conf", as part of FRR installation, this file will be copied into /etc/frr directory.
2.Python script file: generate_support_bundle.py - This file has the python code that has the below functionality.
* It reads the support_bundle_commands.conf file. For each process present in the conf file, it creates a support_bundle file. For example, it creates bgp_support_bundle.log file for BGP and zebra_support_bundle.log file for Zebra. These files will be created in /var/log/frr/ directory. This is where regular FRR log files are also stored currently.
* The script reads the CLI command specified between CLI_START and CLI_END key words for each process. It will execute the commands one by one.
* For each such command, the script also appends the current time stamp at which the CLI command is executed.
* In case of successful execution of the CLI command, it will copy the CLI output into the above support bundle file.
* In case of CLI command failure, it will capture the error thrown and the error is also written into the same file.
* A small snippet of the output file is as below.
>>[2019-01-02 13:55:23.318987]show bgp summary
IPv4 Unicast Summary:
BGP router identifier 203.0.113.1, local AS number 65000 vrf-id 0
BGP table version 4
RIB entries 7, using 1176 bytes of memory
Peers 1, using 21 KiB of memory
Peer groups 1, using 64 bytes of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
203.0.113.2 4 65001 34 34 0 0 0 00:29:47 2
Total number of neighbors 1
>>[2019-01-02 13:55:23.619953]show ip bgp
BGP table version is 4, local router ID is 203.0.113.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Signed-off-by: Sri Mohana Singamsetty <msingamsetty@vmware.com>
2019-02-20 20:56:22 +01:00
|
|
|
try:
|
2021-06-30 00:03:31 +02:00
|
|
|
for line in open(args.config):
|
|
|
|
line = line.rstrip()
|
|
|
|
if len(line) == 0 or line[0] == "#":
|
|
|
|
continue
|
|
|
|
|
|
|
|
cmd_line = line.split(":")
|
|
|
|
if cmd_line[0] == "PROC_NAME":
|
|
|
|
proc = cmd_line[1]
|
|
|
|
temp = tempfile.NamedTemporaryFile("w+")
|
|
|
|
collecting = False
|
|
|
|
elif cmd_line[0] == "CMD_LIST_START":
|
|
|
|
collecting = True
|
|
|
|
elif cmd_line[0] == "CMD_LIST_END":
|
|
|
|
collecting = False
|
|
|
|
temp.flush()
|
|
|
|
proc_cmds[proc] = open(temp.name)
|
|
|
|
temp.close()
|
|
|
|
elif collecting:
|
|
|
|
temp.write(line + "\n")
|
FRR: Python script to generate support bundle for FRR
This has a python script that helps in collecting various CLI show command outputs in an automated way.
This commit has two files.
1.Text Configuration file: support_bundle_commands.conf - This file has list of CLI show commands to be executed. This file will be in tools/etc/frr/ directory. On executing command "sudo install -m 644 tools/etc/frr/ support_bundle_commands.conf /etc/frr/support_bundle_commands.conf", as part of FRR installation, this file will be copied into /etc/frr directory.
2.Python script file: generate_support_bundle.py - This file has the python code that has the below functionality.
* It reads the support_bundle_commands.conf file. For each process present in the conf file, it creates a support_bundle file. For example, it creates bgp_support_bundle.log file for BGP and zebra_support_bundle.log file for Zebra. These files will be created in /var/log/frr/ directory. This is where regular FRR log files are also stored currently.
* The script reads the CLI command specified between CLI_START and CLI_END key words for each process. It will execute the commands one by one.
* For each such command, the script also appends the current time stamp at which the CLI command is executed.
* In case of successful execution of the CLI command, it will copy the CLI output into the above support bundle file.
* In case of CLI command failure, it will capture the error thrown and the error is also written into the same file.
* A small snippet of the output file is as below.
>>[2019-01-02 13:55:23.318987]show bgp summary
IPv4 Unicast Summary:
BGP router identifier 203.0.113.1, local AS number 65000 vrf-id 0
BGP table version 4
RIB entries 7, using 1176 bytes of memory
Peers 1, using 21 KiB of memory
Peer groups 1, using 64 bytes of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
203.0.113.2 4 65001 34 34 0 0 0 00:29:47 2
Total number of neighbors 1
>>[2019-01-02 13:55:23.619953]show ip bgp
BGP table version is 4, local router ID is 203.0.113.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Signed-off-by: Sri Mohana Singamsetty <msingamsetty@vmware.com>
2019-02-20 20:56:22 +01:00
|
|
|
else:
|
2021-06-30 00:03:31 +02:00
|
|
|
print("Ignoring unexpected input " + line.rstrip())
|
|
|
|
except IOError as error:
|
|
|
|
logging.fatal("Cannot read config file: %s: %s", args.config, str(error))
|
|
|
|
return
|
2020-10-07 23:22:26 +02:00
|
|
|
|
2021-06-30 00:03:31 +02:00
|
|
|
# Spawn a vtysh to fetch each set of commands
|
|
|
|
procs = []
|
|
|
|
for proc in proc_cmds:
|
2025-04-10 15:58:44 +02:00
|
|
|
if args.pathspace:
|
|
|
|
ofn = os.path.join(args.log_dir, args.pathspace + "_" + proc + "_support_bundle.log")
|
|
|
|
p = subprocess.Popen(
|
|
|
|
["/usr/bin/env", "vtysh", "-t", "-N", args.pathspace],
|
|
|
|
stdin=proc_cmds[proc],
|
|
|
|
stdout=open_with_backup(ofn),
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
ofn = os.path.join(args.log_dir, proc + "_support_bundle.log")
|
|
|
|
p = subprocess.Popen(
|
|
|
|
["/usr/bin/env", "vtysh", "-t"],
|
|
|
|
stdin=proc_cmds[proc],
|
|
|
|
stdout=open_with_backup(ofn),
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
)
|
2021-06-30 00:03:31 +02:00
|
|
|
procs.append(p)
|
|
|
|
|
|
|
|
for p in procs:
|
|
|
|
p.wait()
|
|
|
|
|
2022-01-06 14:18:30 +01:00
|
|
|
|
2021-06-30 00:03:31 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|