def _start_api(bot): # Start and asyncio event loop loop = asyncio.get_event_loop() api = bot.get_config_option('api') itemNo = -1 if isinstance(api, list): for sinkConfig in api: itemNo += 1 try: certfile = sinkConfig["certfile"] if not certfile: print("config.api[{}].certfile must be configured".format(itemNo)) continue name = sinkConfig["name"] port = sinkConfig["port"] except KeyError as e: print("config.api[{}] missing keyword".format(itemNo), e) continue logger.info("started on https://{}:{}/".format(name, port)) threadmanager.start_thread(start_listening, args=( bot, loop, name, port, certfile, APIRequestHandler, "plugin-api"))
def _start_api(bot): # Start and asyncio event loop loop = asyncio.get_event_loop() api = bot.get_config_option('api') itemNo = -1 if isinstance(api, list): for sinkConfig in api: itemNo += 1 try: certfile = sinkConfig["certfile"] if not certfile: print("config.api[{}].certfile must be configured".format( itemNo)) continue name = sinkConfig["name"] port = sinkConfig["port"] except KeyError as e: print("config.api[{}] missing keyword".format(itemNo), e) continue logger.info("started on https://{}:{}/".format(name, port)) threadmanager.start_thread(start_listening, args=(bot, loop, name, port, certfile, APIRequestHandler, "plugin-api"))
def _start_slack_sinks(bot): # Start and asyncio event loop loop = asyncio.get_event_loop() slack_sink = bot.get_config_option('slack') itemNo = -1 if isinstance(slack_sink, list): for sinkConfig in slack_sink: itemNo += 1 try: certfile = sinkConfig["certfile"] if not certfile: print( "config.slack[{}].certfile must be configured".format( itemNo)) continue name = sinkConfig["name"] port = sinkConfig["port"] except KeyError as e: print("config.slack[{}] missing keyword".format(itemNo), e) continue logger.info("started on https://{}:{}/".format(name, port)) threadmanager.start_thread(start_listening, args=(bot, loop, name, port, certfile)) logger.info( "_start_slack_sinks(): {} sink thread(s) started".format(itemNo + 1))
def _start_slack_sinks(bot): # Start and asyncio event loop loop = asyncio.get_event_loop() slack_sink = bot.get_config_option('slack') itemNo = -1 if isinstance(slack_sink, list): for sinkConfig in slack_sink: itemNo += 1 try: certfile = sinkConfig["certfile"] if not certfile: print("config.slack[{}].certfile must be configured".format(itemNo)) continue name = sinkConfig["name"] port = sinkConfig["port"] except KeyError as e: print("config.slack[{}] missing keyword".format(itemNo), e) continue logger.info("started on https://{}:{}/".format(name, port)) threadmanager.start_thread(start_listening, args=( bot, loop, name, port, certfile)) logger.info("_start_slack_sinks(): {} sink thread(s) started".format(itemNo + 1))
def _start_sinks(self, bot): loop = asyncio.get_event_loop() itemNo = -1 threads = [] if isinstance(self.configuration, list): for listener in self.configuration: itemNo += 1 try: certfile = listener["certfile"] if not certfile: logger.warning("config.{}[{}].certfile must be configured".format(self.configkey, itemNo)) continue name = listener["name"] port = listener["port"] except KeyError as e: logger.warning("config.{}[{}] missing keyword".format(self.configkey, itemNo)) continue threadmanager.start_thread(start_listening, args=( bot, loop, name, port, certfile, self.RequestHandler, self.configkey)) logger.info("webbridge.sinks: {} thread(s) started for {}".format(itemNo, self.configkey))
def start(bot): shared_loop = asyncio.get_event_loop() jsonrpc_sinks = bot.get_config_option('jsonrpc') itemNo = -1 threadcount = 0 if isinstance(jsonrpc_sinks, list): for sinkConfig in jsonrpc_sinks: itemNo += 1 try: module = sinkConfig["module"].split(".") if len(module) < 3: logger.error("config.jsonrpc[{}].module should have at least 3 packages {}".format(itemNo, module)) continue module_name = ".".join(module[0:-1]) class_name = ".".join(module[-1:]) if not module_name or not class_name: logger.error("config.jsonrpc[{}].module must be a valid package name".format(itemNo)) continue certfile = sinkConfig["certfile"] if not certfile: logger.error("config.jsonrpc[{}].certfile must be configured".format(itemNo)) continue name = sinkConfig["name"] port = sinkConfig["port"] except KeyError as e: logger.error("config.jsonrpc[{}] missing keyword".format(itemNo), e) continue try: handler_class = class_from_name(module_name, class_name) except (AttributeError, ImportError) as e: logger.error("not found: {} {}".format(module_name, class_name)) continue # start up rpc listener in a separate thread logger.debug("starting sink: {}".format(module)) threadmanager.start_thread(start_listening, args=( bot, shared_loop, name, port, certfile, handler_class, module_name)) threadcount = threadcount + 1 if threadcount: logger.info("{} sink(s) from config.jsonrpc".format(threadcount))
def start(bot): shared_loop = asyncio.get_event_loop() jsonrpc_sinks = bot.get_config_option('jsonrpc') itemNo = -1 if isinstance(jsonrpc_sinks, list): for sinkConfig in jsonrpc_sinks: itemNo += 1 try: module = sinkConfig["module"].split(".") if len(module) < 3: print("config.jsonrpc[{}].module should have at least 3 packages {}".format(itemNo, module)) continue module_name = ".".join(module[0:-1]) class_name = ".".join(module[-1:]) if not module_name or not class_name: print(_("config.jsonrpc[{}].module must be a valid package name").format(itemNo)) continue certfile = sinkConfig["certfile"] if not certfile: print(_("config.jsonrpc[{}].certfile must be configured").format(itemNo)) continue name = sinkConfig["name"] port = sinkConfig["port"] except KeyError as e: print(_("config.jsonrpc[{}] missing keyword").format(itemNo), e) continue try: handler_class = class_from_name(module_name, class_name) except AttributeError as e: logging.exception(e) print("could not identify sink: {} {}".format(module_name, class_name)) continue # start up rpc listener in a separate thread print(_("_start_sinks(): {}").format(module)) threadmanager.start_thread(start_listening, args=( bot, shared_loop, name, port, certfile, handler_class, module_name)) message = _("_start_sinks(): {} sink thread(s) started").format(len(threadmanager.threads)) logging.info(message)
def _initialise(bot): loop = asyncio.get_event_loop() threadmanager.start_thread(_periodic_watermark_update, args=(bot, loop))
def start(bot): shared_loop = asyncio.get_event_loop() jsonrpc_sinks = bot.get_config_option('jsonrpc') itemNo = -1 threadcount = 0 aiohttpcount = 0 if isinstance(jsonrpc_sinks, list): for sinkConfig in jsonrpc_sinks: itemNo += 1 try: module = sinkConfig["module"].split(".") if len(module) < 3: logger.error( "config.jsonrpc[{}].module should have at least 3 packages {}" .format(itemNo, module)) continue module_name = ".".join(module[0:-1]) class_name = ".".join(module[-1:]) if not module_name or not class_name: logger.error( "config.jsonrpc[{}].module must be a valid package name" .format(itemNo)) continue certfile = sinkConfig.get("certfile") if certfile and not os.path.isfile(certfile): logger.error( "config.jsonrpc[{}].certfile not available at {}". format(itemNo, certfile)) continue name = sinkConfig["name"] port = sinkConfig["port"] except KeyError as e: logger.error( "config.jsonrpc[{}] missing keyword".format(itemNo), e) continue try: handler_class = class_from_name(module_name, class_name) except (AttributeError, ImportError) as e: logger.error("not found: {} {}".format(module_name, class_name)) continue # start up rpc listener in a separate thread logger.debug("starting sink: {}".format(module)) if issubclass(handler_class, AsyncRequestHandler): aiohttp_start(bot, name, port, certfile, handler_class, "json-rpc") aiohttpcount = aiohttpcount + 1 else: threadmanager.start_thread(start_listening, args=(bot, shared_loop, name, port, certfile, handler_class, module_name)) threadcount = threadcount + 1 if threadcount: logger.info("{} threaded listener(s)".format(threadcount)) if aiohttpcount: logger.info("{} aiohttp web listener(s)".format(aiohttpcount))
def start(bot): shared_loop = asyncio.get_event_loop() jsonrpc_sinks = bot.get_config_option("jsonrpc") itemNo = -1 threadcount = 0 aiohttpcount = 0 if isinstance(jsonrpc_sinks, list): for sinkConfig in jsonrpc_sinks: itemNo += 1 try: module = sinkConfig["module"].split(".") if len(module) < 3: logger.error("config.jsonrpc[{}].module should have at least 3 packages {}".format(itemNo, module)) continue module_name = ".".join(module[0:-1]) class_name = ".".join(module[-1:]) if not module_name or not class_name: logger.error("config.jsonrpc[{}].module must be a valid package name".format(itemNo)) continue certfile = sinkConfig.get("certfile") if certfile and not os.path.isfile(certfile): logger.error("config.jsonrpc[{}].certfile not available at {}".format(itemNo, certfile)) continue name = sinkConfig["name"] port = sinkConfig["port"] except KeyError as e: logger.error("config.jsonrpc[{}] missing keyword".format(itemNo), e) continue try: handler_class = class_from_name(module_name, class_name) except (AttributeError, ImportError) as e: logger.error("not found: {} {}".format(module_name, class_name)) continue # start up rpc listener in a separate thread logger.debug("starting sink: {}".format(module)) if issubclass(handler_class, AsyncRequestHandler): aiohttp_start(bot, name, port, certfile, handler_class, "json-rpc") aiohttpcount = aiohttpcount + 1 else: threadmanager.start_thread( start_listening, args=(bot, shared_loop, name, port, certfile, handler_class, module_name) ) threadcount = threadcount + 1 if threadcount: logger.info("{} threaded listener(s)".format(threadcount)) if aiohttpcount: logger.info("{} aiohttp web listener(s)".format(aiohttpcount))
def _initialise(bot): loop = asyncio.get_event_loop() threadmanager.start_thread(_periodic_watermark_update, args=( bot, loop))