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):
69
70
71
72 if not rcvtime:
73 self.firstTime = self.lastTime = time.time()
74 else:
75 self.firstTime = self.lastTime = rcvtime
76 self._clearClasses = []
77 self._action = "status"
78 self._fields = kwargs.get('fields',[])
79 self.eventKey = ''
80 self.component = ''
81 if kwargs: self.updateFromDict(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
90 """return an list of event data"""
91 return [ getattr(self, x) for x in self._fields]
92
93
95 """
96 Update event from list of fields and list of data values.
97 They must have the same length. To be used when pulling data
98 from the backend db.
99 """
100 self._fields = fields
101 for i in range(len(fields)):
102 if data[i] is None: data[i] = ''
103 setattr(self, fields[i], data[i])
104
105
107 """Update event from dict. Keys that don't match attributes are
108 put into the detail list of the event.
109 """
110 for key, value in data.items():
111 setattr(self, key, value)
112
113
115 """Return a list of classes that this event clears.
116 if we have specified clearClasses always return them
117 if we ave a 0 severity return ourself as well.
118 """
119 clearcls = self._clearClasses
120 evclass = getattr(self, "eventClass", None)
121 sev = getattr(self, 'severity', None)
122 if evclass and sev == 0: clearcls.append(self.eventClass)
123 return clearcls
124
125
127 """return a list of data elements that map to the fields parameter.
128 """
129 return map(lambda x: getattr(self, x), fields)
130
131
133 """Return list of dedupid fields.
134 """
135 return default
136 pb.setUnjellyableForClass(Event, Event)
137
138
139
147 pb.setUnjellyableForClass(EventHeartbeat, EventHeartbeat)
148