]>
git.proxmox.com Git - mirror_frr.git/blob - tools/generate_support_bundle.py
2 # SPDX-License-Identifier: GPL-2.0-or-later
4 # Copyright (c) 2021, LabN Consulting, L.L.C.
7 ########################################################
8 ### Python Script to generate the FRR support bundle ###
9 ########################################################
17 def open_with_backup(path
):
18 if os
.path
.exists(path
):
19 print("Making backup of " + path
)
20 subprocess
.check_call("mv {0} {0}.prev".format(path
), shell
=True)
21 return open(path
, "w")
25 parser
= argparse
.ArgumentParser()
29 default
="/etc/frr/support_bundle_commands.conf",
33 "-l", "--log-dir", default
="/var/log/frr", help="directory for logfiles"
35 args
= parser
.parse_args()
37 collecting
= False # file format has sentinels (seem superfluous)
42 # Collect all the commands for each daemon
44 for line
in open(args
.config
):
46 if len(line
) == 0 or line
[0] == "#":
49 cmd_line
= line
.split(":")
50 if cmd_line
[0] == "PROC_NAME":
52 temp
= tempfile
.NamedTemporaryFile("w+")
54 elif cmd_line
[0] == "CMD_LIST_START":
56 elif cmd_line
[0] == "CMD_LIST_END":
59 proc_cmds
[proc
] = open(temp
.name
)
62 temp
.write(line
+ "\n")
64 print("Ignoring unexpected input " + line
.rstrip())
65 except IOError as error
:
66 logging
.fatal("Cannot read config file: %s: %s", args
.config
, str(error
))
69 # Spawn a vtysh to fetch each set of commands
71 for proc
in proc_cmds
:
72 ofn
= os
.path
.join(args
.log_dir
, proc
+ "_support_bundle.log")
74 ["/usr/bin/env", "vtysh", "-t"],
75 stdin
=proc_cmds
[proc
],
76 stdout
=open_with_backup(ofn
),
77 stderr
=subprocess
.STDOUT
,
85 if __name__
== "__main__":