健康检查设置域名时检查域名是否存在

This commit is contained in:
GoEdgeLab
2022-09-17 11:38:04 +08:00
parent 3212e687cb
commit 0c07fcf504
4 changed files with 79 additions and 5 deletions

View File

@@ -0,0 +1,52 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package health
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"net"
"strings"
)
type CheckDomainAction struct {
actionutils.ParentAction
}
func (this *CheckDomainAction) RunPost(params struct {
Host string
ClusterId int64
}) {
this.Data["isOk"] = true // 默认为TRUE
var host = params.Host
if len(host) > 0 &&
!strings.Contains(host, "{") /** 包含变量 **/ {
h, _, err := net.SplitHostPort(host)
if err == nil && len(h) > 0 {
host = h
}
// 是否为IP
if net.ParseIP(host) != nil {
this.Success()
return
}
host = strings.ToLower(host)
resp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
NodeClusterId: params.ClusterId,
ServerNames: []string{host},
SupportWildcard: true,
})
if err != nil {
this.ErrorPage(err)
return
}
if len(resp.DuplicatedServerNames) == 0 {
this.Data["isOk"] = false
}
}
this.Success()
}

View File

@@ -29,6 +29,7 @@ func init() {
// 健康检查
GetPost("/health", new(health.IndexAction)).
GetPost("/health/runPopup", new(health.RunPopupAction)).
Post("/health/checkDomain", new(health.CheckDomainAction)).
// 缓存
GetPost("/cache", new(cache.IndexAction)).