From 718ebae9e1f90342a34f5c2854839cb1789fc025 Mon Sep 17 00:00:00 2001 From: Laurence Jones Date: Thu, 4 Jan 2024 10:39:49 +0000 Subject: [PATCH] Fix http reporting (#51) * Update crowdsec.lua * distinct timeouts for stream and live mode --------- Co-authored-by: bui --- lib/crowdsec.lua | 10 +++++++--- lib/plugins/crowdsec/config.lua | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/crowdsec.lua b/lib/crowdsec.lua index 462851c..1c4d683 100644 --- a/lib/crowdsec.lua +++ b/lib/crowdsec.lua @@ -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) diff --git a/lib/plugins/crowdsec/config.lua b/lib/plugins/crowdsec/config.lua index 89d8e63..98ae404 100644 --- a/lib/plugins/crowdsec/config.lua +++ b/lib/plugins/crowdsec/config.lua @@ -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,