@@ -79,10 +79,7 @@ def setup_cherrypy_logging(args):
7979
8080def updateCherrypyConf (args ):
8181
82- globalConfig = {'global' : {'server.socket_port' : args .get ('port' ),
83- # default error response
84- 'error_page.default' : format_default_error_page ,
85- # unexpected errors
82+ globalConfig = {'global' : {'error_page.default' : format_default_error_page ,
8683 'request.error_response' : handle_error },
8784 }
8885
@@ -91,6 +88,20 @@ def updateCherrypyConf(args):
9188 dirname , filename = os .path .split (os .path .abspath (__file__ ))
9289 customconf = os .path .join (dirname , 'mycherrypy.conf' )
9390 cherrypy .config .update (customconf )
91+ cherrypy .server .unsubscribe ()
92+
93+
94+ def bind_opentsdb_server (args ):
95+ opentsdb_server = cherrypy ._cpserver .Server ()
96+ opentsdb_server .socket_port = args .get ('port' )
97+ opentsdb_server ._socket_host = '0.0.0.0'
98+ if args .get ('protocol' ) == "https" :
99+ certPath = os .path .join (args .get ('tlsKeyPath' ), args .get ('tlsCertFile' ))
100+ keyPath = os .path .join (args .get ('tlsKeyPath' ), args .get ('tlsKeyFile' ))
101+ opentsdb_server .ssl_module = 'builtin'
102+ opentsdb_server .ssl_certificate = certPath
103+ opentsdb_server .ssl_private_key = keyPath
104+ opentsdb_server .subscribe ()
94105
95106
96107def updateCherrypySslConf (args ):
@@ -164,8 +175,6 @@ def main(argv):
164175
165176 # prepare cherrypy server configuration
166177 updateCherrypyConf (args )
167- if args .get ('protocol' ) == "https" :
168- updateCherrypySslConf (args )
169178
170179 # prepare metadata
171180 try :
@@ -203,44 +212,47 @@ def main(argv):
203212 logger .error ("ZiMon sensor configuration file not found" )
204213 return
205214
206- api = OpenTsdbApi (logger , mdHandler )
207- cherrypy .tree .mount (api , '/api/query' ,
208- {'/' :
209- {'request.dispatch' : cherrypy .dispatch .MethodDispatcher (),
210- 'request.body.processors' : {'application/x-www-form-urlencoded' : processFormJSON }
211- }
212- }
213- )
214- # query for metric name (openTSDB: zimon extension returns keys as well)
215- cherrypy .tree .mount (api , '/api/suggest' ,
216- {'/' :
217- {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
218- }
219- )
220- # query for tag name and value, given a metric (openTSDB)
221- cherrypy .tree .mount (api , '/api/search/lookup' ,
222- {'/' :
223- {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
224- }
225- )
226- # query to force update of metadata (zimon feature)
227- cherrypy .tree .mount (api , '/api/update' ,
228- {'/' :
229- {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
230- }
231- )
232- # query for list of aggregators (openTSDB)
233- cherrypy .tree .mount (api , '/api/aggregators' ,
234- {'/' :
235- {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
236- }
237- )
238- # query for list of filters (openTSDB)
239- cherrypy .tree .mount (api , '/api/config/filters' ,
240- {'/' :
241- {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
242- }
243- )
215+ if args .get ('port' ):
216+ bind_opentsdb_server (args )
217+ api = OpenTsdbApi (logger , mdHandler )
218+
219+ cherrypy .tree .mount (api , '/api/query' ,
220+ {'/' :
221+ {'request.dispatch' : cherrypy .dispatch .MethodDispatcher (),
222+ 'request.body.processors' : {'application/x-www-form-urlencoded' : processFormJSON }
223+ }
224+ }
225+ )
226+ # query for metric name (openTSDB: zimon extension returns keys as well)
227+ cherrypy .tree .mount (api , '/api/suggest' ,
228+ {'/' :
229+ {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
230+ }
231+ )
232+ # query for tag name and value, given a metric (openTSDB)
233+ cherrypy .tree .mount (api , '/api/search/lookup' ,
234+ {'/' :
235+ {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
236+ }
237+ )
238+ # query to force update of metadata (zimon feature)
239+ cherrypy .tree .mount (api , '/api/update' ,
240+ {'/' :
241+ {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
242+ }
243+ )
244+ # query for list of aggregators (openTSDB)
245+ cherrypy .tree .mount (api , '/api/aggregators' ,
246+ {'/' :
247+ {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
248+ }
249+ )
250+ # query for list of filters (openTSDB)
251+ cherrypy .tree .mount (api , '/api/config/filters' ,
252+ {'/' :
253+ {'request.dispatch' : cherrypy .dispatch .MethodDispatcher ()}
254+ }
255+ )
244256
245257 try :
246258 files_to_watch = SensorConfig .get_config_paths ()
0 commit comments