]>
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
))
27 # Create the output file name
28 def createOutputFile(procName
):
29 fileName
= procName
+ "_support_bundle.log"
30 oldFile
= LOG_DIR
+ fileName
31 cpFileCmd
= "cp " + oldFile
+ " " + oldFile
+ ".prev"
32 rmFileCmd
= "rm -rf " + oldFile
33 print "Making backup of " + oldFile
35 print "Removing " + oldFile
39 # Open the output file for this process
40 def openOutputFile(fileName
):
41 crt_file_cmd
= LOG_DIR
+ fileName
44 outputFile
= open(crt_file_cmd
, "w")
49 # Close the output file for this process
50 def closeOutputFile(file):
57 # Execute the command over vtysh and store in the
59 def executeCommand(cmd
, outputFile
):
60 cmd_exec_str
= "vtysh -c \"" + cmd
+ "\" "
62 cmd_output
= subprocess
.check_output(cmd_exec_str
, shell
=True)
64 dateTime
= datetime
.datetime
.now()
65 outputFile
.write(">>[" + str(dateTime
) + "]" + cmd
+ "\n")
66 outputFile
.write(cmd_output
)
67 outputFile
.write("########################################################\n")
68 outputFile
.write('\n')
70 print "Writing to ouptut file Failed"
71 except subprocess
.CalledProcessError
as e
:
72 dateTime
= datetime
.datetime
.now()
73 outputFile
.write(">>[" + str(dateTime
) + "]" + cmd
+ "\n")
74 outputFile
.write(e
.output
)
75 outputFile
.write("########################################################\n")
76 outputFile
.write('\n')
77 print "Error:" + e
.output
80 # Process the support bundle configuration file
81 # and call appropriate functions
82 def processConfFile(lines
):
86 cmd_line
= line
.split(':')
87 if cmd_line
[0] == "PROC_NAME":
88 outputFileName
= createOutputFile(cmd_line
[1])
90 print outputFileName
, "created for", cmd_line
[1]
91 elif cmd_line
[0] == "CMD_LIST_START":
92 outputFile
= openOutputFile(outputFileName
)
94 print outputFileName
, "opened"
96 print outputFileName
, "open failed"
98 elif cmd_line
[0] == "CMD_LIST_END":
99 if closeOutputFile(outputFile
):
100 print outputFileName
, "closed"
102 print outputFileName
, "close failed"
104 print "Execute:" , cmd_line
[0]
105 executeCommand(cmd_line
[0], outputFile
)
108 lines
= openConfFile(inputFile
)
110 print "File support_bundle_commands.conf not present in /etc/frr/ directory"
112 processConfFile(lines
)