Skip to content

Commit

Permalink
查询超时也要记录日志 (#2110)
Browse files Browse the repository at this point in the history
* 查询超时也要记录日志

* 修复通用审计中下载未记录sql信息问题

---------

Co-authored-by: 小圈圈 <[email protected]>
  • Loading branch information
woshiyanghai and hhyo committed Jun 18, 2023
1 parent 07ef383 commit a794389
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
28 changes: 15 additions & 13 deletions sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,24 @@ def query(request):
limit_num = int(query_result.affected_rows)
else:
limit_num = min(int(limit_num), int(query_result.affected_rows))
query_log = QueryLog(
username=user.username,
user_display=user.display,
db_name=db_name,
instance_name=instance.instance_name,
sqllog=sql_content,
effect_row=limit_num,
cost_time=query_result.query_time,
priv_check=priv_check,
hit_rule=query_result.mask_rule_hit,
masking=query_result.is_masked,
)
# 防止查询超时
if connection.connection and not connection.is_usable():
close_old_connections()
query_log.save()
else:
limit_num = 0
query_log = QueryLog(
username=user.username,
user_display=user.display,
db_name=db_name,
instance_name=instance.instance_name,
sqllog=sql_content,
effect_row=limit_num,
cost_time=query_result.query_time,
priv_check=priv_check,
hit_rule=query_result.mask_rule_hit,
masking=query_result.is_masked,
)
query_log.save()
except Exception as e:
logger.error(f"查询异常报错,查询语句:{sql_content}\n,错误信息:{traceback.format_exc()}")
result["status"] = 1
Expand Down
4 changes: 3 additions & 1 deletion sql/templates/sqlquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,9 @@ <h4 class="modal-title text-danger">收藏语句</h4>
for(let i=0;i<tabs.length;i++){
if(tabs[i].getAttribute("class") === "active") {
// sql内容固定隐藏绑定在第二个子元素
var extraInfo = tabs[i].children[1].innerHTML+"|"+e.length;
var instance_name = $("#instance_name").val()
var db_name =$("#db_name").val()
var extraInfo = instance_name+"/"+db_name+"|"+$(tabs[i].children[1]).attr('sql_cache')+"|"+e.length;
$.ajax({
type: "post",
url: "/audit/input/",
Expand Down

0 comments on commit a794389

Please sign in to comment.