1
2
3
4
5
6
7
8
9
10
11
12
13
14 import time
15
16 from Products.ZenEvents.ZenEventClasses import *
17 from Products.ZenEvents.Exceptions import *
18
19 from twisted.spread import pb
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: %s" % (field, evdict))
29 evt = EventHeartbeat(evdict['device'], evdict['component'],
30 evdict['timeout'])
31 else:
32 evt = Event(**evdict)
33 return evt
34
35
36
37 -class Event(pb.Copyable, pb.RemoteCopy):
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 message,
54 stateChange,
55 firstTime,
56 lastTime,
57 count,
58 prodState,
59 DevicePriority,
60 manager,
61 agent,
62 DeviceClass,
63 Location,
64 Systems,
65 DeviceGroups,
66 """
67
68 - def __init__(self, rcvtime=None, **kwargs):
82
83
85 """return an array of event fields tuples (field,value)"""
86 return [(x, getattr(self, x)) for x in self._fields]
87
88
89
90
91
92
93
94
96 """
97 Update event from list of fields and list of data values.
98 They must have the same length. To be used when pulling data
99 from the backend db.
100 """
101 self._fields = fields
102 data = [d if d is not None else '' for d in data]
103 for field,val in zip(fields, data):
104 setattr(self, field, val)
105
106
108 """Update event from dict. Keys that don't match attributes are
109 put into the detail list of the event.
110 """
111 for key, value in data.items():
112 setattr(self, key, value)
113
115 ret = self.__class__(**self.__dict__)
116
117 ret._fields = self._fields[:]
118 ret._clearClasses = self._clearClasses[:]
119 return ret
120
122 """Return a list of classes that this event clears.
123 if we have specified clearClasses always return them
124 if we ave a 0 severity return ourself as well.
125 """
126 clearcls = self._clearClasses
127 evclass = getattr(self, "eventClass", None)
128 sev = getattr(self, 'severity', None)
129 if evclass and sev == 0:
130 clearcls.append(self.eventClass)
131
132
133 clearcls = list(set(clearcls))
134 return clearcls
135
136
137
138
139
140
141
142
143
145 """Return list of dedupid fields.
146 """
147 return default
148 pb.setUnjellyableForClass(Event, Event)
149
150
151
159 pb.setUnjellyableForClass(EventHeartbeat, EventHeartbeat)
160