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 pill = getEventPillME(self.context)
29 if isinstance(pill, (list, tuple)) and len(pill)==1: return pill[0]
30 return pill
31
34 """
35 Return an HTML link and event pill for each object passed as a JSON
36 object ready for inclusion in a YUI data table.
37
38 @param objects: The objects for which to create links and pills.
39 @type objects: list
40 @return: A JSON-formatted string representation of the columns and rows
41 of the table
42 @rtype: string
43 """
44 @json
49
51 raise NotImplementedError
52
57
62
67
70 """
71 Return an HTML link and event pill for each object passed as a JSON
72 object ready for inclusion in a YUI data table.
73
74 @param objects: The objects for which to create links and pills.
75 @type objects: list
76 @return: A JSON-formatted string representation of the columns and rows
77 of the table
78 @rtype: string
79 """
80 mydict = {'columns':[], 'data':[]}
81 mydict['columns'] = ['Object', 'Events']
82 getcolor = re.compile(r'class=\"evpill-(.*?)\"', re.S|re.I|re.M).search
83 colors = ('red','orange','yellow','blue','grey','green')
84 def pillcompare(a,b):
85 a, b = map(lambda x:getcolor(x[1]), (a, b))
86 def getindex(x):
87 try:
88 color = x.groups()[0]
89 smallcolor = x.groups()[0].replace('-acked','')
90 isacked = 'acked' in color
91 index = colors.index(x.groups()[0].replace('-acked',''))
92 if isacked: index += .5
93 return index
94 except: return 5
95 a, b = map(getindex, (a, b))
96 return cmp(a, b)
97 devdata = []
98 for obj in objects:
99 alink = obj.getPrettyLink()
100 pill = getEventPillME(obj, showGreen=True, prodState=prodState)
101 if isinstance(pill, (list, tuple)): pill = pill[0]
102 devdata.append([alink, pill])
103 devdata.sort(pillcompare)
104 mydict['data'] = [{'Object':x[0],'Events':x[1]} for x in devdata]
105 return mydict
106
114
115
116 -def _getPill(summary, url=None, number=3):
117 iconTemplate = """
118 <td class="severity-icon-small
119 %(severity)s %(cssclass)s"
120 title="%(acked)s out of %(total)s acknowledged">
121 %(total)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')
131 summary = [summary[x] for x in stati]
132
133 cells = []
134 for i, counts in enumerate(summary[:number]):
135 total = counts['count']
136 acked = counts['acknowledged_count']
137 cssclass = 'no-events' if not total else 'acked-events' if total==acked else ''
138 cells.append(iconTemplate % {
139 'cssclass': cssclass,
140 'severity': stati[i],
141 'total': total,
142 'acked': acked
143 })
144 return rainbowTemplate % {
145 'url': url,
146 'cells': ''.join(cells),
147 'number': number
148 }
149
150 -def getEventPillME(me, number=3, minSeverity=0, showGreen=True,
151 prodState=None, severities=None):
152 """
153 Get HTML code displaying the maximum event severity and the number of
154 events of that severity on a particular L{ManagedEntity} in a pleasing
155 pill-shaped container. Optionally return pills for lesser severities as
156 well. Optionally return a green pill if there are no events (normally no
157 events in a severity will not yield a result).
158
159 @param me: The object regarding which event data should be queried.
160 @type me: L{ManagedEntity}
161 @param number: The number of pills to return
162 @type number: int
163 @param showGreen: Whether to return an empty green pill if all is well
164 @type showGreen: bool
165 @return: HTML strings ready for template inclusion
166 @rtype: list
167 @param severities: The severity counts that you can pass in if
168 you do not want the getEventSeveritiesCount to be called. This is useful
169 for batch pills queries
170 @param type: dictionary
171 """
172 url = getEventsURL(me)
173 sevs = severities
174 if not severities:
175 sevs = me.getEventSeveritiesCount()
176 return _getPill(sevs, url, number)
177
178
179 organizerTypes = {
180 'Devices': 'devices',
181 'Groups': 'groups',
182 'Locations': 'locs',
183 'Systems': 'systems'
184 }
201