-
Notifications
You must be signed in to change notification settings - Fork 4
/
accessLogsPopup.go
70 lines (59 loc) · 1.7 KB
/
accessLogsPopup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type AccessLogsPopupAction struct {
actionutils.ParentAction
}
func (this *AccessLogsPopupAction) Init() {
this.Nav("", "", "")
}
func (this *AccessLogsPopupAction) RunGet(params struct {
ItemId int64
}) {
itemResp, err := this.RPC().IPItemRPC().FindEnabledIPItem(this.AdminContext(), &pb.FindEnabledIPItemRequest{IpItemId: params.ItemId})
if err != nil {
this.ErrorPage(err)
return
}
var item = itemResp.IpItem
if item == nil {
this.NotFound("ipItem", params.ItemId)
return
}
this.Data["ipFrom"] = item.IpFrom
this.Data["ipTo"] = item.IpTo
// 多找几个Partition
var day = timeutil.FormatTime("Ymd", item.CreatedAt)
partitionsResp, err := this.RPC().HTTPAccessLogRPC().FindHTTPAccessLogPartitions(this.AdminContext(), &pb.FindHTTPAccessLogPartitionsRequest{Day: day})
if err != nil {
this.ErrorPage(err)
return
}
var hasAccessLogs = false
for _, partition := range partitionsResp.ReversePartitions {
accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: partition,
Day: day,
Keyword: "ip:" + item.IpFrom + "," + item.IpTo,
Size: 20,
})
if err != nil {
this.ErrorPage(err)
return
}
var accessLogs = accessLogsResp.HttpAccessLogs
if len(accessLogs) > 0 {
this.Data["accessLogs"] = accessLogs
hasAccessLogs = true
break
}
}
if !hasAccessLogs {
this.Data["accessLogs"] = []interface{}{}
}
this.Show()
}