mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-01-01 16:27:05 +08:00
浏览访问日志时自动用点符号标记有数据的分表
This commit is contained in:
67
internal/web/actions/default/servers/logs/hasLogs.go
Normal file
67
internal/web/actions/default/servers/logs/hasLogs.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package logs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HasLogsAction 检查某个分区是否有日志
|
||||
type HasLogsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *HasLogsAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
NodeId int64
|
||||
Day string
|
||||
Hour string
|
||||
Keyword string
|
||||
Ip string
|
||||
Domain string
|
||||
HasError int
|
||||
HasWAF int
|
||||
Partition int32 `default:"-1"`
|
||||
|
||||
RequestId string
|
||||
ServerId int64
|
||||
}) {
|
||||
if len(params.Day) == 0 {
|
||||
params.Day = timeutil.Format("Y-m-d")
|
||||
}
|
||||
|
||||
var day = params.Day
|
||||
|
||||
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
||||
day = strings.ReplaceAll(day, "-", "")
|
||||
}
|
||||
|
||||
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||
Partition: params.Partition,
|
||||
RequestId: params.RequestId,
|
||||
NodeClusterId: params.ClusterId,
|
||||
NodeId: params.NodeId,
|
||||
ServerId: params.ServerId,
|
||||
HasError: params.HasError > 0,
|
||||
HasFirewallPolicy: params.HasWAF > 0,
|
||||
Day: day,
|
||||
HourFrom: params.Hour,
|
||||
HourTo: params.Hour,
|
||||
Keyword: params.Keyword,
|
||||
Ip: params.Ip,
|
||||
Domain: params.Domain,
|
||||
Size: 1,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["hasLogs"] = len(resp.HttpAccessLogs) > 0
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -18,6 +18,7 @@ func init() {
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/settings", new(SettingsAction)).
|
||||
Post("/partitionData", new(PartitionDataAction)).
|
||||
Post("/hasLogs", new(HasLogsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user