def __init__(self, *args, **kwargs): host = convert_variable_to_env_setting(kwargs.get('host')) prefix = convert_variable_to_env_setting(kwargs.get('prefix')) try: port = int(convert_variable_to_env_setting(kwargs.get('port'))) except: port = None logger.info("Attempting to configure StatsDAnalytics with %s:%s:%s" % (host, port, prefix)) if host is not None and prefix is not None and port is not None and not host.startswith("$") and not prefix.startswith("$"): self.client = statsd.StatsClient(host, port, prefix=prefix) logger.info("Configured StatsDAnalytics with %s:%s:%s" % (host, port, prefix)) else: self.client = None logger.warning("StatsDAnalytics NOT configured, incomplete configuration: %s:%s:%s" % (host, port, prefix))
def __init__(self, *args, **kwargs): self.config = kwargs.get('config', {}) self.ttl = self.config.get('ttl', 300) super(RedisAPICacheStore, self).__init__(*args, **kwargs) if self.config.get("use_settings", False): redis_settings = settings.CACHE_REDIS else: redis_settings = self.config.get('parameters') host = convert_variable_to_env_setting(redis_settings.get('host', "localhost")) port = redis_settings.get('port', 6379) db = redis_settings.get('db', 0) pw = redis_settings.get('password', None) timeout = redis_settings.get('timeout', .3) self.redis = StrictRedis(host=host, port=port, db=db, password=pw, socket_timeout=timeout) if self.config.get('use_settings'): logger.info("Configuring Face/Off API cache with REDIS using settings.py") else: logger.info("Configuring Face/Off API cache with REDIS using JSON settings") logger.info("Face/off API cache settings: redis://%s:%s/%s with ttl %s" % (host, port, db, self.ttl))
def __init__(self, **kwargs): super(RedisHealthCheckStorage, self).__init__(**kwargs) redis_conf = kwargs.get('redis') use_settings = False if redis_conf.get('use_settings', False): use_settings = True redis_conf = settings.HEALTH_CHECK_REDIS self.redis = StrictRedis(host=convert_variable_to_env_setting(redis_conf.get('host', 'localhost')), port=redis_conf.get('port'), db=redis_conf.get('db'), password=redis_conf.get('password'), socket_timeout=.3) if use_settings: logger.info("Configuring Face/Off healthcheck store with REDIS using settings.py") else: logger.info("Configuring Face/Off healthcheck store with REDIS using JSON settings") logger.info("Face/Off with REDIS healthcheck settings: redis://%s:%s/%s" % (redis_conf.get('host'), redis_conf.get('port'), redis_conf.get('db')))
def init_backend_servers(cls, **initkwargs): server = initkwargs.get('cfg').get('server') rotation_policy_clazz = server.get('rotation_policy', "proxy.rotations.RoundRobin") RotationPolicyClass = load_class_from_name(rotation_policy_clazz) actual_servers = [] for x in server.get('servers'): actual_servers.append(convert_variable_to_env_setting(x)) initkwargs['rotation_policy'] = RotationPolicyClass(actual_servers) return initkwargs
def healthcheck(self, server=None, **kwargs): if server is None: server = convert_variable_to_env_setting(self.server) try: basic_auth_params = parse_basic_auth(server) if "login" in basic_auth_params: resp = requests.head(server, auth=(basic_auth_params['login'], basic_auth_params['password'])) else: resp = requests.head(server) if resp.ok: return HealthCheckResponse(server=server, name=self.name) else: health_check_response = HealthCheckResponse(name=self.name, server=server, code=resp.status_code, passed=False) return health_check_response except ConnectionError as e: health_check_response = HealthCheckResponse(code=999, passed=False) health_check_response.descriptive_message = "Connection Refused" health_check_response.technical_message = "connection refused" health_check_response.server = server health_check_response.name = self.name return health_check_response
def __init__(self, server=None, name=None): self.server = convert_variable_to_env_setting(server) self.name = name