]> git.proxmox.com Git - mirror_frr.git/blame - tools/generate_support_bundle.py
lib: Add a nexthop_dup() that allocates and copies
[mirror_frr.git] / tools / generate_support_bundle.py
CommitLineData
e60eb780
SMS
1########################################################
2### Python Script to generate the FRR support bundle ###
3########################################################
4import os
5import subprocess
6import datetime
7
8TOOLS_DIR="tools/"
9ETC_DIR="/etc/frr/"
10LOG_DIR="/var/log/frr/"
11SUCCESS = 1
12FAIL = 0
13
14inputFile = ETC_DIR + "support_bundle_commands.conf"
15
16# Open support bundle configuration file
17def openConfFile(i_file):
18 try:
19 with open(i_file) as supportBundleConfFile:
20 lines = filter(None, (line.rstrip() for line in supportBundleConfFile))
21 return lines
22 except IOError:
23 return ([])
24
25# Create the output file name
26def 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
32 os.system(cpFileCmd)
33 print "Removing " + oldFile
34 os.system(rmFileCmd)
35 return fileName
36
37# Open the output file for this process
38def openOutputFile(fileName):
39 crt_file_cmd = LOG_DIR + fileName
40 print crt_file_cmd
41 try:
42 outputFile = open(crt_file_cmd, "w")
43 return outputFile
44 except IOError:
45 return ()
46
47# Close the output file for this process
48def closeOutputFile(file):
49 try:
50 file.close()
51 return SUCCESS
52 except IOError:
53 return FAIL
54
55# Execute the command over vtysh and store in the
56# output file
57def executeCommand(cmd, outputFile):
58 cmd_exec_str = "vtysh -c \"" + cmd + "\" "
59 try:
60 cmd_output = subprocess.check_output(cmd_exec_str, shell=True)
61 try:
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')
67 except:
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
76
77
78# Process the support bundle configuration file
79# and call appropriate functions
80def processConfFile(lines):
81 for line in lines:
82 if line[0][0] == '#':
83 continue
84 cmd_line = line.split(':')
85 if cmd_line[0] == "PROC_NAME":
86 outputFileName = createOutputFile(cmd_line[1])
87 if outputFileName:
88 print outputFileName, "created for", cmd_line[1]
89 elif cmd_line[0] == "CMD_LIST_START":
90 outputFile = openOutputFile(outputFileName)
91 if outputFile:
92 print outputFileName, "opened"
93 else:
94 print outputFileName, "open failed"
95 return FAIL
96 elif cmd_line[0] == "CMD_LIST_END":
97 if closeOutputFile(outputFile):
98 print outputFileName, "closed"
99 else:
100 print outputFileName, "close failed"
101 else:
102 print "Execute:" , cmd_line[0]
103 executeCommand(cmd_line[0], outputFile)
104
105# Main Function
106lines = openConfFile(inputFile)
107if not lines:
108 print "File support_bundle_commands.conf not present in /etc/frr/ directory"
109else:
110 processConfFile(lines)