1
2
3
4
5
6
7
8
9
10
11
12
13
14 import time
15 import socket
16
17 from ZenEventClasses import *
18 from Exceptions import *
19
20
22 """Build an event object from a dictionary.
23 """
24 evclass = evdict.get("eventClass", Unknown)
25 if evclass == Heartbeat:
26 for field in ("device", "component", "timeout"):
27 if field not in evdict:
28 raise ZenEventError("Required event field %s not found" % field)
29 evt = EventHeartbeat(evdict['device'], evdict['component'],
30 evdict['timeout'])
31 else:
32 evt = Event(**evdict)
33 return evt
34
35
36
38 """
39 Event that lives independant of zope context. As interface that allows
40 it to be persisted to/from the event backend.
41 dedupid,
42 evid,
43 device,
44 ipAddress,
45 component,
46 eventClass,
47 eventGroup,
48 eventKey,
49 facility,
50 severity,
51 priority,
52 summary,
53 stateChange,
54 firstTime,
55 lastTime,
56 count,
57 prodState,
58 manager,
59 agent,
60 DeviceClass,
61 Location,
62 Systems,
63 DeviceGroups,
64 """
65
67
68
69
70 if not rcvtime:
71 self.firstTime = self.lastTime = time.time()
72 else:
73 self.firstTime = self.lastTime = rcvtime
74 self._clearClasses = []
75 self._action = "status"
76 self._fields = kwargs.get('fields',[])
77 self.eventKey = ''
78 if kwargs: self.updateFromDict(kwargs)
79
80
82 """return an array of event fields tuples (field,value)"""
83 return [(x, getattr(self, x)) for x in self._fields]
84
85
87 """return an list of event data"""
88 return [ getattr(self, x) for x in self._fields]
89
90
92 """
93 Update event from list of fields and list of data values.
94 They must have the same length. To be used when pulling data
95 from the backend db.
96 """
97 self._fields = fields
98 for i in range(len(fields)):
99 setattr(self, fields[i], data[i])
100
101
103 """Update event from dict. Keys that don't match attributes are
104 put into the detail list of the event.
105 """
106 for key, value in data.items():
107 setattr(self, key, value)
108
109
111 """Return a list of classes that this event clears.
112 if we have specified clearClasses always return them
113 if we ave a 0 severity return ourself as well.
114 """
115 clearcls = self._clearClasses
116 evclass = getattr(self, "eventClass", None)
117 sev = getattr(self, 'severity', None)
118 if evclass and sev == 0: clearcls.append(self.eventClass)
119 return clearcls
120
121
123 """return a list of data elements that map to the fields parameter.
124 """
125 return map(lambda x: getattr(self, x), fields)
126
127
129 """Return list of dedupid fields.
130 """
131 return default
132
133
142