1
2
3
4
5
6
7
8
9
10
11 __doc__="""
12
13 Event classifier classifies events based on their summary text. It
14 uses a positional index to determin the class. So for each word in the
15 summary it looks for the same word or wild card to determine which classes
16 that word in that position could be part.
17
18 positionIndex is an array of dictionaries. Each positoin of the array
19 represents the position of the word in the summary string. The value
20 is a dictionary with the words as keys and a tuple of classids as values.
21 """
22
23 import copy
24 from os import path
25 from threading import Lock
26
27 from Products.ZenUtils.Exceptions import ZentinelException
28
30
32
34
36 self.positionIndex = []
37 self.templatesource = templatesource
38 self.indexlock = Lock()
39
40
41
42
44 words = event.summary.split()
45 if hasattr(event, "process"):
46 words.insert(0,event.process)
47 if len(words) > len(self.positionIndex):
48 raise EventClassNotFound, "event summary longer than position index"
49 classids = None
50 classid = -1
51 for index, word in zip(self.positionIndex, words):
52 if '*' in index:
53 if not classids:
54 classids = copy.copy(index['*'])
55 else:
56 classids = classids.union(index['*'])
57 if word in index:
58 if not classids:
59 classids = copy.copy(index[word])
60 else:
61 classids = classids.intersection(index[word])
62 if len(classids) == 1:
63 classid = classids.pop()
64 break
65 elif len(classids) == 0:
66 raise EventClassNotFound, \
67 "no class found for words: " + " ".join(words)
68 if classid == -1:
69 raise EventClassNotUnique, \
70 "could not find unique classid possabilites are: ", classids
71
72
73 return classid
74
75
77 """build event classes based on log data"""
78 pass
79
80
82 """get a list of summary templates
83 and build our positionIndex from it"""
84 with self.indexlock:
85 templates = self.readTemplates()
86 for process, summary, classid in templates:
87 words = summary.split()
88 if process: words.insert(0, process)
89
90 self.positionIndex.extend(dict() for i in range(len(self.positionIndex), len(words)))
91 for posnIndex, word in zip(self.positionIndex, words):
92 if not word in posnIndex:
93 posnIndex[word] = set()
94 posnIndex[word].add(classid)
95
96
97
98
100 templates = []
101 if "http" in self.templatesource:
102
103 pass
104 elif path.exists(self.templatesource):
105 file = open(self.templatesource, "r")
106 for line in file.readlines():
107 if line.find("#") == 0: continue
108 process, summary, classid = line.split('||')
109 templates.append((process,summary,int(classid)))
110 file.close()
111 return templates
112