diff --git a/cmd/server/agentmanager/PAgentMap.go b/cmd/server/agentmanager/PAgentMap.go index b1e1a8652bc6433608dda34ace6b3f4bdee31c25..0bcb14cc87515f4e7cfe772403b1b9d56d55093e 100644 --- a/cmd/server/agentmanager/PAgentMap.go +++ b/cmd/server/agentmanager/PAgentMap.go @@ -68,7 +68,7 @@ func (am *AgentManager) InitMachineList() { machine_list, err := pluginclient.Global_Client.MachineList() if err != nil { - err = errors.Errorf(err.Error()) + err = errors.Errorf("%s", err.Error()) global.ERManager.ErrorTransmit("agentmanager", "error", err, true, true) } diff --git a/cmd/server/main.go b/cmd/server/main.go index 4472a8af1380aa19982c4ab5c6dce9dcc997d6fd..d5cb8dedb4cf99b546301f8ad00c30eca223953d 100755 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -46,7 +46,7 @@ func main() { */ ermanager, err := resourcemanage.CreateErrorReleaseManager(global.RootContext, global.Close) if err != nil { - sdklogger.Fatal(err.Error()) + sdklogger.Fatal("%s", err.Error()) } global.ERManager = ermanager diff --git a/cmd/server/pluginclient/meta.go b/cmd/server/pluginclient/meta.go index 09c9a05bd2f24e13e3fa51e68729eafa90f16dfa..52c9d89c5550570991a47afa7b965c75abcf6054 100644 --- a/cmd/server/pluginclient/meta.go +++ b/cmd/server/pluginclient/meta.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: Wangjunqi123 * Date: Mon Nov 4 14:30:13 2024 +0800 @@ -20,5 +20,7 @@ var PluginInfo = &client.PluginInfo{ Author: "wangjunqi", Email: "wangjunqi@kylinos.cn", Url: "", // 远端访问插件服务端的地址 + Icon: "Help", + MenuName: "集群拓扑", PluginType: "micro-app", } diff --git a/go.mod b/go.mod index f6535a6c7f092bd16d9ad92718bff8bbff11edc2..bc1e205974ec729c0827d01af1a5ef0647cfe579 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gitee.com/openeuler/PilotGo-plugin-topology go 1.21 require ( - gitee.com/openeuler/PilotGo/sdk v0.0.0-20240711084602-e34bc1158484 + gitee.com/openeuler/PilotGo/sdk v0.0.0-20241227025309-05f048f9c7d8 github.com/fsouza/go-dockerclient v1.11.0 github.com/gin-contrib/timeout v0.0.3 github.com/gin-gonic/gin v1.9.1 diff --git a/go.sum b/go.sum index 5157a6bc65477f7ff81e682126201fc840c27e0c..041a55edb0fc445022f4d5b574edbe81f51159be 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -gitee.com/openeuler/PilotGo/sdk v0.0.0-20240711084602-e34bc1158484 h1:cb21Q6oVVLH5mCQ7Tb9lWpmpp3ZGYLtX4Y4DvkvgMtw= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20240711084602-e34bc1158484/go.mod h1:87giU5v2IkUx78GRfezNBHhDGqzlwhNICOVY+hUYSJM= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20241227025309-05f048f9c7d8 h1:J6BKrPKKpdkjBwthualuZUTra5qdYR2O62WHWlZBD3k= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20241227025309-05f048f9c7d8/go.mod h1:Et2wSYAR8hj9jMnSqwtyi8fA79q63tLvPcHwySiRG+g= github.com/AdaLogics/go-fuzz-headers v0.0.0-20210715213245-6c3934b029d8 h1:V8krnnfGj4pV65YLUm3C0/8bl7V5Nry2Pwvy3ru/wLc= github.com/AdaLogics/go-fuzz-headers v0.0.0-20210715213245-6c3934b029d8/go.mod h1:CzsSbkDixRphAF5hS6wbMKq0eI6ccJRb7/A0M6JBnwg= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= @@ -45,8 +45,8 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fsouza/go-dockerclient v1.11.0 h1:4ZAk6W7rPAtPXm7198EFqA5S68rwnNQORxlOA5OurCA= github.com/fsouza/go-dockerclient v1.11.0/go.mod h1:0I3TQCRseuPTzqlY4Y3ajfsg2VAdMQoazrkxJTiJg8s= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/common.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/common.go new file mode 100644 index 0000000000000000000000000000000000000000..cedd84baeee314641a066bd8e1cdf13658bc889b --- /dev/null +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/common.go @@ -0,0 +1,45 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Tue Jul 23 15:50:05 2024 +0800 + */ +package common + +import ( + "encoding/json" + "time" +) + +type MessageData struct { + MsgType int `json:"msg_type_id"` + MessageType string `json:"msg_type"` + TimeStamp time.Time `json:"timestamp"` + Data interface{} `json:"data"` +} + +type EventMessage struct { + MessageType int `json:"msgType"` + MessageData string `json:"msgData"` +} + +type EventCallback func(e *EventMessage) + +func (msgData *MessageData) ToMessageDataString() (string, error) { + data, err := json.Marshal(msgData) + if err != nil { + return "", err + } + return string(data), nil +} + +type CommonResult struct { + Code int `json:"code"` + Message string `json:"msg"` + Data json.RawMessage `json:"data"` +} + +func (r *CommonResult) ParseData(d interface{}) error { + return json.Unmarshal(r.Data, d) +} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/event.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/event.go deleted file mode 100644 index df2eca2ceca9c066cd1f69ec74bf413e6a277fe1..0000000000000000000000000000000000000000 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/event.go +++ /dev/null @@ -1,61 +0,0 @@ -package common - -import "encoding/json" - -// event消息类型定义 -const ( - // 主机安装软件包 - MsgPackageInstall = 0 - // 主机升级软件包 - MsgPackageUpdate = 1 - // 主机卸载软件包 - MsgPackageUninstall = 2 - // 主机ip变更 - MsgIPChange = 3 - - // 平台新增主机 - MsgHostAdd = 10 - // 平台移除主机 - MsgHostRemove = 11 - - // 插件添加 - MsgPluginAdd = 20 - // 插件卸载 - MsgPluginRemove = 21 -) - -type EventMessage struct { - MessageType int - MessageData string -} - -// 将 MessageData json字符串转换成指定结构体的message消息数据 -func ToMessage(d string, s interface{}) error { - return json.Unmarshal([]byte(d), s) -} - -type MDPackageInstall struct { - HostUUID string - Name string - Version string - Time string -} - -type MDPackageUpdate struct { - HostUUID string - Name string - Version string - Time string -} - -type MDPackageUninstall struct { - HostUUID string - Name string - Version string - Time string -} - -type MDIPChange struct { - HostUUID string - NewIP string -} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go index 90fe3522fc91dabc4d6eedf69e0b1bca027cd62c..d848919b1dc41369a5e7ec6d223e622a756f5569 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: Gzx1999 + * Date: Tue Nov 7 15:01:17 2023 +0800 + */ package common const ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go index 2a8f7d0a6e2b18f51882ccefaa6471530d2d406a..387a6b48cd80c8f3210956b554e34f1165ed621e 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package common type MachineNode struct { diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go index ebbc060b5e485364ea1acf2dc981db3014233f8f..7c0313de7f6dab129229a7b473587088010b28e7 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: wubijie + * Date: Thu Jan 11 20:24:26 2024 +0800 + */ package common type Permission struct { diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go index 8c6144536e7ae5d19ea9033bcc791c5f9c1c7601..fbf5ae7316a17a2adcb74ff114eed31964c46657 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: Gzx1999 + * Date: Wed Oct 11 16:18:11 2023 +0800 + */ package common type AsyncCmdResult struct { diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/service.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/service.go index 2e9dde094d9982d45b76394fcffcf2549f92cecf..ac4ad730c85965947fddb5e1c9dd7f7e1c14d8d1 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/service.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/service.go @@ -1,70 +1,65 @@ -package common - -import "encoding/json" - -const ( - ServiceActiveStatusRunning = "running" - ServiceActiveStatusExited = "exited" - ServiceActiveStatusWaiting = "waiting" - ServiceActiveStatusInactive = "inactive" - ServiceActiveStatusUnknown = "unknown" - - ServiceLoadedStatusEnabled = "enabled" - ServiceLoadedStatusDisabled = "disabled" - ServiceLoadedStatusStatic = "static" - ServiceLoadedStatusMask = "mask" - ServiceLoadedStatusUnknown = "unknown" -) - -const ( - ServiceUnit = "service" - SocketUnit = "socket" - TargetUnit = "target" - MountUnit = "mount" - AutomountUnit = "automount" - PathUnit = "path" - TimeUnit = "time" -) - -type ServiceResult struct { - MachineUUID string - MachineIP string - ServiceSample ServiceInfo -} - -type ServiceInfo struct { - ServiceName string - UnitName string - UnitType string - ServicePath string //配置文件放置的目录 - ServiceAfter string //在什么服务启动后启动 - ServiceBefore string //在什么服务启动前启动 - ServiceRequires string //需要的daemon - ServiceWants string //与requires相反 - ServiceEnvironmentFile string //启动脚本的环境配置文件 - ServiceExectStart string //实际执行daemon的指令或脚本程序 - ServiceActiveStatus string - ServiceLoadedStatus string - StartTime string -} - -type ServiceStruct struct { - Batch *Batch `json:"batch"` - ServiceName string `json:"service"` -} - -type Result struct { - Code int `json:"code"` - Mseeage string `json:"msg"` - Data []*ServiceResult `json:"data"` -} - -type CommonResult struct { - Code int `json:"code"` - Message string `json:"msg"` - Data json.RawMessage `json:"data"` -} - -func (r *CommonResult) ParseData(d interface{}) error { - return json.Unmarshal(r.Data, d) -} +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ +package common + +const ( + ServiceActiveStatusRunning = "running" + ServiceActiveStatusExited = "exited" + ServiceActiveStatusWaiting = "waiting" + ServiceActiveStatusInactive = "inactive" + ServiceActiveStatusUnknown = "unknown" + + ServiceLoadedStatusEnabled = "enabled" + ServiceLoadedStatusDisabled = "disabled" + ServiceLoadedStatusStatic = "static" + ServiceLoadedStatusMask = "mask" + ServiceLoadedStatusUnknown = "unknown" +) + +const ( + ServiceUnit = "service" + SocketUnit = "socket" + TargetUnit = "target" + MountUnit = "mount" + AutomountUnit = "automount" + PathUnit = "path" + TimeUnit = "time" +) + +type ServiceResult struct { + MachineUUID string + MachineIP string + ServiceSample ServiceInfo +} + +type ServiceInfo struct { + ServiceName string + UnitName string + UnitType string + ServicePath string //配置文件放置的目录 + ServiceAfter string //在什么服务启动后启动 + ServiceBefore string //在什么服务启动前启动 + ServiceRequires string //需要的daemon + ServiceWants string //与requires相反 + ServiceEnvironmentFile string //启动脚本的环境配置文件 + ServiceExectStart string //实际执行daemon的指令或脚本程序 + ServiceActiveStatus string + ServiceLoadedStatus string + StartTime string +} + +type ServiceStruct struct { + Batch *Batch `json:"batch"` + ServiceName string `json:"service"` +} + +type Result struct { + Code int `json:"code"` + Mseeage string `json:"msg"` + Data []*ServiceResult `json:"data"` +} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/status.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/status.go index 5d0cd8c3335befaa745710983b2ee19635be8336..2e6cef40b203d8d09caee6f378e492d7831e4b13 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/status.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/status.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ // 提供公共数据结构定义 package common diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/tag.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/tag.go index dab5e54e80dada87daeb21e496225366a3c406e9..5f8de3ab85ead78c4e40a6ed54d12e8d51039f2e 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/tag.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/tag.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: wubijie + * Date: Thu Nov 2 16:38:53 2023 +0800 + */ package common const ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go b/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go index 6854d6fe42a98f93f49eaa54fb851968af88a8a2..aad3575be8844055f0ef4f2ce6148013cb406253 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go @@ -1,17 +1,10 @@ -/****************************************************************************** - * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved. - * PilotGo is licensed under the Mulan PSL v2. - * You can use this software accodring to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - * Author: yangzhao1 - * Date: 2022-03-01 09:59:30 - * LastEditTime: 2022-04-05 11:37:16 - * Description: provide agent log manager of pilotgo - ******************************************************************************/ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package logger import ( @@ -26,7 +19,7 @@ import ( type LogOpts struct { Level string `yaml:"level"` - Driver string `yaml:"driver"` + Driver string `yaml:"driver" comment:"可选stdout和file.stdout:输出到终端控制台;file:输出到path下的指定文件。"` Path string `yaml:"path"` MaxFile int `yaml:"max_file"` MaxSize int `yaml:"max_size"` @@ -120,41 +113,45 @@ func Fatal(format string, args ...interface{}) { logrus.Fatalf(format, args...) } -func RequestLogger() gin.HandlerFunc { +func RequestLogger(_skipPaths []string) gin.HandlerFunc { + var skip map[string]struct{} + if len(_skipPaths) > 0 { + skip = make(map[string]struct{}, len(_skipPaths)) + + for _, path := range _skipPaths { + skip[path] = struct{}{} + } + } return func(c *gin.Context) { - // 开始时间 - startTime := time.Now() + start := time.Now() + path := c.Request.URL.Path + raw := c.Request.URL.RawQuery - // 处理请求 c.Next() - // 结束时间 - endTime := time.Now() - - // 执行时间 - latencyTime := endTime.Sub(startTime) - - // 请求方式 - reqMethod := c.Request.Method - - // 请求路由 - reqUri := c.Request.RequestURI - - // 状态码 - statusCode := c.Writer.Status() - - // 请求IP - clientIP := c.ClientIP() - - // 日志格式 - if reqUri != "/api/v1/pluginapi/heartbeat" && reqUri != "/plugin/prometheus/target" { - Debug("status_code:%d latency_time:%s client_ip:%s req_method:%s req_uri:%s", + if _, ok := skip[path]; !ok { + endTime := time.Now() + latency := endTime.Sub(start) + method := c.Request.Method + statusCode := c.Writer.Status() + clientIP := c.ClientIP() + errorMessage := c.Errors.ByType(gin.ErrorTypePrivate).String() + + if raw != "" { + path = path + "?" + raw + } + if latency > time.Minute { + latency = latency.Truncate(time.Second) + } + + Debug("%s status_code:%3d latency_time:%-13v client_ip:%-15s method:%-7s req_uri:%#v\n%s", + start.Format("2006-01-02 15:04:05"), statusCode, - latencyTime, + latency, clientIP, - reqMethod, - reqUri, - ) + method, + path, + errorMessage) } } } diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go index 088761aab7d49d209415d1e3db0e7036f718de7f..70f1f99af2eb036a5ef9cc12b2f5afdf95fcc3dc 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Fri Jan 19 11:08:30 2024 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go index f73f97cd488d06e9d837aedd7f3b631182352508..83145caa4361716f06a51d5cd1894d9221fae895 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: wubijie + * Date: Wed Dec 27 19:38:17 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go index 5c936d4b5b96aa864406e05dee319dbf92ea300b..dcae6b878882762a634396cf9558ea866257821f 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( @@ -23,8 +30,8 @@ type Client struct { token string // 用于event消息处理 - eventChan chan *common.EventMessage - eventCallbackMap map[int]EventCallback + EventChan chan *common.EventMessage + EventCallbackMap map[int]common.EventCallback // 用于异步command及script执行结果处理机 asyncCmdResultChan chan *common.AsyncCmdResult @@ -50,8 +57,8 @@ func DefaultClient(desc *PluginInfo) *Client { global_client = &Client{ PluginInfo: desc, - eventChan: make(chan *common.EventMessage, 20), - eventCallbackMap: make(map[int]EventCallback), + EventChan: make(chan *common.EventMessage, 20), + EventCallbackMap: make(map[int]common.EventCallback), asyncCmdResultChan: make(chan *common.AsyncCmdResult, 20), cmdProcessorCallbackMap: make(map[string]CallbackHandler), @@ -90,10 +97,6 @@ func (client *Client) RegisterHandlers(router *gin.Engine) { c.Set("__internal__client_instance", client) }, tagsHandler) - api.POST("/event", func(c *gin.Context) { - c.Set("__internal__client_instance", client) - }, eventHandler) - api.PUT("/command_result", func(c *gin.Context) { c.Set("__internal__client_instance", client) }, commandResultHandler) @@ -108,7 +111,7 @@ func (client *Client) RegisterHandlers(router *gin.Engine) { // } // TODO: start command result process service - client.startEventProcessor() + // client.startEventProcessor() client.startCommandResultProcessor() } diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go index 643bb9bac0c527c14200e24d6919daf89417bbc9..41add3e37a4b5520f18a77919a44bfa4de4ab04f 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go deleted file mode 100644 index 8d76833b10b5aff0da075e92c16bb5f7edb2198b..0000000000000000000000000000000000000000 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go +++ /dev/null @@ -1,160 +0,0 @@ -package client - -import ( - "encoding/json" - "errors" - "net/http" - "strconv" - "strings" - - "gitee.com/openeuler/PilotGo/sdk/common" - "gitee.com/openeuler/PilotGo/sdk/utils/httputils" -) - -type EventCallback func(e *common.EventMessage) - -// 注册event事件监听 -func (c *Client) ListenEvent(eventTypes []int, callbacks []EventCallback) error { - var eventtypes []string - for _, i := range eventTypes { - eventtypes = append(eventtypes, strconv.Itoa(i)) - } - - url := c.Server() + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") - r, err := httputils.Put(url, &httputils.Params{ - Body: c.PluginInfo, - Cookie: map[string]string{ - TokenCookie: c.token, - }, - }) - if err != nil { - return err - } - if r.StatusCode != http.StatusOK { - return errors.New("server process error:" + strconv.Itoa(r.StatusCode)) - } - - resp := &common.CommonResult{} - if err := json.Unmarshal(r.Body, resp); err != nil { - return err - } - if resp.Code != http.StatusOK { - return errors.New(resp.Message) - } - - data := &struct { - Status string `json:"status"` - Error string `json:"error"` - }{} - if err := resp.ParseData(data); err != nil { - return err - } - for i, eventType := range eventTypes { - c.registerEventCallback(eventType, callbacks[i]) - } - return nil -} - -// 取消注册event事件监听 -func (c *Client) UnListenEvent(eventTypes []int) error { - var eventtypes []string - for _, i := range eventTypes { - eventtypes = append(eventtypes, strconv.Itoa(i)) - } - - url := c.Server() + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") - r, err := httputils.Delete(url, &httputils.Params{ - Body: c.PluginInfo, - Cookie: map[string]string{ - TokenCookie: c.token, - }, - }) - if err != nil { - return err - } - if r.StatusCode != http.StatusOK { - return errors.New("server process error:" + strconv.Itoa(r.StatusCode)) - } - - resp := &common.CommonResult{} - if err := json.Unmarshal(r.Body, resp); err != nil { - return err - } - if resp.Code != http.StatusOK { - return errors.New(resp.Message) - } - - data := &struct { - Status string `json:"status"` - Error string `json:"error"` - }{} - if err := resp.ParseData(data); err != nil { - return err - } - - for _, eventType := range eventTypes { - c.unregisterEventCallback(eventType) - } - return nil -} - -// 发布event事件 -func (c *Client) PublishEvent(msg common.EventMessage) error { - url := c.Server() + "/api/v1/pluginapi/publish_event" - r, err := httputils.Put(url, &httputils.Params{ - Body: &msg, - Cookie: map[string]string{ - TokenCookie: c.token, - }, - }) - if err != nil { - return err - } - if r.StatusCode != http.StatusOK { - return errors.New("server process error:" + strconv.Itoa(r.StatusCode)) - } - - resp := &common.CommonResult{} - if err := json.Unmarshal(r.Body, resp); err != nil { - return err - } - if resp.Code != http.StatusOK { - return errors.New(resp.Message) - } - - data := &struct { - Status string `json:"status"` - Error string `json:"error"` - }{} - if err := resp.ParseData(data); err != nil { - return err - } - return nil -} - -func (c *Client) registerEventCallback(eventType int, callback EventCallback) { - c.eventCallbackMap[eventType] = callback -} - -func (c *Client) unregisterEventCallback(eventType int) { - delete(c.eventCallbackMap, eventType) -} - -func (c *Client) ProcessEvent(event *common.EventMessage) { - c.eventChan <- event -} - -func (c *Client) startEventProcessor() { - go func() { - for { - e := <-c.eventChan - - // TODO: process event message - cb, ok := c.eventCallbackMap[e.MessageType] - if ok { - cb(e) - } - } - }() - -} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go index a0d233efcc79d4531f37b35a1270315f67882f53..1f7955035ebd2c3514e1fad54e01576fcac27a09 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: Gzx1999 + * Date: Tue Nov 7 15:01:17 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/fileservice.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/fileservice.go index fe67a8f37518e9244a651e4686a1d38153a9648c..3fe24a816e0537968ed1346189eb39e98544a0af 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/fileservice.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/fileservice.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Tue Mar 12 15:33:09 2024 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go index b8c9def763e9a5dbcd95c5ff326f86c0ec615859..d8e1389a1f5fc70c84e5eb149236ea9c39581f33 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( @@ -85,30 +92,6 @@ func bindHandler(c *gin.Context) { response.Success(c, nil, "bind server success") } -func eventHandler(c *gin.Context) { - j, err := io.ReadAll(c.Request.Body) // 接收数据 - if err != nil { - logger.Error("没获取到:%s", err.Error()) - return - } - var msg common.EventMessage - if err := json.Unmarshal(j, &msg); err != nil { - logger.Error("反序列化结果失败%s", err.Error()) - return - } - - v, ok := c.Get("__internal__client_instance") - if !ok { - return - } - client, ok := v.(*Client) - if !ok { - return - } - - client.ProcessEvent(&msg) -} - func commandResultHandler(c *gin.Context) { j, err := io.ReadAll(c.Request.Body) // 接收数据 if err != nil { diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go index fa1fb9ce81f7a12f5afdea91406b783284d6bf1b..f4aedd3fb935c943b76e25c2c1ffa2041ec598af 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Mon Dec 18 10:57:09 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go index 94043cfcfc3e9b22a4954c01c263ae6167738d9f..85bc2294a9d7c74967750ee19357de2d56dc65aa 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go index 155b66e6463ee8c8320fbe6342d61456d45b937b..10352de3b1ec4769d199042f46a6debe87b96ab8 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: wubijie + * Date: Thu Jan 11 20:24:26 2024 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go index e878f3323da4e8e8bdf0a22eb2aae84eb7b5e6bf..3fb88227a327003a9b9860144f6f227df52ddac4 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( @@ -10,12 +17,14 @@ import ( // 用于初始化Client type PluginInfo struct { + MenuName string `json:"menuName"` Name string `json:"name"` Version string `json:"version"` Description string `json:"description"` Author string `json:"author"` Email string `json:"email"` Url string `json:"url"` + Icon string `json:"icon"` PluginType string `json:"plugin_type"` ReverseDest string `json:"reverse_dest"` } @@ -27,11 +36,11 @@ type PluginFullInfo struct { Permissions []common.Permission } -func (c *Client) GetPluginInfo(name string) (*PluginInfo, error) { +func (c *Client) GetPlugins() ([]*PluginInfo, error) { if !c.IsBind() { return nil, errors.New("unbind PilotGo-server platform") } - url := c.Server() + "/api/v1/pluginapi/plugins" + url := "http://" + c.Server() + "/api/v1/pluginapi/plugins" r, err := httputils.Get(url, &httputils.Params{ Cookie: map[string]string{ TokenCookie: c.token, @@ -41,10 +50,13 @@ func (c *Client) GetPluginInfo(name string) (*PluginInfo, error) { return nil, err } - resp := &PluginInfo{} - if err := json.Unmarshal(r.Body, resp); err != nil { + resp := struct { + Code int `json:"code"` + Data []*PluginInfo `json:"data"` + }{} + if err := json.Unmarshal(r.Body, &resp); err != nil { return nil, err } - return resp, nil + return resp.Data, nil } diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go index 2d28745e89f5bd2860e71201ec48976062f9d4b1..ccf9776b230ada7f7ef7d0ee88c5f1cf0287378a 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go index 29597123325bcb098ffe8740891162296ecea300..a2fe2c661aaf8f757ee66a2ba96f1d79dce2e338 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/response/response.go b/vendor/gitee.com/openeuler/PilotGo/sdk/response/response.go index ac0d707a0415f384a1fcc2c1ba610d3230c6aa23..25087d5382ec894a8b44a4f34889d3ec76fc92af 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/response/response.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/response/response.go @@ -1,7 +1,16 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package response import ( + "fmt" "net/http" + "reflect" "github.com/gin-gonic/gin" ) @@ -38,3 +47,40 @@ type PaginationQ struct { Data interface{} `json:"data" comment:"muster be a pointer of slice gorm.Model"` TotalSize int `json:"total"` } + +// 结构体分页查询方法 +func DataPaging(p *PaginationQ, list interface{}, total int) (interface{}, error) { + data := make([]interface{}, 0) + if reflect.TypeOf(list).Kind() == reflect.Slice { + s := reflect.ValueOf(list) + for i := 0; i < s.Len(); i++ { + ele := s.Index(i) + data = append(data, ele.Interface()) + } + } + if p.PageSize < 1 { + p.PageSize = 10 + } + if p.Page < 1 { + p.Page = 1 + } + if total == 0 { + p.TotalSize = 0 + } + num := p.PageSize * (p.Page - 1) + if num > total { + return nil, fmt.Errorf("页码超出") + } + if p.PageSize*p.Page > total { + return data[num:], nil + } else { + if p.PageSize*p.Page < num { + return nil, fmt.Errorf("读取错误") + } + if p.PageSize*p.Page == 0 { + return data, nil + } else { + return data[num : p.Page*p.PageSize], nil + } + } +} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/judgeProtocol.go b/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/judgeProtocol.go index 96d9f61c5311781fae5789d417fed20868f73b94..8b1c861022a7e0f0eb91021cc766c15ddea470c4 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/judgeProtocol.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/judgeProtocol.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: Wangjunqi123 + * Date: Wed Jun 12 14:00:31 2024 +0800 + */ package httputils import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go b/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go index c5b7689044cea8c2b109d30f057fda13c6a3c537..0f88478161c70289663638c0f43583f8edad1d7e 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package httputils import ( diff --git a/vendor/modules.txt b/vendor/modules.txt index 032fc2d434a410df4aa6340be88fce355cf31338..00f795871a773366eaef0b7a4fad7df245f0ec7d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# gitee.com/openeuler/PilotGo/sdk v0.0.0-20240711084602-e34bc1158484 +# gitee.com/openeuler/PilotGo/sdk v0.0.0-20241227025309-05f048f9c7d8 ## explicit; go 1.20 gitee.com/openeuler/PilotGo/sdk/common gitee.com/openeuler/PilotGo/sdk/logger diff --git a/web/vite.config.ts b/web/vite.config.ts index 6d13da8f752778ad018eb0dbdd2ee023ccf388b3..0525639a18fb0310a0d465b346e5b30a0e53a341 100755 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -2,7 +2,7 @@ * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. - * Author: Wangjunqi123 + * Author: zhao_zhen_fang * Date: Mon Oct 9 11:19:00 2023 +0800 */ import { fileURLToPath, URL } from 'node:url' @@ -28,14 +28,22 @@ export default defineConfig({ server:{ proxy:{ "/plugin/topology/api": { - target: 'http://10.41.107.29:9991', + target: 'http://127.0.0.1:9991', // target: 'http://10.44.55.72:9991', changeOrigin:true, + secure: false, // rewrite: (path)=> path.replace("/^\/api/", ""), }, + '/plugin/elk/api': { + target: 'https://10.41.107.29:9993', + secure: false, + changeOrigin: true, + rewrite: path => path.replace(/^\//, '') + }, "/plugin/prometheus/api/v1": { - target: 'http://10.44.55.72:8090', + target: 'https://10.41.161.101:8090', changeOrigin:true, + secure: false, // rewrite: (path)=> path.replace("/^\/api/", ""), } }