mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-10 16:30:24 +08:00
服务日志:增加区域信息
This commit is contained in:
@@ -3,6 +3,7 @@ package log
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -34,6 +35,8 @@ func (this *HistoryAction) RunGet(params struct {
|
||||
this.Data["hasError"] = params.HasError
|
||||
|
||||
day := params.Day
|
||||
ipList := []string{}
|
||||
|
||||
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
||||
day = strings.ReplaceAll(day, "-", "")
|
||||
size := int64(10)
|
||||
@@ -56,6 +59,13 @@ func (this *HistoryAction) RunGet(params struct {
|
||||
this.Data["accessLogs"] = []interface{}{}
|
||||
} else {
|
||||
this.Data["accessLogs"] = resp.AccessLogs
|
||||
for _, accessLog := range resp.AccessLogs {
|
||||
if len(accessLog.RemoteAddr) > 0 {
|
||||
if !lists.ContainsString(ipList, accessLog.RemoteAddr) {
|
||||
ipList = append(ipList, accessLog.RemoteAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["hasMore"] = resp.HasMore
|
||||
this.Data["nextRequestId"] = resp.RequestId
|
||||
@@ -83,5 +93,21 @@ func (this *HistoryAction) RunGet(params struct {
|
||||
}
|
||||
}
|
||||
|
||||
// 根据IP查询区域
|
||||
regionMap := map[string]string{} // ip => region
|
||||
if len(ipList) > 0 {
|
||||
resp, err := this.RPC().IPLibraryRPC().LookupIPRegions(this.AdminContext(), &pb.LookupIPRegionsRequest{IpList: ipList})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.IpRegionMap != nil {
|
||||
for ip, region := range resp.IpRegionMap {
|
||||
regionMap[ip] = region.Summary
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Data["regions"] = regionMap
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user