]>
git.proxmox.com Git - mirror_frr.git/blob - tools/generate_support_bundle.py
3 # Copyright (c) 2021, LabN Consulting, L.L.C.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; see the file COPYING; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ########################################################
21 ### Python Script to generate the FRR support bundle ###
22 ########################################################
29 def open_with_backup(path
):
30 if os
.path
.exists(path
):
31 print("Making backup of " + path
)
32 subprocess
.check_call("mv {0} {0}.prev".format(path
))
33 return open(path
, "w")
36 parser
= argparse
.ArgumentParser()
37 parser
.add_argument("-c", "--config", default
="/etc/frr/support_bundle_commands.conf", help="input config")
38 parser
.add_argument("-l", "--log-dir", default
="/var/log/frr", help="directory for logfiles")
39 args
= parser
.parse_args()
41 collecting
= False # file format has sentinels (seem superfluous)
46 # Collect all the commands for each daemon
48 for line
in open(args
.config
):
50 if len(line
) == 0 or line
[0] == "#":
53 cmd_line
= line
.split(":")
54 if cmd_line
[0] == "PROC_NAME":
56 temp
= tempfile
.NamedTemporaryFile("w+")
58 elif cmd_line
[0] == "CMD_LIST_START":
60 elif cmd_line
[0] == "CMD_LIST_END":
63 proc_cmds
[proc
] = open(temp
.name
)
66 temp
.write(line
+ "\n")
68 print("Ignoring unexpected input " + line
.rstrip())
69 except IOError as error
:
70 logging
.fatal("Cannot read config file: %s: %s", args
.config
, str(error
))
73 # Spawn a vtysh to fetch each set of commands
75 for proc
in proc_cmds
:
76 ofn
= os
.path
.join(args
.log_dir
, proc
+ "_support_bundle.log")
78 ["/usr/bin/env", "vtysh", "-t"],
79 stdin
=proc_cmds
[proc
],
80 stdout
=open_with_backup(ofn
),
81 stderr
=subprocess
.STDOUT
,
88 if __name__
== "__main__":