1
2
3
4
5
6
7
8
9
10
11
12
13
14 import urllib
15 from Products.Five.browser import BrowserView
16
17 from Products.ZenUtils.json import json
18 from Products.ZenUtils.Utils import unused
19
20
22 """
23 A view for Devices, CustomEventViews and EventViews that provides JSON data
24 to populate the event console widget.
25 """
28
29 @json
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 unused(kwargs)
37
38 context = self.context
39 zem = self._getEventManager()
40
41 if hasattr(context, 'getResultFields'):
42 fields = context.getResultFields()
43 else:
44
45 if hasattr(context, 'event_key'):
46 base = context
47 else:
48 base = zem.dmd.Events
49 fields = zem.lookupManagedEntityResultFields(base.event_key)
50
51 data, totalCount = zem.getEventListME(context,
52 offset=offset, rows=count, resultFields=fields,
53 getTotalCount=getTotalCount, filter=filter, severity=severity,
54 state=state, orderby=orderby, startdate=startdate, enddate=enddate)
55
56 results = [self._extract_data_from_zevent(ev, fields) for ev in data]
57 return (results, totalCount)
58
60 return self.context.dmd.ZenEventManager
61
63 """return a list of data elements that map to the fields parameter.
64 """
65 def _sanitize(val):
66 return val.replace('<', '<').replace('>','>')
67
68 data = []
69 for field in fields:
70 value = getattr(zevent, field)
71 _shortvalue = str(value) or ''
72 if field == "device":
73 value = urllib.quote('<a class="%s"' % ('') +
74 ' href="/zport/dmd/deviceSearchResults'
75 '?query=%s">%s</a>' % (value, _shortvalue))
76 elif field == 'eventClass':
77 _shortvalue = _shortvalue.replace('/','/­')
78 if not zevent.eventPermission:
79 value = _shortvalue
80 else:
81 value = urllib.quote('<a class="%s" ' % ('') +
82 'href="/zport/dmd/Events%s">%s</a>' % (value,_shortvalue))
83 elif field == 'component' and getattr(zevent, 'device', None):
84 value = urllib.quote('<a class="%s"' % ('') +
85 ' href="/zport/dmd/searchComponents'
86 '?device=%s&component=%s">%s</a>' % (
87 getattr(zevent, 'device'), value, _shortvalue))
88 elif field == 'summary':
89 value = urllib.quote(
90 value.replace('<','<').replace('>','>'))
91 else:
92 value = _shortvalue
93 data.append(value)
94 data.append('evid')
95 data.append(zevent.getCssClass())
96 return data
97
98
100 """
101 Get the fields for the event console. This is a separate call so that the
102 header DOM elements can be created first.
103
104 FIXME: Make the event console a single call.
105 """
108
109 @json
124
126 return self.context.dmd.ZenEventManager
127
128
129 -class HistoryConsole(EventConsole):
130 """
131 Same as the event console, only it accesses the history table.
132 """
134 return self.context.dmd.ZenEventHistory
135
136
137 -class HistoryConsoleFields(EventConsoleFields):
138 """
139 Same as the event console fields, only for history.
140
141 FIXME: Is this used anywhere?
142 """
144 return self.context.dmd.ZenEventHistory
145