Exemplo n.º 1
0
 def test_parse_cli_args_no_config(self):
     # Short option.
     args = util.parse_cli(['-c'])
     self.assertEqual(args.config, [])
     # Long option.
     args = util.parse_cli(['--config'])
     self.assertEqual(args.config, [])
Exemplo n.º 2
0
 def test_parse_cli_args_config(self):
     # Short option.
     args = util.parse_cli(['-c', 'foo.yaml', 'bar.yaml'])
     self.assertEqual(args.config, ['foo.yaml', 'bar.yaml'])
     # Long option.
     args = util.parse_cli(['--config', 'baz.yaml', 'qux.yaml'])
     self.assertEqual(args.config, ['baz.yaml', 'qux.yaml'])
Exemplo n.º 3
0
def main():
    """Run the framework based on the schedule."""
    # Configure the logger as the first thing as per the base
    # configuration. We need this to be the first thing, so that
    # we can see the messages logged by util.load_config().
    logging.config.dictConfig(baseconfig.config_dict['logger'])
    _log.info('Cloudmarker %s', cloudmarker.__version__)

    # Parse the command line arguments and handle the options that can
    # be handled immediately.
    args = util.parse_cli()
    if args.print_base_config:
        print(baseconfig.config_yaml.strip())
        return

    # Now load user's configuration files.
    config = util.load_config(args.config)

    # Then configure the logger once again to honour any logger
    # configuration defined in the user's configuration files.
    logging.config.dictConfig(config['logger'])

    # Finally, run the audits, either right now or as per a schedule,
    # depending on the command line options.
    if args.now:
        _log.info('Starting job now')
        job(config)
    else:
        _log.info('Scheduled to run job everyday at %s', config['schedule'])
        schedule.every().day.at(config['schedule']).do(job, config)
        while True:
            schedule.run_pending()
            time.sleep(60)
Exemplo n.º 4
0
 def test_parse_cli_args_none(self):
     args = util.parse_cli([])
     self.assertEqual(args.config, [
         '/etc/cloudmarker.yaml',
         '~/.cloudmarker.yaml',
         '~/cloudmarker.yaml',
         'cloudmarker.yaml'
     ])
Exemplo n.º 5
0
def main():
    """Run the framework based on the schedule."""
    args = util.parse_cli()
    config = util.load_config(args.config)

    logging.config.dictConfig(config['logger'])

    # Run the audits according to the schedule set in the configuration if the
    # 'force' flag is not set in the command line.
    if args.force:
        _log.info('Starting job now')
        job(config)
    else:
        _log.info('Scheduled to run job everyday at %s', config['schedule'])
        schedule.every().day.at(config['schedule']).do(job, config)
        while True:
            schedule.run_pending()
            time.sleep(60)
Exemplo n.º 6
0
def main():
    """Run the framework."""
    args = util.parse_cli()
    config = util.load_config(args.config)

    logging.config.dictConfig(config['logger'])

    # Create an audit object for each audit configured to be run.
    audits = []
    for audit_name in config['run']:
        audits.append(Audit(audit_name, config))

    # Start all audits.
    for audit in audits:
        audit.start()

    # Wait for all audits to terminate.
    for audit in audits:
        audit.join()
Exemplo n.º 7
0
 def test_parse_cli_args_none(self):
     args = util.parse_cli([])
     self.assertEqual(args.config, ['config.base.yaml', 'config.yaml'])