]> git.proxmox.com Git - mirror_frr.git/blob - tools/generate_support_bundle.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tools / generate_support_bundle.py
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 #
4 # Copyright (c) 2021, LabN Consulting, L.L.C.
5 #
6
7 ########################################################
8 ### Python Script to generate the FRR support bundle ###
9 ########################################################
10 import argparse
11 import logging
12 import os
13 import subprocess
14 import tempfile
15
16
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")
22
23
24 def main():
25 parser = argparse.ArgumentParser()
26 parser.add_argument(
27 "-c",
28 "--config",
29 default="/etc/frr/support_bundle_commands.conf",
30 help="input config",
31 )
32 parser.add_argument(
33 "-l", "--log-dir", default="/var/log/frr", help="directory for logfiles"
34 )
35 args = parser.parse_args()
36
37 collecting = False # file format has sentinels (seem superfluous)
38 proc_cmds = {}
39 proc = None
40 temp = None
41
42 # Collect all the commands for each daemon
43 try:
44 for line in open(args.config):
45 line = line.rstrip()
46 if len(line) == 0 or line[0] == "#":
47 continue
48
49 cmd_line = line.split(":")
50 if cmd_line[0] == "PROC_NAME":
51 proc = cmd_line[1]
52 temp = tempfile.NamedTemporaryFile("w+")
53 collecting = False
54 elif cmd_line[0] == "CMD_LIST_START":
55 collecting = True
56 elif cmd_line[0] == "CMD_LIST_END":
57 collecting = False
58 temp.flush()
59 proc_cmds[proc] = open(temp.name)
60 temp.close()
61 elif collecting:
62 temp.write(line + "\n")
63 else:
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))
67 return
68
69 # Spawn a vtysh to fetch each set of commands
70 procs = []
71 for proc in proc_cmds:
72 ofn = os.path.join(args.log_dir, proc + "_support_bundle.log")
73 p = subprocess.Popen(
74 ["/usr/bin/env", "vtysh", "-t"],
75 stdin=proc_cmds[proc],
76 stdout=open_with_backup(ofn),
77 stderr=subprocess.STDOUT,
78 )
79 procs.append(p)
80
81 for p in procs:
82 p.wait()
83
84
85 if __name__ == "__main__":
86 main()