mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-11 22:00:27 +08:00
WAF全局看板中拦截类型只显示当天的统计/合并同名规则分组统计
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -158,10 +159,14 @@ func (this *FirewallService) ComposeFirewallGlobalBoard(ctx context.Context, req
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 规则分组
|
// 规则分组
|
||||||
groupStats, err := stats.SharedServerHTTPFirewallDailyStatDAO.GroupDailyCount(tx, 0, 0, dayFrom, day, 0, 10)
|
var today = timeutil.Format("Ymd")
|
||||||
|
groupStats, err := stats.SharedServerHTTPFirewallDailyStatDAO.GroupDailyCount(tx, 0, 0, today, today, 0, 20)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 合并同名
|
||||||
|
var groupNamedStatsMap = map[string]*stats.ServerHTTPFirewallDailyStat{} // name => *ServerHTTPFirewallDailyStat
|
||||||
for _, stat := range groupStats {
|
for _, stat := range groupStats {
|
||||||
ruleGroupName, err := models.SharedHTTPFirewallRuleGroupDAO.FindHTTPFirewallRuleGroupName(tx, int64(stat.HttpFirewallRuleGroupId))
|
ruleGroupName, err := models.SharedHTTPFirewallRuleGroupDAO.FindHTTPFirewallRuleGroupName(tx, int64(stat.HttpFirewallRuleGroupId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -171,11 +176,26 @@ func (this *FirewallService) ComposeFirewallGlobalBoard(ctx context.Context, req
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namedStat, ok := groupNamedStatsMap[ruleGroupName]
|
||||||
|
if ok {
|
||||||
|
namedStat.Count += stat.Count
|
||||||
|
} else {
|
||||||
|
groupNamedStatsMap[ruleGroupName] = stat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ruleGroupName, stat := range groupNamedStatsMap {
|
||||||
result.HttpFirewallRuleGroups = append(result.HttpFirewallRuleGroups, &pb.ComposeFirewallGlobalBoardResponse_HTTPFirewallRuleGroupStat{
|
result.HttpFirewallRuleGroups = append(result.HttpFirewallRuleGroups, &pb.ComposeFirewallGlobalBoardResponse_HTTPFirewallRuleGroupStat{
|
||||||
HttpFirewallRuleGroup: &pb.HTTPFirewallRuleGroup{Id: int64(stat.HttpFirewallRuleGroupId), Name: ruleGroupName},
|
HttpFirewallRuleGroup: &pb.HTTPFirewallRuleGroup{Id: int64(stat.HttpFirewallRuleGroupId), Name: ruleGroupName},
|
||||||
Count: int64(stat.Count),
|
Count: int64(stat.Count),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
sort.Slice(result.HttpFirewallRuleGroups, func(i, j int) bool {
|
||||||
|
return result.HttpFirewallRuleGroups[i].Count > result.HttpFirewallRuleGroups[j].Count
|
||||||
|
})
|
||||||
|
if len(result.HttpFirewallRuleGroups) > 10 {
|
||||||
|
result.HttpFirewallRuleGroups = result.HttpFirewallRuleGroups[:10]
|
||||||
|
}
|
||||||
|
|
||||||
// 节点排行
|
// 节点排行
|
||||||
topNodeStats, err := stats.SharedNodeTrafficHourlyStatDAO.FindTopNodeStatsWithAttack(tx, "node", hourFrom, hourTo, 10)
|
topNodeStats, err := stats.SharedNodeTrafficHourlyStatDAO.FindTopNodeStatsWithAttack(tx, "node", hourFrom, hourTo, 10)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -90,10 +91,13 @@ func (this *ServerHTTPFirewallDailyStatService) ComposeServerHTTPFirewallDashboa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 规则分组
|
// 规则分组
|
||||||
groupStats, err := stats.SharedServerHTTPFirewallDailyStatDAO.GroupDailyCount(tx, userId, req.ServerId, monthFrom, monthTo, 0, 10)
|
groupStats, err := stats.SharedServerHTTPFirewallDailyStatDAO.GroupDailyCount(tx, userId, req.ServerId, monthFrom, monthTo, 0, 20)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 合并同名
|
||||||
|
var groupNamedStatsMap = map[string]*stats.ServerHTTPFirewallDailyStat{} // name => *ServerHTTPFirewallDailyStat
|
||||||
for _, stat := range groupStats {
|
for _, stat := range groupStats {
|
||||||
ruleGroupName, err := models.SharedHTTPFirewallRuleGroupDAO.FindHTTPFirewallRuleGroupName(tx, int64(stat.HttpFirewallRuleGroupId))
|
ruleGroupName, err := models.SharedHTTPFirewallRuleGroupDAO.FindHTTPFirewallRuleGroupName(tx, int64(stat.HttpFirewallRuleGroupId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -103,11 +107,26 @@ func (this *ServerHTTPFirewallDailyStatService) ComposeServerHTTPFirewallDashboa
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namedStat, ok := groupNamedStatsMap[ruleGroupName]
|
||||||
|
if ok {
|
||||||
|
namedStat.Count += stat.Count
|
||||||
|
} else {
|
||||||
|
groupNamedStatsMap[ruleGroupName] = stat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ruleGroupName, stat := range groupNamedStatsMap {
|
||||||
resp.HttpFirewallRuleGroups = append(resp.HttpFirewallRuleGroups, &pb.ComposeServerHTTPFirewallDashboardResponse_HTTPFirewallRuleGroupStat{
|
resp.HttpFirewallRuleGroups = append(resp.HttpFirewallRuleGroups, &pb.ComposeServerHTTPFirewallDashboardResponse_HTTPFirewallRuleGroupStat{
|
||||||
HttpFirewallRuleGroup: &pb.HTTPFirewallRuleGroup{Id: int64(stat.HttpFirewallRuleGroupId), Name: ruleGroupName},
|
HttpFirewallRuleGroup: &pb.HTTPFirewallRuleGroup{Id: int64(stat.HttpFirewallRuleGroupId), Name: ruleGroupName},
|
||||||
Count: int64(stat.Count),
|
Count: int64(stat.Count),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
sort.Slice(resp.HttpFirewallRuleGroups, func(i, j int) bool {
|
||||||
|
return resp.HttpFirewallRuleGroups[i].Count > resp.HttpFirewallRuleGroups[j].Count
|
||||||
|
})
|
||||||
|
if len(resp.HttpFirewallRuleGroups) > 10 {
|
||||||
|
resp.HttpFirewallRuleGroups = resp.HttpFirewallRuleGroups[:10]
|
||||||
|
}
|
||||||
|
|
||||||
// 每日趋势
|
// 每日趋势
|
||||||
dayBefore := timeutil.Format("Ymd", date.AddDate(0, 0, -14))
|
dayBefore := timeutil.Format("Ymd", date.AddDate(0, 0, -14))
|
||||||
|
|||||||
Reference in New Issue
Block a user