diff --git a/internal/web/actions/default/clusters/cluster/settings/health.go b/internal/web/actions/default/clusters/cluster/settings/health/index.go similarity index 89% rename from internal/web/actions/default/clusters/cluster/settings/health.go rename to internal/web/actions/default/clusters/cluster/settings/health/index.go index 1bc3c411..d0f64522 100644 --- a/internal/web/actions/default/clusters/cluster/settings/health.go +++ b/internal/web/actions/default/clusters/cluster/settings/health/index.go @@ -1,4 +1,4 @@ -package settings +package health import ( "encoding/json" @@ -9,16 +9,16 @@ import ( "github.com/iwind/TeaGo/actions" ) -type HealthAction struct { +type IndexAction struct { actionutils.ParentAction } -func (this *HealthAction) Init() { +func (this *IndexAction) Init() { this.Nav("", "setting", "") this.SecondMenu("health") } -func (this *HealthAction) RunGet(params struct { +func (this *IndexAction) RunGet(params struct { ClusterId int64 }) { configResp, err := this.RPC().NodeClusterRPC().FindNodeClusterHealthCheckConfig(this.AdminContext(), &pb.FindNodeClusterHealthCheckConfigRequest{NodeClusterId: params.ClusterId}) @@ -40,7 +40,7 @@ func (this *HealthAction) RunGet(params struct { this.Show() } -func (this *HealthAction) RunPost(params struct { +func (this *IndexAction) RunPost(params struct { ClusterId int64 HealthCheckJSON []byte Must *actions.Must diff --git a/internal/web/actions/default/clusters/cluster/settings/healthRunPopup.go b/internal/web/actions/default/clusters/cluster/settings/health/runPopup.go similarity index 76% rename from internal/web/actions/default/clusters/cluster/settings/healthRunPopup.go rename to internal/web/actions/default/clusters/cluster/settings/health/runPopup.go index cb6a02f1..7084946b 100644 --- a/internal/web/actions/default/clusters/cluster/settings/healthRunPopup.go +++ b/internal/web/actions/default/clusters/cluster/settings/health/runPopup.go @@ -1,4 +1,4 @@ -package settings +package health import ( "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" @@ -7,20 +7,19 @@ import ( "github.com/iwind/TeaGo/actions" ) -type HealthRunPopupAction struct { +type RunPopupAction struct { actionutils.ParentAction } -func (this *HealthRunPopupAction) Init() { +func (this *RunPopupAction) Init() { this.Nav("", "", "") } -func (this *HealthRunPopupAction) RunGet(params struct{}) { - +func (this *RunPopupAction) RunGet(params struct{}) { this.Show() } -func (this *HealthRunPopupAction) RunPost(params struct { +func (this *RunPopupAction) RunPost(params struct { ClusterId int64 Must *actions.Must diff --git a/internal/web/actions/default/clusters/cluster/settings/init.go b/internal/web/actions/default/clusters/cluster/settings/init.go index b89adea0..48b0acd7 100644 --- a/internal/web/actions/default/clusters/cluster/settings/init.go +++ b/internal/web/actions/default/clusters/cluster/settings/init.go @@ -5,6 +5,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/cache" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/dns" firewallActions "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/firewall-actions" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/health" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/services" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/toa" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/waf" @@ -22,8 +23,8 @@ func init() { GetPost("", new(IndexAction)). // 健康检查 - GetPost("/health", new(HealthAction)). - GetPost("/healthRunPopup", new(HealthRunPopupAction)). + GetPost("/health", new(health.IndexAction)). + GetPost("/health/runPopup", new(health.RunPopupAction)). // 缓存 GetPost("/cache", new(cache.IndexAction)). diff --git a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go index 88ad5c2f..8452ca5c 100644 --- a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go +++ b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go @@ -1,11 +1,13 @@ package clusterutils import ( + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/rpc" "github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/logs" "github.com/iwind/TeaGo/maps" @@ -86,16 +88,27 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt "isActive": selectedItem == "waf", "isOn": cluster.HttpFirewallPolicyId > 0, }) - items = append(items, maps.Map{ - "name": "WAF动作", - "url": "/clusters/cluster/settings/firewall-actions?clusterId=" + clusterId, - "isActive": selectedItem == "firewallAction", - }) - items = append(items, maps.Map{ - "name": "健康检查", - "url": "/clusters/cluster/settings/health?clusterId=" + clusterId, - "isActive": selectedItem == "health", - }) + + { + hasActions, _ := this.checkFirewallActions(cluster.Id) + items = append(items, maps.Map{ + "name": "WAF动作", + "url": "/clusters/cluster/settings/firewall-actions?clusterId=" + clusterId, + "isActive": selectedItem == "firewallAction", + "isOn": hasActions, + }) + } + + { + healthCheckIsOn, _ := this.checkHealthCheckIsOn(cluster.Id) + items = append(items, maps.Map{ + "name": "健康检查", + "url": "/clusters/cluster/settings/health?clusterId=" + clusterId, + "isActive": selectedItem == "health", + "isOn": healthCheckIsOn, + }) + } + items = append(items, maps.Map{ "name": "DNS设置", "url": "/clusters/cluster/settings/dns?clusterId=" + clusterId, @@ -114,3 +127,37 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt }) return } + +// 检查健康检查是否开启 +func (this *ClusterHelper) checkHealthCheckIsOn(clusterId int64) (bool, error) { + rpcClient, err := rpc.SharedRPC() + if err != nil { + return false, err + } + resp, err := rpcClient.NodeClusterRPC().FindNodeClusterHealthCheckConfig(rpcClient.Context(0), &pb.FindNodeClusterHealthCheckConfigRequest{NodeClusterId: clusterId}) + if err != nil { + return false, err + } + if len(resp.HealthCheckJSON) > 0 { + healthCheckConfig := &serverconfigs.HealthCheckConfig{} + err = json.Unmarshal(resp.HealthCheckJSON, healthCheckConfig) + if err != nil { + return false, err + } + return healthCheckConfig.IsOn, nil + } + return false, nil +} + +// 检查是否有WAF动作 +func (this *ClusterHelper) checkFirewallActions(clusterId int64) (bool, error) { + rpcClient, err := rpc.SharedRPC() + if err != nil { + return false, err + } + resp, err := rpcClient.NodeClusterFirewallActionRPC().CountAllEnabledNodeClusterFirewallActions(rpcClient.Context(0), &pb.CountAllEnabledNodeClusterFirewallActionsRequest{NodeClusterId: clusterId}) + if err != nil { + return false, err + } + return resp.Count > 0, nil +} diff --git a/web/views/@default/clusters/cluster/settings/health.html b/web/views/@default/clusters/cluster/settings/health/index.html similarity index 100% rename from web/views/@default/clusters/cluster/settings/health.html rename to web/views/@default/clusters/cluster/settings/health/index.html diff --git a/web/views/@default/clusters/cluster/settings/health.js b/web/views/@default/clusters/cluster/settings/health/index.js similarity index 72% rename from web/views/@default/clusters/cluster/settings/health.js rename to web/views/@default/clusters/cluster/settings/health/index.js index 48804c4f..17b474bc 100644 --- a/web/views/@default/clusters/cluster/settings/health.js +++ b/web/views/@default/clusters/cluster/settings/health/index.js @@ -3,7 +3,7 @@ Tea.context(function () { this.run = function () { teaweb.confirm("确定要对当前集群下的所有节点进行健康检查吗?", function () { - teaweb.popup("/clusters/cluster/settings/healthRunPopup?clusterId=" + this.clusterId, { + teaweb.popup("/clusters/cluster/settings/health/runPopup?clusterId=" + this.clusterId, { height: "25em" }) }) diff --git a/web/views/@default/clusters/cluster/settings/healthRunPopup.html b/web/views/@default/clusters/cluster/settings/health/runPopup.html similarity index 100% rename from web/views/@default/clusters/cluster/settings/healthRunPopup.html rename to web/views/@default/clusters/cluster/settings/health/runPopup.html diff --git a/web/views/@default/clusters/cluster/settings/healthRunPopup.js b/web/views/@default/clusters/cluster/settings/health/runPopup.js similarity index 100% rename from web/views/@default/clusters/cluster/settings/healthRunPopup.js rename to web/views/@default/clusters/cluster/settings/health/runPopup.js