Package ZenRRD :: Module zenrender
[hide private]
[frames] | no frames]

Source Code for Module ZenRRD.zenrender

  1  #! /usr/bin/env python  
  2  ########################################################################### 
  3  # 
  4  # This program is part of Zenoss Core, an open source monitoring platform. 
  5  # Copyright (C) 2007, Zenoss Inc. 
  6  # 
  7  # This program is free software; you can redistribute it and/or modify it 
  8  # under the terms of the GNU General Public License version 2 as published by 
  9  # the Free Software Foundation. 
 10  # 
 11  # For complete information please visit: http://www.zenoss.com/oss/ 
 12  # 
 13  ########################################################################### 
 14   
 15  DEFAULT_HTTP_PORT = 8091 
 16   
 17  import Globals 
 18   
 19  from Products.ZenHub.PBDaemon import PBDaemon 
 20  from Products.ZenModel.PerformanceConf import performancePath 
 21  from RenderServer import RenderServer as OrigRenderServer 
 22  from Products.ZenUtils.ObjectCache import ObjectCache 
 23   
 24  from twisted.web import resource, server 
 25  from twisted.internet import reactor 
 26   
 27  import os 
 28  import mimetypes 
 29   
30 -class RenderServer(OrigRenderServer):
31 32 cache = None 33
34 - def setupCache(self):
35 """make new cache if we need one""" 36 if self.cache is None: 37 self.cache = ObjectCache() 38 self.cache.initCache() 39 return self.cache
40
41 -class HttpRender(resource.Resource):
42 43 isLeaf = True 44
45 - def render_GET(self, request):
46 args = request.args.copy() 47 for k, v in args.items(): 48 if len(v) == 1: 49 args[k] = v[0] 50 command = request.postpath[-1] 51 zr.log.debug("Processing %s request" % command) 52 args.setdefault('ftype', 'PNG') 53 ftype = args['ftype'] 54 del args['ftype'] 55 mimetype = mimetypes.guess_type('.%s'%ftype)[0] 56 if not mimetype: mimetype = 'image/%s'%ftype 57 request.setHeader('Content-type', mimetype) 58 return getattr(zr, 'remote_' + command)(**args)
59
60 -class zenrender(PBDaemon):
61 62 initialServices = ['ZenRender'] 63 name = 'zenrender' 64
65 - def __init__(self):
66 PBDaemon.__init__(self) 67 self.rs = RenderServer(self.name)
68
69 - def remote_render(self, *args, **kw):
70 return self.rs.render(*args, **kw)
71
72 - def remote_packageRRDFiles(self, *args, **kw):
73 return self.rs.packageRRDFiles(*args, **kw)
74
75 - def remote_unpackageRRDFiles(self, *args, **kw):
76 return self.rs.unpackageRRDFiles(*args, **kw)
77
78 - def remote_receiveRRDFiles(self, *args, **kw):
79 return self.rs.receiveRRDFiles(*args, **kw)
80
81 - def remote_sendRRDFiles(self, *args, **kw):
82 return self.rs.sendRRDFiles(*args, **kw)
83
84 - def remote_moveRRDFiles(self, *args, **kw):
85 return self.rs.moveRRDFiles(*args, **kw)
86
87 - def remote_plugin(self, *args, **kw):
88 return self.rs.plugin(*args, **kw)
89
90 - def remote_summary(self, *args, **kw):
91 return self.rs.summary(*args, **kw)
92
93 - def remote_currentValues(self, *args, **kw):
94 return self.rs.currentValues(*args, **kw)
95
96 - def buildOptions(self):
97 PBDaemon.buildOptions(self) 98 self.parser.add_option('--http-port', 99 dest='httpport', 100 default=DEFAULT_HTTP_PORT, 101 help='Port zenrender listens on for http' 102 'render requests. Default is %s.' % 103 DEFAULT_HTTP_PORT)
104 105 106 if __name__ == '__main__': 107 zr = zenrender() 108 reactor.listenTCP(int(zr.options.httpport), server.Site(HttpRender())) 109 zr.run() 110