]> git.proxmox.com Git - mirror_frr.git/blame - tools/generate_support_bundle.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tools / generate_support_bundle.py
CommitLineData
70b99f2f 1#!/usr/bin/env python3
acddc0ed 2# SPDX-License-Identifier: GPL-2.0-or-later
5417cc2d
CH
3#
4# Copyright (c) 2021, LabN Consulting, L.L.C.
5#
11c83aa4 6
e60eb780
SMS
7########################################################
8### Python Script to generate the FRR support bundle ###
9########################################################
5417cc2d
CH
10import argparse
11import logging
e60eb780
SMS
12import os
13import subprocess
5417cc2d
CH
14import tempfile
15
667cfdc8 16
5417cc2d
CH
17def open_with_backup(path):
18 if os.path.exists(path):
19 print("Making backup of " + path)
b321edc5 20 subprocess.check_call("mv {0} {0}.prev".format(path), shell=True)
5417cc2d
CH
21 return open(path, "w")
22
667cfdc8 23
5417cc2d
CH
24def main():
25 parser = argparse.ArgumentParser()
667cfdc8
DS
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 )
5417cc2d
CH
35 args = parser.parse_args()
36
667cfdc8 37 collecting = False # file format has sentinels (seem superfluous)
5417cc2d
CH
38 proc_cmds = {}
39 proc = None
40 temp = None
41
42 # Collect all the commands for each daemon
e60eb780 43 try:
5417cc2d
CH
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")
701a0192 63 else:
5417cc2d
CH
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
701a0192 68
5417cc2d
CH
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
667cfdc8 84
5417cc2d
CH
85if __name__ == "__main__":
86 main()