コード例 #1
0
ファイル: util_.py プロジェクト: jpalardy1752/crits-adapter
 def run(self):
     '''daemon main logic'''
     while True:
         enabled_crits_sites = list()
         enabled_edge_sites = list()
         for c_site in self.config['crits']['sites'].keys():
             if self.config['crits']['sites'][c_site]['enabled']:
                 enabled_crits_sites.append(c_site)
         for e_site in self.config['edge']['sites'].keys():
             if self.config['edge']['sites'][e_site]['enabled']:
                 enabled_edge_sites.append(e_site)
         # sync crits to edge
         for c_site in enabled_crits_sites:
             for e_site in enabled_edge_sites:
                 # check if (and when) we synced src and dest...
                 now = nowutc()
                 last_run = self.db.get_last_sync(src=c_site,
                                                  dest=e_site,
                                                  direction='c2e')
                 last_run = last_run.replace(tzinfo=pytz.utc)
                 poll_interval = self.get_poll_interval(c_site)
                 if now >= \
                    last_run + datetime.timedelta(seconds=poll_interval):
                     self.logger.info('initiating crits=>edge sync between '
                                      '%s and %s' % (c_site, e_site))
                     completed_run = crits_.crits2edge(self.config, c_site,
                                                       e_site, daemon=True,
                                                       now=now,
                                                       last_run=last_run)
                     if completed_run:
                         self.db.set_last_sync(src=c_site,
                                               dest=e_site,
                                               direction='c2e',
                                               timestamp=completed_run)
         # sync edge to crits
         for e_site in enabled_edge_sites:
             for c_site in enabled_crits_sites:
                 now = nowutc()
                 last_run = self.db.get_last_sync(src=e_site,
                                                  dest=c_site,
                                                  direction='e2c')
                 last_run = last_run.replace(tzinfo=pytz.utc)
                 poll_interval = self.get_poll_interval(e_site)
                 if now >= \
                    last_run + datetime.timedelta(seconds=poll_interval):
                     self.logger.info('initiating edge=>crits sync between '
                                      '%s and %s' % (e_site, c_site))
                     completed_run = edge_.edge2crits(self.config, e_site,
                                                      c_site, daemon=True,
                                                      now=now,
                                                      last_run=last_run)
                     if completed_run:
                         self.db.set_last_sync(src=e_site,
                                               dest=c_site,
                                               direction='e2c',
                                               timestamp=completed_run)
         time.sleep(1)
コード例 #2
0
def main():
    args = docopt(__doc__, version=__version__)
    config = util_.parse_config(args['--config'])
    config['config_file'] = args['--config']
    logger = log_.setup_logging(config)
    config['logger'] = logger
    db = db_.DB(config)
    config['db'] = db
    config['daemon']['app_path'] = app_path
    if args['--c2e']:
        if args['--src'] in config['crits']['sites'].keys() \
           and args['--dest'] in config['edge']['sites'].keys():
            logger.info('initiating crits=>edge sync between %s and %s'
                        % (args['--src'], args['--dest']))
            crits2edge(config, args['--src'], args['--dest'])
    elif args['--e2c']:
        if args['--src'] in config['edge']['sites'].keys() and \
           args['--dest'] in config['crits']['sites'].keys():
            logger.info('initiating edge=>crits sync between %s and %s'
                        % (args['--src'], args['--dest']))
            edge2crits(config, args['--src'], args['--dest'])