1
2
3
4
5
6
7
8
9
10
11
12
13 __doc__ = """ReportServer
14
15 A front end to all the report plugins.
16
17 """
18
19
20 import os
21 import sys
22 from glob import glob
23 import logging
24 log = logging.getLogger('zen.reportserver')
25
26 from Globals import InitializeClass
27 from AccessControl import ClassSecurityInfo
28
29 from Products.ZenModel.ZenModelRM import ZenModelRM
30 from Products.ZenUtils.Utils import importClass, zenPath
31 from Products.ZenModel.ZenossSecurity import *
32
33
35 security = ClassSecurityInfo()
36 security.setDefaultAccess('allow')
37
39 directories = []
40 for p in self.ZenPackManager.packs():
41 if p.id == 'broken':
42 continue
43 try:
44 pluginpath = p.path('reports', 'plugins')
45 directories.append(pluginpath)
46 except AttributeError:
47 log.warn("Unable to load report plugins for ZenPack %s",
48 p.id)
49 directories.append(zenPath('Products/ZenReports/plugins'))
50 return directories
51
53 allPlugins = []
54 for dir in self._getPluginDirectories():
55 plugins = [fn.replace('.py','') for fn in glob('%s/*.py' % dir) \
56 if not fn.endswith('__init__.py')]
57 allPlugins.extend(plugins)
58 return allPlugins
59
86
87 security.declareProtected(ZEN_COMMON, 'plugin')
88 - def plugin(self, name, REQUEST, templateArgs = None):
89 "Run a plugin to generate the report object"
90 dmd = self.dmd
91 args = dict(zip(REQUEST.keys(), REQUEST.values()))
92
93
94
95
96 if 'RESPONSE' in args:
97 del args['RESPONSE']
98
99 klass = self._importPluginClass(name)
100 if not klass:
101 raise IOError('Unable to find plugin named "%s"' % name)
102 instance = klass()
103 log.debug("Running plugin %s", name)
104 if templateArgs == None:
105 return instance.run(dmd, args)
106 else:
107 return instance.run(dmd, args, templateArgs)
108
115
116
117 InitializeClass(ReportServer)
118