主分支代码
This commit is contained in:
98
EdgeAdmin/internal/web/actions/default/db/clickhouse.go
Normal file
98
EdgeAdmin/internal/web/actions/default/db/clickhouse.go
Normal file
@@ -0,0 +1,98 @@
|
||||
//go:build plus
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
const clickhouseConfigCode = "clickhouseConfig"
|
||||
|
||||
type ClickHouseAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) Init() {
|
||||
this.Nav("db", "db", "clickhouse")
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) RunGet(params struct{}) {
|
||||
this.Data["mainTab"] = "clickhouse"
|
||||
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: clickhouseConfigCode})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
cfg := &systemconfigs.ClickHouseSetting{Port: 8123, Database: "default"}
|
||||
if len(resp.ValueJSON) > 0 {
|
||||
_ = json.Unmarshal(resp.ValueJSON, cfg)
|
||||
}
|
||||
if cfg.Port <= 0 {
|
||||
cfg.Port = 8123
|
||||
}
|
||||
if cfg.Database == "" {
|
||||
cfg.Database = "default"
|
||||
}
|
||||
this.Data["config"] = map[string]interface{}{
|
||||
"host": cfg.Host,
|
||||
"port": cfg.Port,
|
||||
"user": cfg.User,
|
||||
"password": cfg.Password,
|
||||
"database": cfg.Database,
|
||||
}
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) RunPost(params struct {
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
Database string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.DBNode_LogUpdateDBNode, 0)
|
||||
if params.Port <= 0 {
|
||||
params.Port = 8123
|
||||
}
|
||||
if params.Database == "" {
|
||||
params.Database = "default"
|
||||
}
|
||||
password := params.Password
|
||||
if password == "" {
|
||||
resp, _ := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: clickhouseConfigCode})
|
||||
if len(resp.ValueJSON) > 0 {
|
||||
var old systemconfigs.ClickHouseSetting
|
||||
if json.Unmarshal(resp.ValueJSON, &old) == nil {
|
||||
password = old.Password
|
||||
}
|
||||
}
|
||||
}
|
||||
cfg := &systemconfigs.ClickHouseSetting{
|
||||
Host: params.Host,
|
||||
Port: params.Port,
|
||||
User: params.User,
|
||||
Password: password,
|
||||
Database: params.Database,
|
||||
}
|
||||
valueJSON, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||
Code: clickhouseConfigCode,
|
||||
ValueJSON: valueJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
33
EdgeAdmin/internal/web/actions/default/db/clickhouse_stub.go
Normal file
33
EdgeAdmin/internal/web/actions/default/db/clickhouse_stub.go
Normal file
@@ -0,0 +1,33 @@
|
||||
//go:build !plus
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type ClickHouseAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) Init() {
|
||||
this.Nav("db", "db", "clickhouse")
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) RunGet(params struct{}) {
|
||||
this.Data["mainTab"] = "clickhouse"
|
||||
this.Data["config"] = map[string]interface{}{
|
||||
"host": "", "port": 8123, "user": "", "password": "", "database": "default",
|
||||
}
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *ClickHouseAction) RunPost(params struct {
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
Database string
|
||||
}) {
|
||||
this.Fail("请使用商业版以在页面上配置 ClickHouse")
|
||||
}
|
||||
@@ -23,5 +23,6 @@ func (this *Helper) BeforeAction(action *actions.ActionObject) {
|
||||
|
||||
var tabbar = actionutils.NewTabbar()
|
||||
tabbar.Add(this.Lang(action, codes.DBNode_TabNodes), "", "/db", "", selectedTabbar == "db")
|
||||
tabbar.Add(this.Lang(action, codes.DBNode_TabClickHouse), "", "/db/clickhouse", "", selectedTabbar == "clickhouse")
|
||||
actionutils.SetTabbar(action, tabbar)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ func init() {
|
||||
Get("/node", new(NodeAction)).
|
||||
Get("/logs", new(LogsAction)).
|
||||
Post("/status", new(StatusAction)).
|
||||
GetPost("/clickhouse", new(ClickHouseAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -87,8 +87,13 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Field("type", params.Type).
|
||||
Require("请选择存储类型")
|
||||
|
||||
baseType, writeTargets := serverconfigs.ParseStorageTypeAndWriteTargets(params.Type)
|
||||
if writeTargets == nil {
|
||||
writeTargets = &serverconfigs.AccessLogWriteTargets{File: true, MySQL: true}
|
||||
}
|
||||
|
||||
var options any = nil
|
||||
switch params.Type {
|
||||
switch baseType {
|
||||
case serverconfigs.AccessLogStorageTypeFile:
|
||||
params.Must.
|
||||
Field("filePath", params.FilePath).
|
||||
@@ -170,14 +175,21 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
writeTargetsMap := map[string]bool{
|
||||
"file": writeTargets.File,
|
||||
"mysql": writeTargets.MySQL,
|
||||
"clickhouse": writeTargets.ClickHouse,
|
||||
}
|
||||
writeTargetsJSON, _ := json.Marshal(writeTargetsMap)
|
||||
createResp, err := this.RPC().HTTPAccessLogPolicyRPC().CreateHTTPAccessLogPolicy(this.AdminContext(), &pb.CreateHTTPAccessLogPolicyRequest{
|
||||
Name: params.Name,
|
||||
Type: params.Type,
|
||||
Type: baseType,
|
||||
OptionsJSON: optionsJSON,
|
||||
CondsJSON: nil, // TODO
|
||||
IsPublic: params.IsPublic,
|
||||
FirewallOnly: params.FirewallOnly,
|
||||
DisableDefaultDB: params.DisableDefaultDB,
|
||||
WriteTargetsJSON: writeTargetsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -46,11 +46,16 @@ func (this *IndexAction) RunGet(params struct{}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
writeTargets := serverconfigs.ParseWriteTargetsFromPolicy(policy.WriteTargetsJSON, policy.Type, policy.DisableDefaultDB)
|
||||
typeDisplay := serverconfigs.ComposeStorageTypeDisplay(policy.Type, writeTargets)
|
||||
if typeDisplay == "" {
|
||||
typeDisplay = policy.Type
|
||||
}
|
||||
policyMaps = append(policyMaps, maps.Map{
|
||||
"id": policy.Id,
|
||||
"name": policy.Name,
|
||||
"type": policy.Type,
|
||||
"typeName": serverconfigs.FindAccessLogStorageTypeName(policy.Type),
|
||||
"typeName": serverconfigs.FindAccessLogStorageTypeName(typeDisplay),
|
||||
"isOn": policy.IsOn,
|
||||
"isPublic": policy.IsPublic,
|
||||
"firewallOnly": policy.FirewallOnly,
|
||||
|
||||
@@ -36,11 +36,18 @@ func InitPolicy(parent *actionutils.ParentAction, policyId int64) error {
|
||||
}
|
||||
}
|
||||
|
||||
writeTargets := serverconfigs.ParseWriteTargetsFromPolicy(policy.WriteTargetsJSON, policy.Type, policy.DisableDefaultDB)
|
||||
typeDisplay := serverconfigs.ComposeStorageTypeDisplay(policy.Type, writeTargets)
|
||||
if typeDisplay == "" {
|
||||
typeDisplay = policy.Type
|
||||
}
|
||||
|
||||
parent.Data["policy"] = maps.Map{
|
||||
"id": policy.Id,
|
||||
"name": policy.Name,
|
||||
"type": policy.Type,
|
||||
"typeName": serverconfigs.FindAccessLogStorageTypeName(policy.Type),
|
||||
"typeDisplay": typeDisplay,
|
||||
"typeName": serverconfigs.FindAccessLogStorageTypeName(typeDisplay),
|
||||
"isOn": policy.IsOn,
|
||||
"isPublic": policy.IsPublic,
|
||||
"firewallOnly": policy.FirewallOnly,
|
||||
|
||||
@@ -39,6 +39,7 @@ func (this *UpdateAction) RunGet(params struct {
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
PolicyId int64
|
||||
Name string
|
||||
Type string // 存储类型(含组合:file / file_mysql / file_clickhouse / file_mysql_clickhouse / es / tcp / syslog / command)
|
||||
|
||||
// file
|
||||
FilePath string
|
||||
@@ -101,10 +102,17 @@ func (this *UpdateAction) RunPost(params struct {
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入日志策略的名称")
|
||||
Require("请输入日志策略的名称").
|
||||
Field("type", params.Type).
|
||||
Require("请选择存储类型")
|
||||
|
||||
baseType, writeTargets := serverconfigs.ParseStorageTypeAndWriteTargets(params.Type)
|
||||
if writeTargets == nil {
|
||||
writeTargets = &serverconfigs.AccessLogWriteTargets{File: true, MySQL: true}
|
||||
}
|
||||
|
||||
var options interface{} = nil
|
||||
switch policy.Type {
|
||||
switch baseType {
|
||||
case serverconfigs.AccessLogStorageTypeFile:
|
||||
params.Must.
|
||||
Field("filePath", params.FilePath).
|
||||
@@ -187,15 +195,23 @@ func (this *UpdateAction) RunPost(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
writeTargetsMap := map[string]bool{
|
||||
"file": writeTargets.File,
|
||||
"mysql": writeTargets.MySQL,
|
||||
"clickhouse": writeTargets.ClickHouse,
|
||||
}
|
||||
writeTargetsJSON, _ := json.Marshal(writeTargetsMap)
|
||||
_, err = this.RPC().HTTPAccessLogPolicyRPC().UpdateHTTPAccessLogPolicy(this.AdminContext(), &pb.UpdateHTTPAccessLogPolicyRequest{
|
||||
HttpAccessLogPolicyId: params.PolicyId,
|
||||
Name: params.Name,
|
||||
Type: baseType,
|
||||
OptionsJSON: optionsJSON,
|
||||
CondsJSON: nil, // TODO
|
||||
IsOn: params.IsOn,
|
||||
IsPublic: params.IsPublic,
|
||||
FirewallOnly: params.FirewallOnly,
|
||||
DisableDefaultDB: params.DisableDefaultDB,
|
||||
WriteTargetsJSON: writeTargetsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package settingutils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
@@ -46,7 +48,10 @@ func (this *AdvancedHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNex
|
||||
if plus.AllowComponent(plus.ComponentCodeUser) {
|
||||
tabbar.Add(this.Lang(actionPtr, codes.AdminSetting_TabUserNodes), "", "/settings/userNodes", "", this.tab == "userNodes")
|
||||
}
|
||||
tabbar.Add(this.Lang(actionPtr, codes.AdminSetting_TabAccessLogDatabases), "", "/db", "", this.tab == "dbNodes")
|
||||
// 外层始终显示「日志数据库」与「ClickHouse 配置」两个标签,不随点击变化
|
||||
path := action.Request.URL.Path
|
||||
tabbar.Add(this.Lang(actionPtr, codes.AdminSetting_TabAccessLogDatabases), "", "/db", "", (path == "/db" || strings.HasPrefix(path, "/db/")) && path != "/db/clickhouse")
|
||||
tabbar.Add(this.Lang(actionPtr, codes.DBNode_TabClickHouse), "", "/db/clickhouse", "", path == "/db/clickhouse")
|
||||
if teaconst.IsPlus {
|
||||
// 目前仅在调试模式下使用
|
||||
if Tea.IsTesting() {
|
||||
|
||||
Reference in New Issue
Block a user