Ejemplo n.º 1
0
def main(**kwargs):
    if kwargs['verbose'] > 1:
        loglevel = logging.DEBUG
    elif kwargs['verbose'] > 0:
        loglevel = logging.INFO
    else:
        loglevel = logging.WARNING
    path = 'logging.yaml'
    if os.path.exists(path):
        with open(path, 'rt') as config_file:
            config = yaml.safe_load(config_file.read())
            logging.config.dictConfig(config)

    logging.getLogger().setLevel(level=loglevel)
    logger = logging.getLogger(__name__)
    config = hemApp.load_config(kwargs['config'])

    metrics = hemApp.initialise_metrics(config['metrics'])

    if not 'settings' in config:
        config['settings'] = {}
    frequency = config['settings'].get('frequency', 30)
    logger.info("Frequency is {}".format(frequency))
    logger.info(config)
    storage = hemApp.HemStore()
    while True:
        duration = hemApp.run_tests(config, metrics, storage)
        try:
            if int(frequency - duration) > 0:
                time.sleep(int(frequency - duration))
        except IOError:
            logger.info("Too quick!")
Ejemplo n.º 2
0
def test_check_jwt_invoke():
    hemstore = hemApp.HemStore()
    with requests_mock.mock() as m:
        m.get('https://1.1.1.1/', text="")
        m.post('https://1.1.1.1/jwt', text='{"jwt":"token"}')
        test = {
            'path': '/',
            'secure': True,
            'verify': True,
            'auth': {
                'type': 'jwt',
                'url': 'https://1.1.1.1/jwt',
                'field': 'jwt'
            }
        }
        check = hemApp.Check('test', test, storage=hemstore)
        results = check.test_list(["1.1.1.1"])
        (response, timing) = results[0]
        assert results is not None
        assert response == 200
        assert type(timing) is datetime.timedelta