Skip to content

Commit

Permalink
webhook功能优化
Browse files Browse the repository at this point in the history
1、webhook仅debug模式进程内发送HTTP,其他模式使用日志采集
2、删除默认代理线程
3、web页面渲染功能优化
  • Loading branch information
xiyoo0812 committed Oct 7, 2023
1 parent ffd8ea4 commit 41d1fea
Show file tree
Hide file tree
Showing 30 changed files with 733 additions and 780 deletions.
26 changes: 11 additions & 15 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ max_cyclomatic_complexity = 13
max_code_line_length = 160
max_comment_line_length = 160
exclude_files = {
"script/luabt/*.*",
"script/luaoop/*.*",
"script/luabt/luaoop/*.*",
"script/luabt/LICENSE",
"script/luaoop/LICENSE",
"script/luabt/luaoop/LICENSE",
"server/robot/accord/page/*",
"extend/lmake/share.lua"
"extend/lmake/share.lua",
"server/robot/accord/page/*"
}
include_files = {
"script/*",
"server/*",
"worker/*",
"bin/proto/*.lua",
"tools/encrypt/*",
"tools/excel2lua/*",
"script/*.lua",
"server/*.lua",
"script/*/*.lua",
"server/*/*.lua",
"script/*/*/*.lua",
"server/*/*/*.lua",
"script/*/*/*/*.lua",
"server/*/*/*/*.lua",
"extend/lmake/*.lua",
"extend/lmake/ltemplate/*.lua",
"tools/*/*.lua",
}
ignore = {"212", "213", "512"}

2 changes: 1 addition & 1 deletion bin/database.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set_env("QUANTA_MONGO_URLS", [[
]])
--redis
set_env("QUANTA_REDIS_URLS", [[
redis://root:123456@127.0.0.1:6379;
redis://root:123456@10.96.8.100:6379;
]])
--mysql
set_env("QUANTA_MYSQL_URLS", [[
Expand Down
9 changes: 6 additions & 3 deletions bin/share.conf
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ set_env("QUANTA_DB_CACHE_MAX", "4096")
--每帧落地最大数量
set_env("QUANTA_DB_CACHE_FLUSH", "10")

--webhook日志等级
--webhook设置
-----------------------------------------------------
set_env("QUANTA_WEBHOOK_LVL", "6")
--log: 日志采集
--http:http发送
set_env("QUANTA_WEBHOOK_MODE", "log")
--webhook地址设置
--set_env("QUANTA_LARK_URL", "https://open.feishu.cn/open-apis/bot/v2/hook/9a6565bf-51b4-48ab-80f0-64caf4d58ab8")
--set_env("QUANTA_DING_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a4c64781-adad-4ddc-a615-6bc232ce71ef")
--set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ee6d97c5-477d-436f-83db-dd5361a5e8bd")
set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d7cd918c-f608-4762-87af-bb8c7fc51074")

--graylog配置
-----------------------------------------------------
Expand Down
61 changes: 43 additions & 18 deletions extend/lmake/ltemplate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ local function render(content, env)
return nil, chunk
end

--导出文件模板
--根据配置导出文件模板
--tpl_f: 文件模板
--tpl_out_f: 输出文件
--tpl_env: 环境变量
--tpl_var_f: 环境变量文件
local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f)
local function render_file(tpl_f, tpl_out_f, tpl_env)
if not tpl_f or not tpl_out_f or not tpl_env then
error("render template file params error!")
return
Expand All @@ -182,19 +181,6 @@ local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f)
tpl_env.NAME = tpl_f
local content = template_file:read("*all")
template_file:close()
if tpl_var_f then
setmetatable(tpl_env, { __index = function(t, k) return _G[k] end })
local func, err = loadfile(tpl_var_f, "bt", tpl_env)
if not func then
error(sformat("open template variable file %s failed :%s", tpl_var_f, err))
return
end
local ok, res = pcall(func)
if not ok then
error(sformat("load template variable file %s failed :%s", tpl_var_f, res))
return
end
end
local out_file = iopen(tpl_out_f, "w")
if not out_file then
error(sformat("open template out file %s failed!", tpl_out_f))
Expand All @@ -214,13 +200,52 @@ local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f)
print(sformat("render template file %s to %s success!", tpl_f, tpl_out_f))
end

--输入参数
local arg_num = select("#", ...)

--工具用法
--tpl_f: 模板文件路径
--tpl_out_f:输出文件路径
--tpl_var_f:环境变量配置文件
if select("#", ...) == 3 then
if arg_num == 3 then
local tpl_env = {}
local tpl_f, tpl_out_f, tpl_var_f = select(1, ...)
render_file(tpl_f, tpl_out_f, {}, tpl_var_f)
if tpl_var_f then
setmetatable(tpl_env, { __index = function(t, k) return _G[k] end })
local func, err = loadfile(tpl_var_f, "bt", tpl_env)
if not func then
error(sformat("open template variable file %s failed :%s", tpl_var_f, err))
return
end
local ok, res = pcall(func)
if not ok then
error(sformat("load template variable file %s failed :%s", tpl_var_f, res))
return
end
end
render_file(tpl_f, tpl_out_f, tpl_env)
end

--工具用法
--tpl_f: 模板文件路径
--tpl_out_f:输出文件路径
--key:文件索引, filename:文件名, ...
if arg_num > 3 then
local tpl_env = {}
local args = { ... }
local filenum = (arg_num - 2) // 2
for i = 1, filenum do
local key = args[2 + i * 2 - 1]
local filename = args[2 + i * 2]
local args_file = iopen(filename, "r")
if not args_file then
error(sformat("open args file %s failed!", filename))
return
end
tpl_env[key] = args_file:read("*all")
args_file:close()
end
render_file(args[1], args[2], tpl_env)
end

return {
Expand Down
97 changes: 0 additions & 97 deletions script/agent/proxy_agent.lua

This file was deleted.

23 changes: 9 additions & 14 deletions script/basic/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ local LOG_LEVEL = log.LOG_LEVEL

local title = quanta.title
local monitors = _ENV.monitors or {}
local dispatch = false

logger = {}
logfeature = {}
Expand All @@ -36,8 +35,8 @@ function logger.daemon(daemon)
log.daemon(daemon)
end

function logger.add_monitor(monitor, lvl)
monitors[monitor] = lvl
function logger.add_monitor(monitor)
monitors[monitor] = true
end

function logger.remove_monitor(monitor)
Expand Down Expand Up @@ -73,7 +72,11 @@ local function logger_output(flag, feature, lvl, lvl_name, fmt, ...)
lprint(LOG_LEVEL.WARN, 0, title, feature, wfmt, lvl_name, msg, info.short_src, info.linedefined)
return
end
return msg
if msg then
for monitor in pairs(monitors) do
monitor:dispatch_log(msg, lvl_name)
end
end
end

local LOG_LEVEL_OPTIONS = {
Expand All @@ -84,19 +87,11 @@ local LOG_LEVEL_OPTIONS = {
[LOG_LEVEL.FATAL] = { "fatal", 0x01 },
[LOG_LEVEL.DUMP] = { "dump", 0x01 | 0x02 },
}

for lvl, conf in pairs(LOG_LEVEL_OPTIONS) do
local lvl_name, flag = tunpack(conf)
logger[lvl_name] = function(fmt, ...)
local msg = logger_output(flag, "", lvl, lvl_name, fmt, ...)
if msg and (not dispatch) then
dispatch = true
pcall(function ()
for monitor in pairs(monitors) do
monitor:dispatch_log(msg, lvl_name)
end
end)
dispatch = false
end
logger_output(flag, "", lvl, lvl_name, fmt, ...)
end
end

Expand Down
4 changes: 2 additions & 2 deletions script/constant.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
local KernCode = enum("KernCode", 0)
KernCode.SUCCESS = 0 --成功
KernCode.FAILED = 1 --系统错误,请重试
KernCode.PARAM_ERROR = 2 --业务参数错误
KernCode.TOO_FAST = 3 --操作太快
KernCode.TOO_FAST = 2 --操作太快
KernCode.PARAM_ERROR = 3 --业务参数错误
KernCode.UPHOLD = 4 --服务维护
KernCode.RPC_FAILED = 5 --RPC调用失败
KernCode.OPERATOR_SELF = 6 --不能对自己操作
Expand Down
Loading

0 comments on commit 41d1fea

Please sign in to comment.