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 __init__(self, token=TOKEN, remote=REMOTE_ADDR, client='stdout', username=None, feed=None, archiver=None, fireball=False, no_fetch=False, verify_ssl=True, goback=False, skip_invalid=False, send_retries=5, send_retries_wait=30): self.logger = logging.getLogger(__name__) self.client = None if client != 'stdout': plugin_path = os.path.join(os.path.dirname(__file__), 'client') if getattr(sys, 'frozen', False): plugin_path = os.path.join(sys._MEIPASS, 'csirtg_smrt', 'client') self.client = load_plugin(plugin_path, client) if not self.client: raise RuntimeError("Unable to load plugin: {}".format(client)) self.client = self.client(remote=remote, token=token, username=username, feed=feed, fireball=fireball, verify_ssl=verify_ssl) self.archiver = archiver or NOOPArchiver() self.fireball = fireball self.no_fetch = no_fetch self.goback = goback self.skip_invalid = skip_invalid self.verify_ssl = verify_sslĂ self.last_cache = None self.send_retries = send_retries self.send_retries_wait = send_retries_wait
def __init__(self, token=TOKEN, remote=REMOTE_ADDR, client='stdout', username=None, feed=None, archiver=None, fireball=False, no_fetch=False, verify_ssl=True, goback=False, skip_invalid=False, send_retries=5, send_retries_wait=30): self.logger = logging.getLogger(__name__) self.client = None if client != 'stdout': plugin_path = os.path.join(os.path.dirname(__file__), 'client') if getattr(sys, 'frozen', False): plugin_path = os.path.join(sys._MEIPASS, 'csirtg_smrt', 'client') self.client = load_plugin(plugin_path, client) if not self.client: raise RuntimeError("Unable to load plugin: {}".format(client)) self.client = self.client(remote=remote, token=token, username=username, feed=feed, fireball=fireball, verify_ssl=verify_ssl) self.archiver = archiver or NOOPArchiver() self.fireball = fireball self.no_fetch = no_fetch self.goback = goback self.skip_invalid = skip_invalid self.verify_ssl = verify_ssl self.last_cache = None self.send_retries = send_retries self.send_retries_wait = send_retries_wait
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
def __init__(self, remote=REMOTE_ADDR, token=TOKEN, client='cif', user=None, feed=None): self.logger = logging.getLogger(__name__) self.logger.debug(csirtg_smrt.client.__path__[0]) self.client = load_plugin(csirtg_smrt.client.__path__[0], client)(remote, token, user=user, feed=feed)