]>
git.proxmox.com Git - mirror_frr.git/blob - tools/generate_support_bundle.py
3 ########################################################
4 ### Python Script to generate the FRR support bundle ###
5 ########################################################
12 LOG_DIR
= "/var/log/frr/"
16 inputFile
= ETC_DIR
+ "support_bundle_commands.conf"
18 # Open support bundle configuration file
19 def openConfFile(i_file
):
21 with
open(i_file
) as supportBundleConfFile
:
22 lines
= filter(None, (line
.rstrip() for line
in supportBundleConfFile
))
28 # Create the output file name
29 def createOutputFile(procName
):
30 fileName
= procName
+ "_support_bundle.log"
31 oldFile
= LOG_DIR
+ fileName
32 cpFileCmd
= "cp " + oldFile
+ " " + oldFile
+ ".prev"
33 rmFileCmd
= "rm -rf " + oldFile
34 print("Making backup of " + oldFile
)
36 print("Removing " + oldFile
)
41 # Open the output file for this process
42 def openOutputFile(fileName
):
43 crt_file_cmd
= LOG_DIR
+ fileName
46 outputFile
= open(crt_file_cmd
, "w")
52 # Close the output file for this process
53 def closeOutputFile(file):
61 # Execute the command over vtysh and store in the
63 def executeCommand(cmd
, outputFile
):
64 cmd_exec_str
= 'vtysh -c "' + cmd
+ '" '
66 cmd_output
= subprocess
.check_output(cmd_exec_str
, shell
=True)
68 dateTime
= datetime
.datetime
.now()
69 outputFile
.write(">>[" + str(dateTime
) + "]" + cmd
+ "\n")
70 outputFile
.write(cmd_output
)
72 "########################################################\n"
74 outputFile
.write("\n")
76 print("Writing to ouptut file Failed")
77 except subprocess
.CalledProcessError
as e
:
78 dateTime
= datetime
.datetime
.now()
79 outputFile
.write(">>[" + str(dateTime
) + "]" + cmd
+ "\n")
80 outputFile
.write(e
.output
)
81 outputFile
.write("########################################################\n")
82 outputFile
.write("\n")
83 print("Error:" + e
.output
)
86 # Process the support bundle configuration file
87 # and call appropriate functions
88 def processConfFile(lines
):
92 cmd_line
= line
.split(":")
93 if cmd_line
[0] == "PROC_NAME":
94 outputFileName
= createOutputFile(cmd_line
[1])
96 print(outputFileName
, "created for", cmd_line
[1])
97 elif cmd_line
[0] == "CMD_LIST_START":
98 outputFile
= openOutputFile(outputFileName
)
100 print(outputFileName
, "opened")
102 print(outputFileName
, "open failed")
104 elif cmd_line
[0] == "CMD_LIST_END":
105 if closeOutputFile(outputFile
):
106 print(outputFileName
, "closed")
108 print(outputFileName
, "close failed")
110 print("Execute:", cmd_line
[0])
111 executeCommand(cmd_line
[0], outputFile
)
115 lines
= openConfFile(inputFile
)
117 print("File support_bundle_commands.conf not present in /etc/frr/ directory")
119 processConfFile(lines
)