def load_parser(self, rule, feed, limit=None, data=None, filters=None): if isinstance(rule, str): rule = Rule(rule) fetch = Fetcher(rule, feed, data=data, no_fetch=self.no_fetch, verify_ssl=self.verify_ssl, limit=limit) self.last_cache = fetch.cache parser_name = rule.feeds[feed].get('parser') or rule.parser or PARSER_DEFAULT if not parser_name: from csirtg_smrt.utils.zcontent import get_type try: parser_name = get_type(self.last_cache) except Exception as e: logger.error(e) if not parser_name: parser_name = PARSER_DEFAULT plugin_path = os.path.join(os.path.dirname(__file__), 'parser') if getattr(sys, 'frozen', False): plugin_path = os.path.join(sys._MEIPASS, plugin_path) parser = load_plugin(plugin_path, parser_name) if parser is None: self.logger.info('trying z{}'.format(parser_name)) parser = load_plugin(csirtg_smrt.parser.__path__[0], 'z{}'.format(parser_name)) if parser is None: raise SystemError('Unable to load parser: {}'.format(parser_name)) self.logger.debug("loading parser: {}".format(parser)) return parser(self.client, fetch, rule, feed, limit=limit, filters=filters, fireball=self.fireball)
def _process(self, rule, feed, limit=None): fetch = Fetcher(rule, feed) parser_name = rule.parser or PARSER_DEFAULT parser = load_plugin(csirtg_smrt.parser.__path__[0], parser_name) if parser is None: self.logger.info('trying z{}'.format(parser_name)) parser = load_plugin(csirtg_smrt.parser.__path__[0], 'z{}'.format(parser_name)) if parser is None: raise SystemError('Unable to load parser: {}'.format(parser_name)) self.logger.debug("loading parser: {}".format(parser)) parser = parser(self.client, fetch, rule, feed, limit=limit) rv = parser.process() return rv