1
2
3
4
5
6
7
8
9
10
11
12
13
14 import re
15 import json
16
17 from Products.Five.browser import BrowserView
18 from Products.AdvancedQuery import Eq, Or
19
20 from Products.ZenUtils.Utils import relative_time
21 from Products.ZenUtils.jsonutils import json
22 from Products.ZenUtils.Utils import nocache, formreq, extractPostContent
23 from Products.ZenWidgets import messaging
24 from Products.ZenModel.ZenossSecurity import *
25 from Products.ZenEvents.browser.EventPillsAndSummaries import \
26 getDashboardObjectsEventSummary, \
27 ObjectsEventSummary, \
28 getEventPillME
32 """
33 Return JSON event summaries for a root organizer.
34 """
35 @nocache
36 @formreq
40
43
46 """
47 Return a map of device to production state in a format suitable for a
48 YUI data table.
49 """
50 @nocache
51 @formreq
54
55 @json
57 """
58 Return a map of device to production state in a format suitable for a
59 YUI data table.
60
61 @return: A JSON representation of a dictionary describing devices
62 @rtype: "{
63 'columns':['Device', 'Prod State'],
64 'data':[
65 {'Device':'<a href=/>', 'Prod State':'Production'},
66 {'Device':'<a href=/>', 'Prod State':'Maintenance'},
67 ]}"
68 """
69 devroot = self.context.dmd.Devices
70 if type(prodStates)==type(''):
71 prodStates = [prodStates]
72 orderby, orderdir = 'id', 'asc'
73 catalog = getattr(devroot, devroot.default_catalog)
74 queries = []
75 for state in prodStates:
76 queries.append(Eq('getProdState', state))
77 query = Or(*queries)
78 objects = catalog.evalAdvancedQuery(query, ((orderby, orderdir),))
79 devs = (x.getObject() for x in objects)
80 mydict = {'columns':['Device', 'Prod State'], 'data':[]}
81 for dev in devs:
82 if not self.context.checkRemotePerm(ZEN_VIEW, dev): continue
83 mydict['data'].append({
84 'Device' : dev.getPrettyLink(),
85 'Prod State' : dev.getProdState()
86 })
87 mydict['data'] = mydict['data'][:100]
88 return mydict
89
92 """
93 Accepts a list of paths to Zope objects which it then attempts to resolve.
94 If no list of paths is given, it will try to read them from the POST data
95 of the REQUEST object.
96
97 @param entities: A list of paths that should be resolved into objects
98 and passed to L{getDashboardObjectsEventSummaryJSON}.
99 @type entities: list
100 @return: A JSON-formatted string representation of the columns and rows
101 of the table
102 @rtype: string
103 """
104 @nocache
105 @formreq
108
109 @json
111 if entities is None:
112 entities = []
113 elif isinstance(entities, basestring):
114 entities = [entities]
115 def getob(e):
116 e = str(e)
117 try:
118 if not e.startswith('/zport/dmd'):
119 bigdev = '/zport/dmd' + e
120 obj = self.context.dmd.unrestrictedTraverse(bigdev)
121 except (AttributeError, KeyError):
122 obj = self.context.dmd.Devices.findDevice(e)
123 if self.context.has_permission("View", obj): return obj
124 entities = filter(lambda x:x is not None, map(getob, entities))
125 return getDashboardObjectsEventSummary(
126 self.context.dmd.ZenEventManager, entities)
127
130 """
131 A list of devices with issues.
132 """
133 @nocache
136
137 @json
139 """
140 Get devices with issues in a form suitable for a portlet on the
141 dashboard.
142
143 @return: A JSON representation of a dictionary describing devices
144 @rtype: "{
145 'columns':['Device', "Events'],
146 'data':[
147 {'Device':'<a href=/>', 'Events':'<div/>'},
148 {'Device':'<a href=/>', 'Events':'<div/>'},
149 ]}"
150 """
151 mydict = {'columns':[], 'data':[]}
152 mydict['columns'] = ['Device', 'Events']
153 deviceinfo = self.getDeviceDashboard()
154 for alink, pill in deviceinfo:
155 mydict['data'].append({'Device':alink,
156 'Events':pill})
157 return mydict
158
182
185 """
186 Heartbeat issues in YUI table form, for the dashboard portlet
187 """
188 @nocache
191
192 @json
194 """
195 Get heartbeat issues in a form suitable for a portlet on the dashboard.
196
197 @return: A JSON representation of a dictionary describing heartbeats
198 @rtype: "{
199 'columns':['Device', 'Daemon', 'Seconds'],
200 'data':[
201 {'Device':'<a href=/>', 'Daemon':'zenhub', 'Seconds':10}
202 ]}"
203 """
204 mydict = {'columns':[], 'data':[]}
205 mydict['columns'] = ['Device', 'Daemon', 'Seconds']
206 heartbeats = self.context.dmd.ZenEventManager.getHeartbeat()
207 for Device, Daemon, Seconds, dummy in heartbeats:
208 mydict['data'].append({'Device':Device,
209 'Daemon':Daemon, 'Seconds':Seconds})
210 return mydict
211
214 """
215 User messages in YUI table form, for the dashboard portlet.
216 """
217 @nocache
218 @json
220 """
221 Get heartbeat issues in a form suitable for a portlet on the dashboard.
222
223 @return: A JSON representation of a dictionary describing heartbeats
224 @rtype: "{
225 'columns':['Device', 'Daemon', 'Seconds'],
226 'data':[
227 {'Device':'<a href=/>', 'Daemon':'zenhub', 'Seconds':10}
228 ]}"
229 """
230 ICONS = ['/zport/dmd/img/agt_action_success-32.png',
231 '/zport/dmd/img/messagebox_warning-32.png',
232 '/zport/dmd/img/agt_stop-32.png']
233 msgbox = messaging.IUserMessages(self.context)
234 msgs = msgbox.get_messages()
235 cols = ['Message']
236 res = []
237 for msg in msgs:
238 res.append(dict(
239 title = msg.title,
240 imgpath = ICONS[msg.priority],
241 body = msg.body,
242 ago = relative_time(msg.timestamp),
243 deletelink = msg.absolute_url_path() + '/delMsg'
244 ))
245 res.reverse()
246 return { 'columns': cols, 'data': res }
247