diff --git a/src/modules/tool/controller/ping.go b/src/modules/tool/controller/ping.go index 3f3f5b44..aa70e036 100644 --- a/src/modules/tool/controller/ping.go +++ b/src/modules/tool/controller/ping.go @@ -81,6 +81,28 @@ func (s *PingController) StatisticsOn(c *gin.Context) { } } +// ping 网元端版本信息 +// +// GET /v +func (s *PingController) Version(c *gin.Context) { + language := ctx.AcceptLanguage(c) + var query struct { + NeType string `form:"neType" binding:"required"` // 网元类型 + NeID string `form:"neId" binding:"required"` // 网元ID + } + if err := c.ShouldBindQuery(&query); err != nil { + c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) + return + } + + output, err := s.pingService.Version(query.NeType, query.NeID) + if err != nil { + c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error()))) + return + } + c.JSON(200, result.OkData(output)) +} + // ping 网元端UNIX运行 // // GET /run @@ -128,7 +150,7 @@ func (s *PingController) Run(c *gin.Context) { wsClient := s.wsService.ClientCreate(loginUser.UserID, nil, wsConn, clientSession) go s.wsService.ClientWriteListen(wsClient) - go s.wsService.ClientReadListen(wsClient, s.pingService.RunNE) + go s.wsService.ClientReadListen(wsClient, s.pingService.Run) // 等待1秒,排空首次消息 time.Sleep(1 * time.Second) diff --git a/src/modules/tool/service/iperf.go b/src/modules/tool/service/iperf.go index 84ec00b6..75ffaaeb 100644 --- a/src/modules/tool/service/iperf.go +++ b/src/modules/tool/service/iperf.go @@ -23,15 +23,8 @@ type IPerf struct{} // Version 查询版本信息 func (s *IPerf) Version(meType, neId string) (string, error) { - // 网元主机的SSH客户端 - sshClient, err := neService.NewNeInfo.NeRunSSHClient(meType, neId) - if err != nil { - return "", err - } - defer sshClient.Close() - // 检查是否安装iperf3 - output, err := sshClient.RunCMD("iperf3 --version") + output, err := neService.NewNeInfo.NeRunSSHCmd(meType, neId, "iperf3 --version") if err != nil { return "", fmt.Errorf("iperf3 not installed") } diff --git a/src/modules/tool/service/ping.go b/src/modules/tool/service/ping.go index 1ce9b016..79f51a2a 100644 --- a/src/modules/tool/service/ping.go +++ b/src/modules/tool/service/ping.go @@ -10,6 +10,7 @@ import ( "be.ems/src/framework/logger" "be.ems/src/framework/utils/ssh" "be.ems/src/framework/vo/result" + neService "be.ems/src/modules/network_element/service" "be.ems/src/modules/tool/model" wsModel "be.ems/src/modules/ws/model" probing "github.com/prometheus-community/pro-bing" @@ -134,8 +135,18 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest) } } -// RunNE 接收ping终端交互业务处理 -func (s *Ping) RunNE(client *wsModel.WSClient, reqMsg wsModel.WSRequest) { +// Version 查询版本信息 +func (s *Ping) Version(meType, neId string) (string, error) { + // 检查是否安装ping + output, err := neService.NewNeInfo.NeRunSSHCmd(meType, neId, "ping -V") + if err != nil { + return "", fmt.Errorf("ping not installed") + } + return strings.TrimSpace(output), err +} + +// Run 接收ping终端交互业务处理 +func (s *Ping) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) { // 必传requestId确认消息 if reqMsg.RequestID == "" { msg := "message requestId is required" diff --git a/src/modules/tool/tool.go b/src/modules/tool/tool.go index 7a92d1d9..70385683 100644 --- a/src/modules/tool/tool.go +++ b/src/modules/tool/tool.go @@ -44,6 +44,10 @@ func Setup(router *gin.Engine) { collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.ping", collectlogs.BUSINESS_TYPE_OTHER)), controller.NewPing.StatisticsOn, ) + pingGroup.GET("/v", + middleware.PreAuthorize(nil), + controller.NewPing.Version, + ) pingGroup.GET("/run", middleware.PreAuthorize(nil), collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.ping", collectlogs.BUSINESS_TYPE_OTHER)),