-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfstorage.py
274 lines (216 loc) · 8.74 KB
/
fstorage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
__author__ = 'SourabhKatti'
import array
from classes import Logfile
import numpy as np
from storage import storage
class featurestorage:
index_mappings = {}
exec_index_mappings = {}
logfile_features = {}
execution_features = {}
logitem_features = {}
lf_index = 0
exec_index = 0
li_index = 0
merged = []
logfiles = {}
filenames = {}
def __init__(self):
self.index_mappings = {}
self.exec_index_mappings = {}
self.logfile_features = {}
self.execution_features = {}
self.logitem_features = {}
self.lf_index = 0
self.exec_index = 0
self.li_index = 0
self.merged = []
self.logfiles = {}
self.filenames = {}
self.dbwriter = storage.db_store()
## Append each line with its execution features and its logfile features
def getMergedtable(self):
self.merged.clear()
print("\nGetting merged table..")
for index in range(0, self.logitem_features.__len__()):
lf_index, exec_index, li_index = self.index_mappings[index]
if lf_index > self.logfile_features.__len__():
break
if exec_index > self.execution_features.__len__():
break
if li_index > self.logitem_features.__len__():
break
lff = self.logfile_features.get(lf_index - 1).copy()
execf = self.execution_features.get(exec_index - 1).copy()
lif = self.logitem_features.get(index)
try:
execf.extend(lif)
except:
execf = np.append(execf, lif)
try:
lff.extend(execf)
except:
lff = np.append(lff, execf)
self.merged.append(np.asarray(lff, dtype=np.uint8).ravel())
return self.merged
def addlogfiletorepository(self, logfile, index):
self.logfiles[index] = logfile
def getlogfilebyindex(self, index):
lf_index, exec_index, li_index = self.index_mappings.get(index)
logfile = self.logfiles.get(lf_index)
filename = self.filenames.get(lf_index)
return logfile, filename
def getlifeatures(self):
featurestoreturn = []
for row in self.logitem_features:
rowtoreturn = list(row)
def getexecutionbyindex(self, index):
lf_index, exec_index, li_index = self.index_mappings[index]
logfile = self.logfiles.get(lf_index)
i = 0
executionret = logfile.getExecutions()[exec_index]
return executionret
def getlogitembyindex(self, index):
lf_index, exec_index, li_index = self.index_mappings[index]
logfile = self.logfiles.get(lf_index)
i = 0
executionf = logfile.getExecutions()[exec_index]
logitemf = executionf.logitems[li_index]
return logitemf
print("No execution for that index")
def commit(self, logfile):
li_old = self.li_index
lf_old = self.lf_index + 1
exec_old = self.exec_index
for execution in logfile.getExecutions():
exec_old += 1
logitem_index = 0
try:
for logitem in execution.getlogitems():
value = [lf_old, exec_old, logitem_index]
self.index_mappings[li_old] = value
li_old += 1
logitem_index += 1
self.addlogfiletorepository(logfile, lf_old)
except:
print("Indexing gone past logitem feature list, logfile may not match")
return self.index_mappings
def commit_db(self, logfile):
lf_db_index = self.dbwriter.write_logfile(logfile)
for execution in logfile.getExecutions():
exec_db_index = self.dbwriter.write_execution(execution, lf_db_index)
li_db_indices = self.dbwriter.write_logitems(execution.getlogitems(), exec_db_index)
def getdictionarywordsbykeyword(self, keywords):
self.dbwriter.getdictionarykeywordsbyid(keywords)
def add_logitems(self, features):
self.li_index = self.logitem_features.__len__()
current_index = self.li_index
li_len = features.__len__()
for row in features:
self.logitem_features[current_index] = row
current_index += 1
def add_executions(self, features1):
self.exec_index = self.execution_features.__len__()
current_index = self.li_index
exec_length = 0
for feature in features1:
self.execution_features[self.exec_index + exec_length] = feature
exec_length += 1
def add_logfile(self, features, filename):
self.lf_index = self.logfile_features.__len__()
self.filenames[self.lf_index] = filename
self.logfile_features[self.lf_index] = features
def getlogfilebytableindex(self, index):
lf = self.logfiles.get(index)
return lf
def getTables(self, mergedtable):
train_features = []
train_class = []
test_features = []
fcount = 0
for row in mergedtable:
lenf = row.__len__() - 1
f = row[:lenf - 1]
train_features.append(f)
train_class.append(row[lenf])
if fcount < 3:
test_features.append(row[:lenf - 1])
fcount += 1
return train_features, train_class, test_features
def getpreds(self, values, level):
if level == 'logitem':
li = []
index = 0
maxz = min(values['rbmpreds'])
for pred in values['rbmpreds']:
if pred < 0.6 * maxz:
lf, execi, lii = self.index_mappings[index]
logfile = self.logfiles[lf]
try:
execution = logfile.getExecutions()[execi - 1]
except:
execution = logfile.getExecutions()
try:
logitem = execution.getlogitems()[lii - 1]
except:
logitem = execution.getlogitems()
li.append({'pred': pred, 'logitem': logitem})
index += 1
linum = 1
lix = sorted(li, key=lambda k: k['pred'])
print("\nPossible logitems: ")
linum = 1
body = ""
for logitemscore in lix:
logitem = logitemscore['logitem']
print("%d. %s on line %d" % (linum, logitem.methodname, logitem.linenumber))
body += "%d. %s at line number %d with a score of %f.\n" % (
linum, logitem.methodname, logitem.linenumber, logitemscore['pred'])
linum += 1
title = "Predictions for logfile %d" % linum
return title, body
elif level == 'execution':
execs = []
index = 0
print('\nExecution category')
i = 0
for value in values:
if int(value) == 1:
print("%s. Most probably an issue with your application server" % str(i + 1))
elif int(value) == 2:
print("%s. Most probably an issue with your database" % str(i + 1))
elif int(value) == 3:
print("%s. Most probably an issue with your LDAP server" % str(i + 1))
else:
print("Invalid prediction", value)
i += 1
elif level == 'logfile':
lfs = []
index = 0
print("\nLogfile type")
try:
for value in values:
try:
logfile = self.logfiles[index + 1]
lfs.append(logfile)
except:
break
if int(value) <= 1:
print("%s is most probably an SSC log" % self.filenames[index])
elif int(value) == 2:
print("%s is most probably an SCA log" % self.filenames[index])
elif int(value) == 3:
print("%s is most probably a debug SCA log" % self.filenames[index])
else:
print("Invalid predictions", value)
index += 1
except:
if int(values) <= 1:
print("%s is most probably an SSC log" % self.filenames[index])
elif int(values) == 2:
print("%s is most probably an SCA log" % self.filenames[index])
elif int(values) == 3:
print("%s is most probably a debug SCA log" % self.filenames[index])
else:
print("Invalid predictions", value)
index += 1