]>
git.proxmox.com Git - mirror_frr.git/blob - tools/generate_support_bundle.py
1 ########################################################
2 ### Python Script to generate the FRR support bundle ###
3 ########################################################
10 LOG_DIR
="/var/log/frr/"
14 inputFile
= ETC_DIR
+ "support_bundle_commands.conf"
16 # Open support bundle configuration file
17 def openConfFile(i_file
):
19 with
open(i_file
) as supportBundleConfFile
:
20 lines
= filter(None, (line
.rstrip() for line
in supportBundleConfFile
))
25 # Create the output file name
26 def createOutputFile(procName
):
27 fileName
= procName
+ "_support_bundle.log"
28 oldFile
= LOG_DIR
+ fileName
29 cpFileCmd
= "cp " + oldFile
+ " " + oldFile
+ ".prev"
30 rmFileCmd
= "rm -rf " + oldFile
31 print "Making backup of " + oldFile
33 print "Removing " + oldFile
37 # Open the output file for this process
38 def openOutputFile(fileName
):
39 crt_file_cmd
= LOG_DIR
+ fileName
42 outputFile
= open(crt_file_cmd
, "w")
47 # Close the output file for this process
48 def closeOutputFile(file):
55 # Execute the command over vtysh and store in the
57 def executeCommand(cmd
, outputFile
):
58 cmd_exec_str
= "vtysh -c \"" + cmd
+ "\" "
60 cmd_output
= subprocess
.check_output(cmd_exec_str
, shell
=True)
62 dateTime
= datetime
.datetime
.now()
63 outputFile
.write(">>[" + str(dateTime
) + "]" + cmd
+ "\n")
64 outputFile
.write(cmd_output
)
65 outputFile
.write("########################################################\n")
66 outputFile
.write('\n')
68 print "Writing to ouptut file Failed"
69 except subprocess
.CalledProcessError
as e
:
70 dateTime
= datetime
.datetime
.now()
71 outputFile
.write(">>[" + str(dateTime
) + "]" + cmd
+ "\n")
72 outputFile
.write(e
.output
)
73 outputFile
.write("########################################################\n")
74 outputFile
.write('\n')
75 print "Error:" + e
.output
78 # Process the support bundle configuration file
79 # and call appropriate functions
80 def processConfFile(lines
):
84 cmd_line
= line
.split(':')
85 if cmd_line
[0] == "PROC_NAME":
86 outputFileName
= createOutputFile(cmd_line
[1])
88 print outputFileName
, "created for", cmd_line
[1]
89 elif cmd_line
[0] == "CMD_LIST_START":
90 outputFile
= openOutputFile(outputFileName
)
92 print outputFileName
, "opened"
94 print outputFileName
, "open failed"
96 elif cmd_line
[0] == "CMD_LIST_END":
97 if closeOutputFile(outputFile
):
98 print outputFileName
, "closed"
100 print outputFileName
, "close failed"
102 print "Execute:" , cmd_line
[0]
103 executeCommand(cmd_line
[0], outputFile
)
106 lines
= openConfFile(inputFile
)
108 print "File support_bundle_commands.conf not present in /etc/frr/ directory"
110 processConfFile(lines
)