实现WAF统计数据接口

This commit is contained in:
GoEdgeLab
2021-01-26 18:41:02 +08:00
parent 2f9fe99088
commit e7a01c567f
12 changed files with 395 additions and 13 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type ServerService struct {
@@ -1247,10 +1248,14 @@ func (this *ServerService) UploadServerHTTPRequestStat(ctx context.Context, req
var tx = this.NullTx()
// 全局
month := req.Month
if len(month) != 6 {
return nil, errors.New("invalid month '" + month + "'")
if len(month) == 0 {
month = timeutil.Format("Ym")
}
day := req.Day
if len(day) == 0 {
day = timeutil.Format("Ymd")
}
// 区域
@@ -1389,5 +1394,22 @@ func (this *ServerService) UploadServerHTTPRequestStat(ctx context.Context, req
}
}
// 防火墙
for _, result := range req.HttpFirewallRuleGroups {
err := func() error {
if result.HttpFirewallRuleGroupId <= 0 {
return nil
}
key := fmt.Sprintf("%d@%d@%s@%s", result.ServerId, result.HttpFirewallRuleGroupId, result.Action, day)
serverStatLocker.Lock()
serverHTTPFirewallRuleGroupStatMap[key] += result.Count
serverStatLocker.Unlock()
return nil
}()
if err != nil {
return nil, err
}
}
return this.Success()
}