Fix http reporting (#51)
* Update crowdsec.lua * distinct timeouts for stream and live mode --------- Co-authored-by: bui <thibault@crowdsec.net>
This commit is contained in:
parent
926de93ce2
commit
718ebae9e1
2 changed files with 9 additions and 4 deletions
|
@ -131,7 +131,11 @@ end
|
|||
|
||||
local function get_remediation_http_request(link)
|
||||
local httpc = http.new()
|
||||
httpc:set_timeout(runtime.conf['REQUEST_TIMEOUT'])
|
||||
if runtime.conf['MODE'] == 'stream' then
|
||||
httpc:set_timeout(runtime.conf['STREAM_REQUEST_TIMEOUT'])
|
||||
else
|
||||
httpc:set_timeout(runtime.conf['REQUEST_TIMEOUT'])
|
||||
end
|
||||
local res, err = httpc:request_uri(link, {
|
||||
method = "GET",
|
||||
headers = {
|
||||
|
@ -264,10 +268,10 @@ local function stream_query(premature)
|
|||
local link = runtime.conf["API_URL"] .. "/v1/decisions/stream?startup=" .. tostring(is_startup)
|
||||
local res, err = get_remediation_http_request(link)
|
||||
if not res then
|
||||
local ok, err = ngx.timer.at(runtime.conf["UPDATE_FREQUENCY"], stream_query)
|
||||
local ok, err2 = ngx.timer.at(runtime.conf["UPDATE_FREQUENCY"], stream_query)
|
||||
if not ok then
|
||||
set_refreshing(false)
|
||||
error("Failed to create the timer: " .. (err or "unknown"))
|
||||
error("Failed to create the timer: " .. (err2 or "unknown"))
|
||||
end
|
||||
set_refreshing(false)
|
||||
error("request failed: ".. err)
|
||||
|
|
|
@ -40,12 +40,13 @@ function config.loadConfig(file)
|
|||
end
|
||||
local conf = {}
|
||||
local valid_params = {'ENABLED','API_URL', 'API_KEY', 'BOUNCING_ON_TYPE', 'MODE', 'SECRET_KEY', 'SITE_KEY', 'BAN_TEMPLATE_PATH' ,'CAPTCHA_TEMPLATE_PATH', 'REDIRECT_LOCATION', 'RET_CODE', 'EXCLUDE_LOCATION', 'FALLBACK_REMEDIATION', 'CAPTCHA_PROVIDER', 'APPSEC_URL', 'APPSEC_FAILURE_ACTION', 'ALWAYS_SEND_TO_APPSEC', 'SSL_VERIFY'}
|
||||
local valid_int_params = {'CACHE_EXPIRATION', 'CACHE_SIZE', 'REQUEST_TIMEOUT', 'UPDATE_FREQUENCY', 'CAPTCHA_EXPIRATION', 'APPSEC_CONNECT_TIMEOUT', 'APPSEC_SEND_TIMEOUT', 'APPSEC_PROCESS_TIMEOUT'}
|
||||
local valid_int_params = {'CACHE_EXPIRATION', 'CACHE_SIZE', 'REQUEST_TIMEOUT', 'UPDATE_FREQUENCY', 'CAPTCHA_EXPIRATION', 'APPSEC_CONNECT_TIMEOUT', 'APPSEC_SEND_TIMEOUT', 'APPSEC_PROCESS_TIMEOUT', 'STREAM_REQUEST_TIMEOUT'}
|
||||
local valid_bouncing_on_type_values = {'ban', 'captcha', 'all'}
|
||||
local valid_truefalse_values = {'false', 'true'}
|
||||
local default_values = {
|
||||
['ENABLED'] = "true",
|
||||
['REQUEST_TIMEOUT'] = 0.2,
|
||||
['STREAM_REQUEST_TIMEOUT'] = 15,
|
||||
['BOUNCING_ON_TYPE'] = "ban",
|
||||
['MODE'] = "stream",
|
||||
['UPDATE_FREQUENCY'] = 10,
|
||||
|
|
Loading…
Add table
Reference in a new issue