Files
waf-platform/EdgeUser/internal/web/actions/default/httpdns/resolveLogs/index.go
2026-02-28 18:55:33 +08:00

124 lines
3.3 KiB
Go

package resolveLogs
import (
"strings"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/httpdns/httpdnsutils"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("httpdns", "resolveLogs", "")
}
func (this *IndexAction) RunGet(params struct {
ClusterId int64
AppId string
Domain string
Status string
Keyword string
}) {
httpdnsutils.AddLeftMenu(this.Parent())
if params.ClusterId > 0 {
this.Data["clusterId"] = params.ClusterId
} else {
this.Data["clusterId"] = ""
}
this.Data["appId"] = params.AppId
this.Data["domain"] = params.Domain
this.Data["status"] = params.Status
this.Data["keyword"] = params.Keyword
clusterResp, err := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.UserContext(), &pb.FindAllHTTPDNSClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
clusters := make([]map[string]interface{}, 0, len(clusterResp.GetClusters()))
clusterDomainMap := map[int64]string{}
for _, cluster := range clusterResp.GetClusters() {
serviceDomain := strings.TrimSpace(cluster.GetServiceDomain())
displayName := serviceDomain
if len(displayName) == 0 {
displayName = cluster.GetName()
}
clusters = append(clusters, map[string]interface{}{
"id": cluster.GetId(),
"name": cluster.GetName(),
"serviceDomain": serviceDomain,
"displayName": displayName,
})
clusterDomainMap[cluster.GetId()] = serviceDomain
}
this.Data["clusters"] = clusters
logResp, err := this.RPC().HTTPDNSAccessLogRPC().ListHTTPDNSAccessLogs(this.UserContext(), &pb.ListHTTPDNSAccessLogsRequest{
Day: "",
ClusterId: params.ClusterId,
NodeId: 0,
AppId: strings.TrimSpace(params.AppId),
Domain: strings.TrimSpace(params.Domain),
Status: strings.TrimSpace(params.Status),
Keyword: strings.TrimSpace(params.Keyword),
Offset: 0,
Size: 100,
})
if err != nil {
this.ErrorPage(err)
return
}
logs := make([]map[string]interface{}, 0, len(logResp.GetLogs()))
for _, item := range logResp.GetLogs() {
createdTime := ""
if item.GetCreatedAt() > 0 {
createdTime = timeutil.FormatTime("Y-m-d H:i:s", item.GetCreatedAt())
}
status := item.GetStatus()
if len(status) == 0 {
status = "failed"
}
errorCode := item.GetErrorCode()
if len(errorCode) == 0 {
errorCode = "none"
}
logs = append(logs, map[string]interface{}{
"time": createdTime,
"clusterId": item.GetClusterId(),
"serviceDomain": func() string {
serviceDomain := strings.TrimSpace(clusterDomainMap[item.GetClusterId()])
if len(serviceDomain) > 0 {
return serviceDomain
}
if len(strings.TrimSpace(item.GetClusterName())) > 0 {
return item.GetClusterName()
}
return "-"
}(),
"appName": item.GetAppName(),
"appId": item.GetAppId(),
"domain": item.GetDomain(),
"query": item.GetQtype(),
"clientIp": item.GetClientIP(),
"os": item.GetOs(),
"sdkVersion": item.GetSdkVersion(),
"ips": item.GetResultIPs(),
"status": status,
"errorCode": errorCode,
"costMs": item.GetCostMs(),
})
}
this.Data["resolveLogs"] = logs
this.Show()
}