]>
git.proxmox.com Git - mirror_frr.git/blob - tools/generate_support_bundle.py
3 ########################################################
4 ### Python Script to generate the FRR support bundle ###
5 ########################################################
11 LOG_DIR
= "/var/log/frr/"
15 inputFile
= ETC_DIR
+ "support_bundle_commands.conf"
17 # Create the output file name
18 def createOutputFile(procName
):
19 fileName
= procName
+ "_support_bundle.log"
20 oldFile
= LOG_DIR
+ fileName
21 cpFileCmd
= "cp " + oldFile
+ " " + oldFile
+ ".prev"
22 rmFileCmd
= "rm -rf " + oldFile
23 print("Making backup of " + oldFile
)
25 print("Removing " + oldFile
)
30 # Open the output file for this process
31 def openOutputFile(fileName
):
32 crt_file_cmd
= LOG_DIR
+ fileName
35 outputFile
= open(crt_file_cmd
, "w")
41 # Close the output file for this process
42 def closeOutputFile(f
):
50 # Execute the command over vtysh and store in the
52 def executeCommand(cmd
, outputFile
):
53 cmd_exec_str
= 'vtysh -c "' + cmd
+ '" '
55 cmd_output
= subprocess
.check_output(cmd_exec_str
, shell
=True)
57 dateTime
= datetime
.datetime
.now()
58 outputFile
.write(">>[" + str(dateTime
) + "]" + cmd
+ "\n")
59 outputFile
.write(str(cmd_output
))
61 "########################################################\n"
63 outputFile
.write("\n")
64 except Exception as e
:
65 print("Writing to output file Failed: ", e
)
66 except subprocess
.CalledProcessError
as e
:
67 dateTime
= datetime
.datetime
.now()
68 outputFile
.write(">>[" + str(dateTime
) + "]" + cmd
+ "\n")
69 outputFile
.write(e
.output
)
70 outputFile
.write("########################################################\n")
71 outputFile
.write("\n")
72 print("Error:" + e
.output
)
75 # Process the support bundle configuration file
76 # and call appropriate functions
77 def processConfFile():
83 with
open(inputFile
, "r") as supportBundleConfFile
:
84 for l
in supportBundleConfFile
:
85 lines
.append(l
.rstrip())
87 print("conf file {} not present".format(inputFile
))
91 if len(line
) == 0 or line
[0] == "#":
94 cmd_line
= line
.split(":")
95 if cmd_line
[0] == "PROC_NAME":
96 outputFileName
= createOutputFile(cmd_line
[1])
98 print(outputFileName
, "created for", cmd_line
[1])
99 elif cmd_line
[0] == "CMD_LIST_START":
100 outputFile
= openOutputFile(outputFileName
)
102 print(outputFileName
, "opened")
104 print(outputFileName
, "open failed")
106 elif cmd_line
[0] == "CMD_LIST_END":
107 if closeOutputFile(outputFile
):
108 print(outputFileName
, "closed")
110 print(outputFileName
, "close failed")
112 print("Execute:", cmd_line
[0])
113 executeCommand(cmd_line
[0], outputFile
)