Package Products :: Package ZenReports :: Module ReportServer |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenReports.ReportServer

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2007, Zenoss Inc.
     5  #
     6  # This program is free software; you can redistribute it and/or modify it
     7  # under the terms of the GNU General Public License version 2 as published by
     8  # the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13  __doc__="""ReportServer
    14
    15  A front end to all the report plugins.
    16
    17  $Id: $"""
    18
    19  __version__ = "$Revision: $"[11:-2]
    20
    21  from Globals import InitializeClass
    22
    23  from AccessControl import ClassSecurityInfo
    24
    25  from Products.ZenModel.ZenModelRM import ZenModelRM
    26  from Products.ZenUtils.Utils import importClass, zenPath
    27  from Products.ZenModel.ZenossSecurity import *
    28
    29  import os
    30  import sys
    31
    32 -class ReportServer(ZenModelRM):
    33      security = ClassSecurityInfo()
    34      security.setDefaultAccess('allow')
    35
    36      security.declareProtected(ZEN_COMMON, 'plugin')
    37 -    def plugin(self, name, REQUEST):
    38          "Run a plugin to generate the report object"
    39          dmd = self.dmd
    40          args = dict(zip(REQUEST.keys(), REQUEST.values()))
    41
    42          # We don't want the response object getting passed to the plugin
    43          # because if it is stringified, it can modify the return code
    44          # and cause problems upstream.
    45          if 'RESPONSE' in args:
    46              del args['RESPONSE']
    47
    48          m = zenPath('Products/ZenReports/plugins')
    49          directories = [
    50              p.path('reports', 'plugins') for p in self.ZenPackManager.packs()
    51              ] + [m]
    52
    53          klass = None
    54          for d in directories:
    55              if os.path.exists('%s/%s.py' % (d, name)):
    56                  try:
    57                      sys.path.insert(0, d)
    58                      klass = importClass(name)
    59                      break
    60                  finally:
    61                      sys.path.remove(d)
    62          if not klass:
    63              raise IOError('Unable to find plugin named "%s"' % name)
    64          instance = klass()
    65          return instance.run(dmd, args)
    66
    67 -def manage_addReportServer(context, id, REQUEST = None):
    68      """make a ReportServer"""
    69      rs = ReportServer(id)
    70      context._setObject(id, rs)
    71      if REQUEST is not None:
    72          REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
    73
    74
    75  InitializeClass(ReportServer)
    76