主分支代码
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
FROM --platform=linux/amd64 alpine:latest
|
||||
LABEL maintainer="goedge.cdn@gmail.com"
|
||||
ENV TZ "Asia/Shanghai"
|
||||
ENV VERSION 1.4.5
|
||||
ENV VERSION 1.4.6
|
||||
ENV ROOT_DIR /usr/local/goedge
|
||||
ENV TAR_FILE edge-admin-linux-amd64-plus-v${VERSION}.zip
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package teaconst
|
||||
|
||||
const (
|
||||
Version = "1.4.5" //1.3.9
|
||||
Version = "1.4.6" //1.3.9
|
||||
|
||||
APINodeVersion = "1.4.5" //1.3.9
|
||||
APINodeVersion = "1.4.6" //1.3.9
|
||||
|
||||
ProductName = "Edge Admin"
|
||||
ProcessName = "edge-admin"
|
||||
|
||||
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() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<first-menu>
|
||||
<first-menu v-if="firstMenuItem !== 'clickhouse'">
|
||||
<menu-item href="/db">所有节点</menu-item>
|
||||
<span class="item disabled">|</span>
|
||||
<menu-item :href="'/db/node?nodeId=' + node.id" code="node">"{{node.name}}"详情</menu-item>
|
||||
|
||||
46
EdgeAdmin/web/views/@default/db/clickHouse.html
Normal file
46
EdgeAdmin/web/views/@default/db/clickHouse.html
Normal file
@@ -0,0 +1,46 @@
|
||||
{$layout}
|
||||
{$template "menu"}
|
||||
|
||||
<h3>ClickHouse 配置</h3>
|
||||
<p class="comment">用于访问日志列表查询(logs_ingest 表)。配置后,访问日志列表将优先从 ClickHouse 读取;不配置则仅从 MySQL 读取。留空表示不使用 ClickHouse。</p>
|
||||
|
||||
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success" @submit.prevent="onSubmit">
|
||||
<csrf-token></csrf-token>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">连接地址(Host)</td>
|
||||
<td>
|
||||
<input type="text" name="host" maxlength="200" ref="focus" placeholder="如 127.0.0.1 或 clickhouse.example.com" :value="config.host"/>
|
||||
<p class="comment">ClickHouse 服务器地址。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>端口(Port)</td>
|
||||
<td>
|
||||
<input type="number" name="port" min="1" max="65535" style="width:6em" :value="config.port"/>
|
||||
<p class="comment">HTTP 接口端口,默认 8123。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>用户名(User)</td>
|
||||
<td>
|
||||
<input type="text" name="user" maxlength="100" :value="config.user"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>密码(Password)</td>
|
||||
<td>
|
||||
<input type="password" name="password" maxlength="200" placeholder="不修改请留空" value=""/>
|
||||
<p class="comment">留空则不修改已保存的密码。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>数据库名(Database)</td>
|
||||
<td>
|
||||
<input type="text" name="database" maxlength="100" placeholder="default" :value="config.database"/>
|
||||
<p class="comment">logs_ingest 表所在库,默认 default。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
12
EdgeAdmin/web/views/@default/db/clickHouse.js
Normal file
12
EdgeAdmin/web/views/@default/db/clickHouse.js
Normal file
@@ -0,0 +1,12 @@
|
||||
Tea.context(function () {
|
||||
this.success = function () {
|
||||
teaweb.success("保存成功")
|
||||
}
|
||||
this.onSubmit = function (e) {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
Tea.action("$").post().form(e.target).success(function () {
|
||||
Tea.Vue.success()
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -15,13 +15,14 @@
|
||||
<td>
|
||||
<select class="ui dropdown auto-width" name="type" v-model="type">
|
||||
<option value="">[选择类型]</option>
|
||||
<option v-for="type in types" :value="type.code">{{type.name}}</option>
|
||||
<option v-for="t in types" :value="t.code">{{t.name}}</option>
|
||||
</select>
|
||||
<p class="comment">可选:文件、文件+MySQL、文件+ClickHouse、文件+MySQL+ClickHouse、ElasticSearch、TCP、Syslog、命令行等。</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- 文件 -->
|
||||
<tbody v-show="type == 'file'">
|
||||
<!-- 文件(含 文件 / 文件+MySQL / 文件+ClickHouse / 文件+MySQL+ClickHouse) -->
|
||||
<tbody v-show="type == 'file' || type == 'file_mysql' || type == 'file_clickhouse' || type == 'file_mysql_clickhouse'">
|
||||
<tr>
|
||||
<td>日志文件路径 *</td>
|
||||
<td>
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
<tr>
|
||||
<td>存储类型 *</td>
|
||||
<td>
|
||||
{{policy.typeName}}
|
||||
<select class="ui dropdown auto-width" name="type" v-model="policy.typeDisplay">
|
||||
<option v-for="t in types" :value="t.code">{{t.name}}</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- 文件 -->
|
||||
<tbody v-show="type == 'file'">
|
||||
<tbody v-show="policy.typeDisplay == 'file' || policy.typeDisplay == 'file_mysql' || policy.typeDisplay == 'file_clickhouse' || policy.typeDisplay == 'file_mysql_clickhouse'">
|
||||
<tr>
|
||||
<td>日志文件路径 *</td>
|
||||
<td>
|
||||
@@ -52,7 +54,7 @@
|
||||
</tbody>
|
||||
|
||||
<!-- Elastic Search -->
|
||||
<tbody v-show="type == 'es'">
|
||||
<tbody v-show="policy.typeDisplay == 'es'">
|
||||
<tr>
|
||||
<td>Endpoint *</td>
|
||||
<td>
|
||||
@@ -114,7 +116,7 @@
|
||||
</tbody>
|
||||
|
||||
<!-- TCP Socket -->
|
||||
<tbody v-show="type == 'tcp'">
|
||||
<tbody v-show="policy.typeDisplay == 'tcp'">
|
||||
<tr>
|
||||
<td>网络协议 *</td>
|
||||
<td>
|
||||
@@ -134,7 +136,7 @@
|
||||
</tbody>
|
||||
|
||||
<!-- Syslog -->
|
||||
<tbody v-show="type == 'syslog'">
|
||||
<tbody v-show="policy.typeDisplay == 'syslog'">
|
||||
<tr>
|
||||
<td>网络协议</td>
|
||||
<td>
|
||||
@@ -188,7 +190,7 @@
|
||||
</tbody>
|
||||
|
||||
<!-- 命令行输入流 -->
|
||||
<tbody v-show="type == 'command'">
|
||||
<tbody v-show="policy.typeDisplay == 'command'">
|
||||
<tr>
|
||||
<td>可执行文件 *</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user