package resolveLogs import ( "strings" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" 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 NodeId 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"] = "" } if params.NodeId > 0 { this.Data["nodeId"] = params.NodeId } else { this.Data["nodeId"] = "" } 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.AdminContext(), &pb.FindAllHTTPDNSClustersRequest{}) if err != nil { this.ErrorPage(err) return } clusters := make([]map[string]interface{}, 0, len(clusterResp.GetClusters())) nodes := make([]map[string]interface{}, 0) for _, cluster := range clusterResp.GetClusters() { clusters = append(clusters, map[string]interface{}{ "id": cluster.GetId(), "name": cluster.GetName(), }) nodeResp, err := this.RPC().HTTPDNSNodeRPC().ListHTTPDNSNodes(this.AdminContext(), &pb.ListHTTPDNSNodesRequest{ ClusterId: cluster.GetId(), }) if err != nil { this.ErrorPage(err) return } for _, node := range nodeResp.GetNodes() { nodes = append(nodes, map[string]interface{}{ "id": node.GetId(), "clusterId": node.GetClusterId(), "name": node.GetName(), }) } } this.Data["clusters"] = clusters this.Data["nodes"] = nodes logResp, err := this.RPC().HTTPDNSAccessLogRPC().ListHTTPDNSAccessLogs(this.AdminContext(), &pb.ListHTTPDNSAccessLogsRequest{ Day: "", ClusterId: params.ClusterId, NodeId: params.NodeId, 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(), "clusterName": item.GetClusterName(), "nodeId": item.GetNodeId(), "nodeName": item.GetNodeName(), "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() }