annotate importFromOpenMind/importer/check_ismi_log.py @ 39:1867bc2180c5

better check_ismi_log analyser.
author casties
date Fri, 28 Oct 2016 19:55:19 +0200
parents 9ab136f412a1
children f38ca3eb1088
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
1
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
2 # coding: utf-8
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
3
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
4 import re
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
5
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
6 # max number of lines to read (for testing)
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
7 maxLinecnt = None
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
8
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
9 # active log levels for logging
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
10 #logLevels = {'INFO', 'WARNING', 'ERROR', 'SYSMSG'}
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
11 logLevels = {'ERROR', 'SYSMSG'}
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
12
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
13 def log(level, message):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
14 if level in logLevels:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
15 print("%s: %s"%(level, message))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
16
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
17
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
18 def prettyPrintNode(node):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
19 nt = node['node-type']
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
20 att = ''
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
21 if nt == 'ENTITY':
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
22 att = " %s=%s "%('oc',node['object-class'])
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
23
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
24 elif nt == 'ATTRIBUTE':
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
25 att = " %s=%s "%('name',node['name'])
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
26
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
27 elif nt == 'RELATION':
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
28 att = " %s=%s "%('oc',node['object-class'])
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
29
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
30 s = "%s%s[%s]"%(nt, att, node)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
31 return s
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
32
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
33
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
34 nodeCsvFieldList = ['node_type', 'id', 'row_id', 'object_class', 'user', 'public', 'type',
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
35 'version', 'modification_time', 'system_status', 'content_type',
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
36 'source_id', 'source_modif', 'source_obj_class', 'target_id', 'target_modif', 'target_obj_class',
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
37 'own_value_b64']
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
38
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
39 nodeCsvFieldMap = {'node_type':'node-type', 'id':'id', 'row_id':'row-id', 'object_class':'object-class', 'user':'user',
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
40 'public':'public', 'type':'type',
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
41 'version':'version', 'modification_time':'mtime', 'system_status':'system-status', 'content_type':'content-type',
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
42 'source_id':'source-id', 'source_modif':'source-mtime', 'source_obj_class':'source-oc',
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
43 'target_id':'target-id', 'target_modif':'target-mtime', 'target_obj_class':'target-oc',
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
44 'own_value_b64':'b64-value'}
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
45
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
46
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
47 def printHeaderCsv(outFile):
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
48 s = ""
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
49 for cf in nodeCsvFieldList:
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
50 if s == "":
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
51 s += "%s"%cf
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
52 else:
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
53 s += ",%s"%cf
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
54
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
55 print(s, file=outFile)
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
56
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
57
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
58 def printNodeCsv(node, outFile):
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
59 s = ""
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
60 for cf in nodeCsvFieldList:
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
61 nf = nodeCsvFieldMap[cf]
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
62 if s == "":
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
63 s += "%s"%(node.get(nf, ''))
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
64 else:
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
65 s += ",%s"%(node.get(nf, ''))
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
66
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
67 print(s, file=outFile)
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
68
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
69
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
70 def parseStart(line):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
71 tstamp = None
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
72 tm = re.match('(\d+-\d+-\d+ \d+:\d+:\d+)', line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
73 if tm:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
74 tstamp = tm.group(1)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
75
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
76 sm = re.search('START Saving (\w+) \[ID=(\d*)', line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
77 if sm:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
78 return {'time': tstamp, 'oc': sm.group(1), 'id': sm.group(2)}
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
79
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
80 return None
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
81
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
82
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
83 def parseSave(line):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
84 match = re.search('([A-Z]+)\[([^\]]+)\]', line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
85 if match:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
86 data = {'node-type': match.group(1)}
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
87 segs = match.group(2).split(', ')
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
88 for seg in segs:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
89 k, v = seg.split('=', 1)
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
90
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
91 # fix bug with relation's object-class parameter
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
92 if k == 'object_class':
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
93 k = 'object-class'
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
94
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
95 data[k] = v.strip('"')
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
96
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
97 # normalize attriute's name to object-class
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
98 if k == 'name':
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
99 data['object-class'] = v.strip('"')
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
100
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
101 return data
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
102
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
103 return None
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
104
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
105
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
106 def equalNodes(prev, cur):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
107 log("DEBUG", "compare: %s vs %s"%(prev, cur))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
108 if prev['id'] != cur['id']:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
109 log("INFO", "node id mismatch!")
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
110 return False
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
111
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
112 if prev['node-type'] != cur['node-type']:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
113 log("INFO", "node node-type mismatch!")
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
114 return False
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
115
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
116 if prev.get('source-id', None) != cur.get('source-id', None):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
117 log("INFO", "node source_id mismatch!")
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
118 return False
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
119
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
120 if prev.get('target-id', None) != cur.get('target-id', None):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
121 log("INFO", "node target_id mismatch!")
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
122 return False
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
123
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
124 if prev['b64-value'] != cur['b64-value']:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
125 log("INFO", "node ownvalue mismatch!")
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
126 return False
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
127
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
128 return True
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
129
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
130
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
131 def getSimilarNode(prev, curList):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
132 nt = prev['node-type']
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
133 if nt == 'ATTRIBUTE':
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
134 for n in curList:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
135 if n['node-type'] == 'ATTRIBUTE' \
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
136 and prev['name'] == n['name']:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
137 # attribute with same name
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
138 log("DEBUG", "similar attributes: %s vs %s"%(prev, n))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
139 return n
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
140
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
141 elif nt == 'RELATION':
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
142 for n in curList:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
143 if n['node-type'] == 'RELATION' \
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
144 and prev['source-id'] == n['source-id'] \
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
145 and prev['target-id'] == n['target-id'] \
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
146 and prev['object-class'] == n['object-class']:
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
147 # relation with same source, target and type
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
148 log("DEBUG", "similar relations: %s vs %s"%(prev, n))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
149 return n
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
150
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
151 return None
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
152
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
153
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
154 def compareNodeLists(prev, cur, ctx, lostFile=None):
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
155 prevNodes = {}
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
156 curNodes = {}
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
157
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
158 #
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
159 # read nodes
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
160 #
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
161 for n in prev:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
162 nid = n['id']
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
163 if nid not in prevNodes:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
164 prevNodes[nid] = n
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
165 else:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
166 log("DEBUG", "duplicate save of prev node id="+nid)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
167 if isinstance(prevNodes[nid], list):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
168 prevNodes[nid].append(n)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
169 else:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
170 prevNodes[nid] = [prevNodes[nid], n]
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
171
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
172 for n in cur:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
173 nid = n['id']
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
174 if nid not in curNodes:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
175 curNodes[nid] = n
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
176 else:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
177 log("DEBUG", "duplicate save of cur node id="+nid)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
178 if isinstance(curNodes[nid], list):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
179 curNodes[nid].append(n)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
180 else:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
181 curNodes[nid] = [curNodes[nid], n]
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
182
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
183 #
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
184 # compare nodes
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
185 #
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
186 curNodeUnchecked = set(curNodes.keys())
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
187 addPrevNodes = []
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
188 addCurNodes = []
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
189
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
190 for nid in prevNodes:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
191 prevNode = prevNodes[nid]
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
192 if isinstance(prevNode, list):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
193 log("DEBUG", "multi-save prev node: %s"%prevNode)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
194 # use the last version(?)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
195 prevNode = prevNode[-1]
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
196
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
197 if nid not in curNodes:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
198 if prevNode['node-type'] == 'ATTRIBUTE' and prevNode['b64-value'] == '':
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
199 # emtpy attribute - ignore
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
200 continue
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
201
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
202 else:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
203 log("DEBUG", "node %s not in cur saves! %s"%(nid,prevNode))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
204 addPrevNodes.append(prevNode)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
205 continue
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
206
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
207 curNode = curNodes[nid]
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
208 if isinstance(curNode, list):
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
209 log("DEBUG", "multi-save cur node: %s"%curNode)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
210 # use the last version?
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
211 curNode = curNode[-1]
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
212
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
213 equalNodes(prevNode, curNode)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
214
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
215 curNodeUnchecked.remove(nid)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
216
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
217 # make list of additional current (=new) nodes
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
218 for nid in curNodeUnchecked:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
219 addCurNodes.append(curNodes[nid])
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
220 log("DEBUG", "new node %s"%curNodes[nid])
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
221
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
222 # compare missing and new nodes
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
223 for n in addPrevNodes.copy():
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
224 sn = getSimilarNode(n, addCurNodes)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
225 if sn is not None:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
226 # similar is good enough
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
227 addPrevNodes.remove(n)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
228 addCurNodes.remove(sn)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
229
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
230 if len(addPrevNodes) > 0:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
231 #print("ERROR: lost nodes: %s"%[prettyPrintNode(n) for n in addPrevNodes])
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
232 log("ERROR", "in %s"%ctx)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
233 for n in addPrevNodes:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
234 log("ERROR","lost node: %s"%prettyPrintNode(n))
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
235 if lostFile is not None:
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
236 printNodeCsv(n, lostFile)
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
237
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
238 if len(addCurNodes) > 0:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
239 #print("INFO: new nodes: %s"%[prettyPrintNode(n) for n in addCurNodes])
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
240 for n in addCurNodes:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
241 log("INFO", "new node: %s"%prettyPrintNode(n))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
242
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
243
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
244
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
245 def analyseLogfile(inFilename, outFilename=None):
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
246 outFile = None
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
247 if outFilename is not None:
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
248 outFile = open(outFilename, mode='w')
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
249 printHeaderCsv(outFile)
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
250
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
251 with open(inFilename) as f:
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
252 saving = 0
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
253 linecnt = 0
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
254 saveCtx = None
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
255 prevSaves = []
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
256 saves = []
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
257
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
258 for line in f:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
259 linecnt += 1
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
260 if '*************** START Saving' in line:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
261 saving += 1
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
262 log('DEBUG', line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
263 saveCtx = parseStart(line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
264
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
265 if saving > 1:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
266 log("ERROR", "Concurrent save (%s) in #%s of %s"%(saving, linecnt, line))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
267 # TODO: what now?
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
268
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
269 elif 'INFO transactionlog' in line:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
270 if 'save previous' in line:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
271 data = parseSave(line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
272 if data is None:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
273 log("DEBUG", "Error parsing line: %s"%line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
274 continue
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
275
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
276 prevSaves.append(data)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
277
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
278 elif 'save' in line:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
279 data = parseSave(line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
280 if data is None:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
281 log("DEBUG", "Error parsing line: %s"%line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
282 continue
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
283
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
284 saves.append(parseSave(line))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
285
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
286 elif '*************** END Saving' in line:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
287 saving -= 1
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
288 log('DEBUG', line)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
289
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
290 if saving > 0:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
291 log("ERROR", "Concurrent end save (%s) in #%s of %s"%(saving, linecnt, line))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
292
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
293 elif saving < 0:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
294 log("ERROR", "Too many END saves!")
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
295 break
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
296
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
297 log("INFO", "saving %s"%saveCtx)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
298 log("INFO", "prev saves: %s"%len(prevSaves))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
299 log("INFO", "saves: %s"%len(saves))
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
300
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
301 if len(prevSaves) > 0:
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
302 compareNodeLists(prevSaves, saves, saveCtx, outFile)
38
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
303
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
304 prevSaves = []
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
305 saves = []
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
306
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
307
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
308 if maxLinecnt is not None and linecnt >= maxLinecnt:
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
309 break
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
310
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
311 log("SYSMSG", "%s lines of logfile scanned"%linecnt)
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
312
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
313
9ab136f412a1 new first version of check_ismi_log analyser.
casties
parents:
diff changeset
314 # run analysis
39
1867bc2180c5 better check_ismi_log analyser.
casties
parents: 38
diff changeset
315 analyseLogfile('ismi-161011.log', 'ismi-161011-lost.csv')