mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-29 14:26:34 +08:00
阶段性提交
This commit is contained in:
@@ -99,6 +99,8 @@ func (this *BindHTTPFirewallPopupAction) RunPost(params struct {
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("绑定IP名单 %d 到WAF策略 %d", params.ListId, params.HttpFirewallPolicyId)
|
||||
|
||||
// List类型
|
||||
listResp, err := this.RPC().IPListRPC().FindEnabledIPList(this.AdminContext(), &pb.FindEnabledIPListRequest{IpListId: params.ListId})
|
||||
if err != nil {
|
||||
|
||||
@@ -18,6 +18,8 @@ func (this *UnbindHTTPFirewallAction) RunPost(params struct {
|
||||
HttpFirewallPolicyId int64
|
||||
ListId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("接触绑定IP名单 %d WAF策略 %d", params.ListId, params.HttpFirewallPolicyId)
|
||||
|
||||
// List类型
|
||||
listResp, err := this.RPC().IPListRPC().FindEnabledIPList(this.AdminContext(), &pb.FindEnabledIPListRequest{IpListId: params.ListId})
|
||||
if err != nil {
|
||||
|
||||
25
internal/web/actions/default/servers/metrics/charts.go
Normal file
25
internal/web/actions/default/servers/metrics/charts.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type ChartsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ChartsAction) Init() {
|
||||
this.Nav("", "", "chart")
|
||||
}
|
||||
|
||||
func (this *ChartsAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
83
internal/web/actions/default/servers/metrics/createPopup.go
Normal file
83
internal/web/actions/default/servers/metrics/createPopup.go
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
Category string
|
||||
}) {
|
||||
this.Data["category"] = params.Category
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
Category string
|
||||
KeysJSON []byte
|
||||
PeriodJSON []byte
|
||||
Value string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入指标名称")
|
||||
|
||||
if len(params.Category) == 0 {
|
||||
this.Fail("请选择指标类型")
|
||||
}
|
||||
|
||||
// 统计对象
|
||||
if len(params.KeysJSON) == 0 {
|
||||
this.FailField("keys", "请选择指标统计的对象")
|
||||
}
|
||||
var keys = []string{}
|
||||
err := json.Unmarshal(params.KeysJSON, &keys)
|
||||
if err != nil {
|
||||
this.FailField("keys", "解析指标对象失败")
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
this.FailField("keys", "请选择指标统计的对象")
|
||||
}
|
||||
|
||||
var periodMap = maps.Map{}
|
||||
err = json.Unmarshal(params.PeriodJSON, &periodMap)
|
||||
if err != nil {
|
||||
this.FailField("period", "解析统计周期失败")
|
||||
}
|
||||
var period = periodMap.GetInt32("period")
|
||||
var periodUnit = periodMap.GetString("unit")
|
||||
|
||||
createResp, err := this.RPC().MetricItemRPC().CreateMetricItem(this.AdminContext(), &pb.CreateMetricItemRequest{
|
||||
Code: "", // TODO 未来实现
|
||||
Category: params.Category,
|
||||
Name: params.Name,
|
||||
Keys: keys,
|
||||
Period: period,
|
||||
PeriodUnit: periodUnit,
|
||||
Value: params.Value,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defer this.CreateLogInfo("创建统计指标 %d", createResp.MetricItemId)
|
||||
this.Success()
|
||||
}
|
||||
26
internal/web/actions/default/servers/metrics/delete.go
Normal file
26
internal/web/actions/default/servers/metrics/delete.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("删除统计指标")
|
||||
|
||||
_, err := this.RPC().MetricItemRPC().DeleteMetricItem(this.AdminContext(), &pb.DeleteMetricItemRequest{MetricItemId: params.ItemId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
61
internal/web/actions/default/servers/metrics/index.go
Normal file
61
internal/web/actions/default/servers/metrics/index.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Category string
|
||||
}) {
|
||||
if len(params.Category) == 0 {
|
||||
params.Category = "http"
|
||||
}
|
||||
this.Data["category"] = params.Category
|
||||
|
||||
countResp, err := this.RPC().MetricItemRPC().CountAllEnabledMetricItems(this.AdminContext(), &pb.CountAllEnabledMetricItemsRequest{Category: params.Category})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
page := this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
itemsResp, err := this.RPC().MetricItemRPC().ListEnabledMetricItems(this.AdminContext(), &pb.ListEnabledMetricItemsRequest{
|
||||
Category: params.Category,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var itemMaps = []maps.Map{}
|
||||
for _, item := range itemsResp.MetricItems {
|
||||
itemMaps = append(itemMaps, maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"isOn": item.IsOn,
|
||||
"period": item.Period,
|
||||
"periodUnit": item.PeriodUnit,
|
||||
"keys": item.Keys,
|
||||
"value": item.Value,
|
||||
"category": item.Category,
|
||||
})
|
||||
}
|
||||
this.Data["items"] = itemMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
24
internal/web/actions/default/servers/metrics/init.go
Normal file
24
internal/web/actions/default/servers/metrics/init.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Data("teaMenu", "servers").
|
||||
Data("teaSubMenu", "metric").
|
||||
Prefix("/servers/metrics").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Get("/item", new(ItemAction)).
|
||||
Get("/charts", new(ChartsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
25
internal/web/actions/default/servers/metrics/item.go
Normal file
25
internal/web/actions/default/servers/metrics/item.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type ItemAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ItemAction) Init() {
|
||||
this.Nav("", "", "item")
|
||||
}
|
||||
|
||||
func (this *ItemAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -2,16 +2,83 @@
|
||||
|
||||
package metrics
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
this.Nav("", "", "update")
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunGet(params struct{}) {
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
err := InitItem(this.Parent(), params.ItemId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
ItemId int64
|
||||
Name string
|
||||
KeysJSON []byte
|
||||
PeriodJSON []byte
|
||||
Value string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入指标名称")
|
||||
|
||||
// 统计对象
|
||||
if len(params.KeysJSON) == 0 {
|
||||
this.FailField("keys", "请选择指标统计的对象")
|
||||
}
|
||||
var keys = []string{}
|
||||
err := json.Unmarshal(params.KeysJSON, &keys)
|
||||
if err != nil {
|
||||
this.FailField("keys", "解析指标对象失败")
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
this.FailField("keys", "请选择指标统计的对象")
|
||||
}
|
||||
|
||||
var periodMap = maps.Map{}
|
||||
err = json.Unmarshal(params.PeriodJSON, &periodMap)
|
||||
if err != nil {
|
||||
this.FailField("period", "解析统计周期失败")
|
||||
}
|
||||
var period = periodMap.GetInt32("period")
|
||||
var periodUnit = periodMap.GetString("unit")
|
||||
|
||||
_, err = this.RPC().MetricItemRPC().UpdateMetricItem(this.AdminContext(), &pb.UpdateMetricItemRequest{
|
||||
MetricItemId: params.ItemId,
|
||||
Name: params.Name,
|
||||
Keys: keys,
|
||||
Period: period,
|
||||
PeriodUnit: periodUnit,
|
||||
Value: params.Value,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defer this.CreateLogInfo("修改统计指标 %d", params.ItemId)
|
||||
this.Success()
|
||||
}
|
||||
|
||||
37
internal/web/actions/default/servers/metrics/utils.go
Normal file
37
internal/web/actions/default/servers/metrics/utils.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
func InitItem(parent *actionutils.ParentAction, itemId int64) error {
|
||||
client, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := client.MetricItemRPC().FindEnabledMetricItem(parent.AdminContext(), &pb.FindEnabledMetricItemRequest{MetricItemId: itemId})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var item = resp.MetricItem
|
||||
if item == nil {
|
||||
return errors.New("not found")
|
||||
}
|
||||
parent.Data["item"] = maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"isOn": item.IsOn,
|
||||
"keys": item.Keys,
|
||||
"value": item.Value,
|
||||
"period": item.Period,
|
||||
"periodUnit": item.PeriodUnit,
|
||||
"category": item.Category,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user