]> git.proxmox.com Git - mirror_frr.git/blob - tools/generate_support_bundle.py
Merge pull request #10925 from qlyoung/fix-grpc-wants-installed-frr
[mirror_frr.git] / tools / generate_support_bundle.py
1 #!/usr/bin/env python3
2 #
3 # Copyright (c) 2021, LabN Consulting, L.L.C.
4 #
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.
9 #
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.
14 #
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
18 #
19
20 ########################################################
21 ### Python Script to generate the FRR support bundle ###
22 ########################################################
23 import argparse
24 import logging
25 import os
26 import subprocess
27 import tempfile
28
29
30 def open_with_backup(path):
31 if os.path.exists(path):
32 print("Making backup of " + path)
33 subprocess.check_call("mv {0} {0}.prev".format(path), shell=True)
34 return open(path, "w")
35
36
37 def main():
38 parser = argparse.ArgumentParser()
39 parser.add_argument(
40 "-c",
41 "--config",
42 default="/etc/frr/support_bundle_commands.conf",
43 help="input config",
44 )
45 parser.add_argument(
46 "-l", "--log-dir", default="/var/log/frr", help="directory for logfiles"
47 )
48 args = parser.parse_args()
49
50 collecting = False # file format has sentinels (seem superfluous)
51 proc_cmds = {}
52 proc = None
53 temp = None
54
55 # Collect all the commands for each daemon
56 try:
57 for line in open(args.config):
58 line = line.rstrip()
59 if len(line) == 0 or line[0] == "#":
60 continue
61
62 cmd_line = line.split(":")
63 if cmd_line[0] == "PROC_NAME":
64 proc = cmd_line[1]
65 temp = tempfile.NamedTemporaryFile("w+")
66 collecting = False
67 elif cmd_line[0] == "CMD_LIST_START":
68 collecting = True
69 elif cmd_line[0] == "CMD_LIST_END":
70 collecting = False
71 temp.flush()
72 proc_cmds[proc] = open(temp.name)
73 temp.close()
74 elif collecting:
75 temp.write(line + "\n")
76 else:
77 print("Ignoring unexpected input " + line.rstrip())
78 except IOError as error:
79 logging.fatal("Cannot read config file: %s: %s", args.config, str(error))
80 return
81
82 # Spawn a vtysh to fetch each set of commands
83 procs = []
84 for proc in proc_cmds:
85 ofn = os.path.join(args.log_dir, proc + "_support_bundle.log")
86 p = subprocess.Popen(
87 ["/usr/bin/env", "vtysh", "-t"],
88 stdin=proc_cmds[proc],
89 stdout=open_with_backup(ofn),
90 stderr=subprocess.STDOUT,
91 )
92 procs.append(p)
93
94 for p in procs:
95 p.wait()
96
97
98 if __name__ == "__main__":
99 main()