diff --git a/internal/web/actions/default/clusters/cluster/settings/health/checkDomain.go b/internal/web/actions/default/clusters/cluster/settings/health/checkDomain.go new file mode 100644 index 00000000..1948c5a7 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/health/checkDomain.go @@ -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() +} diff --git a/internal/web/actions/default/clusters/cluster/settings/init.go b/internal/web/actions/default/clusters/cluster/settings/init.go index 5d7ee790..cf1ce903 100644 --- a/internal/web/actions/default/clusters/cluster/settings/init.go +++ b/internal/web/actions/default/clusters/cluster/settings/init.go @@ -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)). diff --git a/web/public/js/components/common/health-check-config-box.js b/web/public/js/components/common/health-check-config-box.js index 0d840707..081a75cb 100644 --- a/web/public/js/components/common/health-check-config-box.js +++ b/web/public/js/components/common/health-check-config-box.js @@ -1,5 +1,5 @@ Vue.component("health-check-config-box", { - props: ["v-health-check-config"], + props: ["v-health-check-config", "v-check-domain-url"], data: function () { let healthCheckConfig = this.vHealthCheckConfig let urlProtocol = "http" @@ -76,7 +76,9 @@ Vue.component("health-check-config-box", { urlHost: urlHost, urlPort: urlPort, urlRequestURI: urlRequestURI, - urlIsEditing: healthCheckConfig.url.length == 0 + urlIsEditing: healthCheckConfig.url.length == 0, + + hostErr: "" } }, watch: { @@ -100,6 +102,7 @@ Vue.component("health-check-config-box", { }, urlHost: function () { this.changeURL() + this.hostErr = "" }, "healthCheck.countTries": function (v) { let count = parseInt(v) @@ -147,6 +150,24 @@ Vue.component("health-check-config-box", { } }) }, + onChangeURLHost: function () { + let checkDomainURL = this.vCheckDomainUrl + if (checkDomainURL == null || checkDomainURL.length == 0) { + return + } + + let that = this + Tea.action(checkDomainURL) + .params({host: this.urlHost}) + .success(function (resp) { + if (!resp.data.isOk) { + that.hostErr = "在当前集群中找不到此域名,可能会影响健康检查结果。" + } else { + that.hostErr = "" + } + }) + .post() + }, editURL: function () { this.urlIsEditing = !this.urlIsEditing } @@ -185,8 +206,8 @@ Vue.component("health-check-config-box", {
已经部署到当前集群的一个域名;如果为空则使用节点IP作为域名。如果协议是https,这里必须填写一个已经设置了SSL证书的域名。
+ +{{hostErr}}已经部署到当前集群的一个域名;如果为空则使用节点IP作为域名。如果协议是https,这里必须填写一个已经设置了SSL证书的域名。