1
2
3
4
5
6
7
8
9
10
11
12
13
14 import urllib
15 from Products.Five.browser import BrowserView
16 from Products.ZenUtils.json import json
17 from Products.ZenUtils.Utils import unused, formreq
18
19
21 """
22 A view for Devices, CustomEventViews and EventViews that provides JSON data
23 to populate the event console widget.
24 """
27
28 @json
29 @formreq
30 - def _getEventsData(self, offset=0, count=50, getTotalCount=True,
31 startdate=None, enddate=None, filter='', severity=2,
32 state=1, orderby='', **kwargs):
33 """
34 Data that populates the event console.
35
36 @return: A JSON representation of a tuple containing a list of lists of
37 event info, and the total number of matching events
38 @rtype: "([[a, b, c], [a, b, c]], 17)"
39 """
40 unused(kwargs)
41
42 context = self.context
43 zem = self._getEventManager()
44
45 if hasattr(context, 'getResultFields'):
46 fields = context.getResultFields()
47 else:
48
49 if hasattr(context, 'event_key'):
50 base = context
51 else:
52 base = zem.dmd.Events
53 fields = zem.lookupManagedEntityResultFields(base.event_key)
54
55 data, totalCount = zem.getEventListME(context,
56 offset=offset, rows=count, resultFields=fields,
57 getTotalCount=getTotalCount, filter=filter, severity=severity,
58 state=state, orderby=orderby, startdate=startdate, enddate=enddate)
59
60 results = [self._extract_data_from_zevent(ev, fields) for ev in data]
61 return (results, totalCount)
62
64 return self.context.dmd.ZenEventManager
65
67 """return a list of data elements that map to the fields parameter.
68 """
69 def _sanitize(val):
70 return val.replace('<', '<').replace('>','>')
71
72 data = []
73 for field in fields:
74 value = getattr(zevent, field)
75 _shortvalue = str(value) or ''
76 if field == "device":
77 value = urllib.quote('<a class="%s"' % ('') +
78 ' href="/zport/dmd/deviceSearchResults'
79 '?query=%s">%s</a>' % (value, _shortvalue))
80 elif field == 'eventClass':
81 _shortvalue = _shortvalue.replace('/','/­')
82 if not zevent.eventPermission:
83 value = _shortvalue
84 else:
85 value = urllib.quote('<a class="%s" ' % ('') +
86 'href="/zport/dmd/Events%s">%s</a>' % (value,_shortvalue))
87 elif field == 'component' and getattr(zevent, 'device', None):
88 value = urllib.quote('<a class="%s"' % ('') +
89 ' href="/zport/dmd/searchComponents'
90 '?device=%s&component=%s">%s</a>' % (
91 getattr(zevent, 'device'), value, _shortvalue))
92 elif field == 'summary':
93 value = urllib.quote(
94 value.replace('<','<').replace('>','>'))
95 else:
96 value = _shortvalue
97 data.append(value)
98 data.append(zevent.evid)
99 data.append(zevent.getCssClass())
100 return data
101
102
104 """
105 Get the fields for the event console. This is a separate call so that the
106 header DOM elements can be created first.
107
108 FIXME: Make the event console a single call.
109 """
112
113 @json
133
135 return self.context.dmd.ZenEventManager
136
137
138 -class HistoryConsole(EventConsole):
139 """
140 Same as the event console, only it accesses the history table.
141 """
143 return self.context.dmd.ZenEventHistory
144
145
146 -class HistoryConsoleFields(EventConsoleFields):
147 """
148 Same as the event console fields, only for history.
149
150 FIXME: Is this used anywhere?
151 """
153 return self.context.dmd.ZenEventHistory
154