1
2
3
4
5
6
7
8
9
10
11
12
13
14 import re
15
16 from Products.Five.browser import BrowserView
17 from Products.ZenUtils.jsonutils import json
18 from Products.ZenModel.DeviceOrganizer import DeviceOrganizer
22 """
23 Gets event pill for worst severity.
24
25 @return: HTML that will render the event pill.
26 @rtype: str
27 """
28 zem = self.context.dmd.ZenEventManager
29 pill = getEventPillME(zem, self.context)
30 if type(pill)==type([]) and len(pill)==1: return pill[0]
31 return pill
32
35 """
36 Return an HTML link and event pill for each object passed as a JSON
37 object ready for inclusion in a YUI data table.
38
39 @param objects: The objects for which to create links and pills.
40 @type objects: list
41 @return: A JSON-formatted string representation of the columns and rows
42 of the table
43 @rtype: string
44 """
45 @json
50
52 raise NotImplementedError
53
58
63
68
71 """
72 Return an HTML link and event pill for each object passed as a JSON
73 object ready for inclusion in a YUI data table.
74
75 @param objects: The objects for which to create links and pills.
76 @type objects: list
77 @return: A JSON-formatted string representation of the columns and rows
78 of the table
79 @rtype: string
80 """
81 mydict = {'columns':[], 'data':[]}
82 mydict['columns'] = ['Object', 'Events']
83 getcolor = re.compile(r'class=\"evpill-(.*?)\"', re.S|re.I|re.M).search
84 colors = "red orange yellow blue grey green".split()
85 def pillcompare(a,b):
86 a, b = map(lambda x:getcolor(x[1]), (a, b))
87 def getindex(x):
88 try:
89 color = x.groups()[0]
90 smallcolor = x.groups()[0].replace('-acked','')
91 isacked = 'acked' in color
92 index = colors.index(x.groups()[0].replace('-acked',''))
93 if isacked: index += .5
94 return index
95 except: return 5
96 a, b = map(getindex, (a, b))
97 return cmp(a, b)
98 devdata = []
99 for obj in objects:
100 alink = obj.getPrettyLink()
101 pill = getEventPillME(zem, obj, showGreen=True, prodState=prodState)
102 if type(pill)==type([]): pill = pill[0]
103 devdata.append([alink, pill])
104 devdata.sort(pillcompare)
105 mydict['data'] = [{'Object':x[0],'Events':x[1]} for x in devdata]
106 return mydict
107
115
116
117 -def _getPill(summary, url=None, number=3):
118 iconTemplate = """
119 <td class="severity-icon-small
120 %(severity)s %(noevents)s">
121 %(count)s
122 </td>
123 """
124 rainbowTemplate = """
125 <table onclick="location.href='%(url)s';"
126 class="eventrainbow eventrainbow_cols_%(number)s">
127 <tr>%(cells)s</tr>
128 </table>
129 """
130 stati = "critical error warning info debug".split()
131 summary =[x[2] for x in summary]
132
133 cells = []
134 for i, count in enumerate(summary[:number]):
135 cells.append(iconTemplate % {
136 'noevents': '' if count else 'no-events',
137 'severity': stati[i],
138 'count':count
139 })
140 return rainbowTemplate % {
141 'url': url,
142 'cells': ''.join(cells),
143 'number': number
144 }
145
146 -def getEventPill(zem, where, number=3, minSeverity=0, showGreen=True,
147 prodState=None, url=None):
150
151 -def getEventPillME(zem, me, number=3, minSeverity=0, showGreen=True,
152 prodState=None):
153 """
154 Get HTML code displaying the maximum event severity and the number of
155 events of that severity on a particular L{ManagedEntity} in a pleasing
156 pill-shaped container. Optionally return pills for lesser severities as
157 well. Optionally return a green pill if there are no events (normally no
158 events in a severity will not yield a result).
159
160 @param zem: A reference to ZenEventManager
161 @type zem: L{Products.ZenEvents.EventManagerBase.EventManagerBase}
162 @param me: The object regarding which event data should be queried.
163 @type me: L{ManagedEntity}
164 @param number: The number of pills to return
165 @type number: int
166 @param showGreen: Whether to return an empty green pill if all is well
167 @type showGreen: bool
168 @return: HTML strings ready for template inclusion
169 @rtype: list
170 """
171 evsum = zem.getEventSummaryME(me, minSeverity, prodState=prodState)
172 url = getEventsURL(me)
173 return _getPill(evsum, url, number)
174
175
176 organizerTypes = {
177 'Devices': 'devices',
178 'Groups': 'groups',
179 'Locations': 'locs',
180 'Systems': 'systems'
181 }
198