1
2
3
4
5
6
7
8
9
10
11 import time
12
13 from Products.ZenEvents.ZenEventClasses import *
14 from Products.ZenEvents.Exceptions import *
15
16 from twisted.spread import pb
17
19 """Build an event object from a dictionary.
20 """
21 evclass = evdict.get("eventClass", Unknown)
22 if evclass == Heartbeat:
23 for field in ("device", "component", "timeout"):
24 if field not in evdict:
25 raise ZenEventError("Required event field %s not found: %s" % (field, evdict))
26 evt = EventHeartbeat(evdict['device'], evdict['component'],
27 evdict['timeout'])
28 else:
29 evt = Event(**evdict)
30 return evt
31
32
33
34 -class Event(pb.Copyable, pb.RemoteCopy):
35 """
36 Event that lives independant of zope context. As interface that allows
37 it to be persisted to/from the event backend.
38 dedupid,
39 evid,
40 device,
41 ipAddress,
42 component,
43 eventClass,
44 eventGroup,
45 eventKey,
46 facility,
47 severity,
48 priority,
49 summary,
50 message,
51 stateChange,
52 firstTime,
53 lastTime,
54 count,
55 prodState,
56 DevicePriority,
57 manager,
58 agent,
59 DeviceClass,
60 Location,
61 Systems,
62 DeviceGroups,
63 """
64
65 - def __init__(self, rcvtime=None, **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
86
87
88
89
90
91
93 """
94 Update event from list of fields and list of data values.
95 They must have the same length. To be used when pulling data
96 from the backend db.
97 """
98 self._fields = fields
99 data = [d if d is not None else '' for d in data]
100 for field,val in zip(fields, data):
101 setattr(self, field, val)
102
103
105 """Update event from dict. Keys that don't match attributes are
106 put into the detail list of the event.
107 """
108 for key, value in data.items():
109 setattr(self, key, value)
110
112 ret = self.__class__(**self.__dict__)
113
114 ret._fields = self._fields[:]
115 ret._clearClasses = self._clearClasses[:]
116 return ret
117
119 """Return a list of classes that this event clears.
120 if we have specified clearClasses always return them
121 if we ave a 0 severity return ourself as well.
122 """
123 clearcls = self._clearClasses
124 evclass = getattr(self, "eventClass", None)
125 sev = getattr(self, 'severity', None)
126 if evclass and sev == 0:
127 clearcls.append(self.eventClass)
128
129
130 clearcls = list(set(clearcls))
131 return clearcls
132
133
134
135
136
137
138
139
140
142 """Return list of dedupid fields.
143 """
144 return default
145 pb.setUnjellyableForClass(Event, Event)
146
147
148
156 pb.setUnjellyableForClass(EventHeartbeat, EventHeartbeat)
157