-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bw - init work on reason data and fix nil REDIS_SENTINEL_HOSTS for se…
…ssions
- Loading branch information
1 parent
68b3d67
commit e108d3f
Showing
16 changed files
with
221 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ server { | |
|
||
# variables | ||
set $reason ''; | ||
set $reason_data = ''; | ||
set $ctx_ref ''; | ||
|
||
# include LUA files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,83 @@ | ||
log_by_lua_block { | ||
local class = require "middleclass" | ||
local clogger = require "bunkerweb.logger" | ||
local helpers = require "bunkerweb.helpers" | ||
local cdatastore = require "bunkerweb.datastore" | ||
local utils = require "bunkerweb.utils" | ||
local cjson = require "cjson" | ||
|
||
local ngx = ngx | ||
local ERR = ngx.ERR | ||
local INFO = ngx.INFO | ||
local fill_ctx = helpers.fill_ctx | ||
local get_reason = utils.get_reason | ||
local require_plugin = helpers.require_plugin | ||
local new_plugin = helpers.new_plugin | ||
local call_plugin = helpers.call_plugin | ||
local tostring = tostring | ||
local encode = cjson.encode | ||
|
||
-- Start log phase | ||
local logger = clogger:new("LOG") | ||
local datastore = cdatastore:new() | ||
logger:log(ngx.INFO, "log phase started") | ||
logger:log(INFO, "log phase started") | ||
|
||
-- Fill ctx | ||
logger:log(ngx.INFO, "filling ngx.ctx ...") | ||
local ok, ret, errors, ctx = helpers.fill_ctx() | ||
logger:log(INFO, "filling ngx.ctx ...") | ||
local ok, ret, errors, ctx = fill_ctx() | ||
if not ok then | ||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret) | ||
logger:log(ERR, "fill_ctx() failed : " .. ret) | ||
elseif errors then | ||
for i, error in ipairs(errors) do | ||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error) | ||
logger:log(ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error) | ||
end | ||
end | ||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")") | ||
logger:log(INFO, "ngx.ctx filled (ret = " .. ret .. ")") | ||
|
||
-- Get plugins order | ||
local order, err = datastore:get("plugins_order", true) | ||
if not order then | ||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err) | ||
logger:log(ERR, "can't get plugins order from datastore : " .. err) | ||
return | ||
end | ||
|
||
-- Call log_stream() methods | ||
logger:log(ngx.INFO, "calling log_stream() methods of plugins ...") | ||
logger:log(INFO, "calling log_stream() methods of plugins ...") | ||
for i, plugin_id in ipairs(order.log_stream) do | ||
-- Require call | ||
local plugin_lua, err = helpers.require_plugin(plugin_id) | ||
local plugin_lua, err = require_plugin(plugin_id) | ||
if plugin_lua == false then | ||
logger:log(ngx.ERR, err) | ||
logger:log(ERR, err) | ||
elseif plugin_lua == nil then | ||
logger:log(ngx.INFO, err) | ||
logger:log(INFO, err) | ||
else | ||
-- Check if plugin has log_stream method | ||
if plugin_lua.log_stream ~= nil then | ||
-- New call | ||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx) | ||
local ok, plugin_obj = new_plugin(plugin_lua, ctx) | ||
if not ok then | ||
logger:log(ngx.ERR, plugin_obj) | ||
logger:log(ERR, plugin_obj) | ||
else | ||
local ok, ret = helpers.call_plugin(plugin_obj, "log_stream") | ||
local ok, ret = call_plugin(plugin_obj, "log_stream") | ||
if not ok then | ||
logger:log(ngx.ERR, ret) | ||
logger:log(ERR, ret) | ||
elseif not ret.ret then | ||
logger:log(ngx.ERR, plugin_id .. ":log_stream() call failed : " .. ret.msg) | ||
logger:log(ERR, plugin_id .. ":log_stream() call failed : " .. ret.msg) | ||
else | ||
logger:log(ngx.INFO, plugin_id .. ":log_stream() call successful : " .. ret.msg) | ||
logger:log(INFO, plugin_id .. ":log_stream() call successful : " .. ret.msg) | ||
end | ||
end | ||
else | ||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method log_stream() is not defined") | ||
logger:log(INFO, "skipped execution of " .. plugin_id .. " because method log_stream() is not defined") | ||
end | ||
end | ||
end | ||
logger:log(ngx.INFO, "called log_stream() methods of plugins") | ||
logger:log(INFO, "called log_stream() methods of plugins") | ||
|
||
-- Display reason at info level | ||
if ctx.bw.reason then | ||
logger:log(ngx.INFO, "client was denied with reason : " .. ctx.bw.reason) | ||
local reason, reason_data = get_reason(ctx) | ||
if reason then | ||
logger:log(INFO, "client was denied with reason " .. reason .. " and data = " .. encode(reason_data)) | ||
end | ||
|
||
logger:log(ngx.INFO, "log phase ended") | ||
logger:log(INFO, "log phase ended") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.