fix: 调整/tmp文件路径到/usr/local/omc

This commit is contained in:
TsMask
2025-06-11 18:31:10 +08:00
parent 2fc70a58ba
commit e35287e8c1
5 changed files with 86 additions and 78 deletions

View File

@@ -10,11 +10,11 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"be.ems/src/framework/i18n" "be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx" "be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/ssh"
"be.ems/src/framework/utils/file" "be.ems/src/framework/utils/file"
"be.ems/src/framework/utils/generate" "be.ems/src/framework/utils/generate"
"be.ems/src/framework/utils/ssh"
"be.ems/src/framework/vo/result"
neService "be.ems/src/modules/network_element/service" neService "be.ems/src/modules/network_element/service"
) )
@@ -45,7 +45,7 @@ type NeActionController struct {
// @Description Sending files from local to network elements // @Description Sending files from local to network elements
// @Router /ne/action/pushFile [post] // @Router /ne/action/pushFile [post]
func (s *NeActionController) PushFile(c *gin.Context) { func (s *NeActionController) PushFile(c *gin.Context) {
language := ctx.AcceptLanguage(c) language := reqctx.AcceptLanguage(c)
var body struct { var body struct {
NeType string `json:"neType" binding:"required"` NeType string `json:"neType" binding:"required"`
NeID string `json:"neId" binding:"required"` NeID string `json:"neId" binding:"required"`
@@ -53,28 +53,29 @@ func (s *NeActionController) PushFile(c *gin.Context) {
DelTemp bool `json:"delTemp"` // 删除本地临时文件 DelTemp bool `json:"delTemp"` // 删除本地临时文件
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
// 查询网元获取IP // 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID) neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeID)
if neInfo.NeId != body.NeID || neInfo.IP == "" { if neInfo.NeId != body.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return return
} }
// 网元主机的SSH客户端 // 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId) sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
defer sshClient.Close() defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输 // 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP() sftpClient, err := sshClient.NewClientSFTP()
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
defer sftpClient.Close() defer sftpClient.Close()
@@ -82,11 +83,11 @@ func (s *NeActionController) PushFile(c *gin.Context) {
// 本地文件 // 本地文件
localFilePath := file.ParseUploadFilePath(body.UploadPath) localFilePath := file.ParseUploadFilePath(body.UploadPath)
// 网元端临时目录 // 网元端临时目录
sshClient.RunCMD("mkdir -p /tmp/omc/push && sudo chmod 777 -R /tmp/omc") sshClient.RunCMD("sudo mkdir -p /tmp/omc/push && sudo chmod 755 -R /tmp/omc")
neFilePath := filepath.ToSlash(filepath.Join("/tmp/omc/push", filepath.Base(localFilePath))) neFilePath := filepath.ToSlash(filepath.Join("/tmp/omc/push", filepath.Base(localFilePath)))
// 复制到远程 // 复制到远程
if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil { if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil {
c.JSON(200, result.ErrMsg("Please check if the file exists or if scp is allowed to copy remotely")) c.JSON(200, resp.ErrMsg("Please check if the file exists or if scp is allowed to copy remotely"))
return return
} }
@@ -95,7 +96,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
_ = os.Remove(localFilePath) _ = os.Remove(localFilePath)
} }
}() }()
c.JSON(200, result.OkData(filepath.ToSlash(neFilePath))) c.JSON(200, resp.OkData(filepath.ToSlash(neFilePath)))
} }
// 从网元到本地获取文件 // 从网元到本地获取文件
@@ -105,7 +106,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
// @Tags network_element/action // @Tags network_element/action
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF) // @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF)
// @Param neId query string true "NE ID" default(001) // @Param neId query string true "NE ID" default(001)
// @Param path query string true "dir path" default(/var/log) // @Param path query string true "dir path" default(/var/log)
// @Param fileName query string true "file name" // @Param fileName query string true "file name"
@@ -116,7 +117,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
// @Description Getting files from the network element to the local // @Description Getting files from the network element to the local
// @Router /ne/action/pullFile [get] // @Router /ne/action/pullFile [get]
func (s *NeActionController) PullFile(c *gin.Context) { func (s *NeActionController) PullFile(c *gin.Context) {
language := ctx.AcceptLanguage(c) language := reqctx.AcceptLanguage(c)
var querys struct { var querys struct {
NeType string `form:"neType" binding:"required"` NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"` NeID string `form:"neId" binding:"required"`
@@ -125,28 +126,29 @@ func (s *NeActionController) PullFile(c *gin.Context) {
DelTemp bool `form:"delTemp"` // 删除本地临时文件 DelTemp bool `form:"delTemp"` // 删除本地临时文件
} }
if err := c.ShouldBindQuery(&querys); err != nil { if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
// 查询网元获取IP // 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID) neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" { if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return return
} }
// 网元主机的SSH客户端 // 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId) sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
defer sshClient.Close() defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输 // 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP() sftpClient, err := sshClient.NewClientSFTP()
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
defer sftpClient.Close() defer sftpClient.Close()
@@ -159,7 +161,7 @@ func (s *NeActionController) PullFile(c *gin.Context) {
} }
// 复制到本地 // 复制到本地
if err = sftpClient.CopyFileRemoteToLocal(nePath, localFilePath); err != nil { if err = sftpClient.CopyFileRemoteToLocal(nePath, localFilePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
@@ -178,7 +180,7 @@ func (s *NeActionController) PullFile(c *gin.Context) {
// @Tags network_element/action // @Tags network_element/action
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF) // @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF)
// @Param neId query string true "NE ID" default(001) // @Param neId query string true "NE ID" default(001)
// @Param path query string true "dir path" default(/var/log) // @Param path query string true "dir path" default(/var/log)
// @Param delTemp query boolean false "Delete Temp File" default(false) // @Param delTemp query boolean false "Delete Temp File" default(false)
@@ -188,7 +190,7 @@ func (s *NeActionController) PullFile(c *gin.Context) {
// @Description Get directories compressed to ZIP from the network element to the local area // @Description Get directories compressed to ZIP from the network element to the local area
// @Router /ne/action/pullDirZip [get] // @Router /ne/action/pullDirZip [get]
func (s *NeActionController) PullDirZip(c *gin.Context) { func (s *NeActionController) PullDirZip(c *gin.Context) {
language := ctx.AcceptLanguage(c) language := reqctx.AcceptLanguage(c)
var querys struct { var querys struct {
NeType string `form:"neType" binding:"required"` NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"` NeID string `form:"neId" binding:"required"`
@@ -196,28 +198,29 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
DelTemp bool `form:"delTemp"` // 删除本地临时文件 DelTemp bool `form:"delTemp"` // 删除本地临时文件
} }
if err := c.ShouldBindQuery(&querys); err != nil { if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
// 查询网元获取IP // 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID) neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" { if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return return
} }
// 网元主机的SSH客户端 // 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId) sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
defer sshClient.Close() defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输 // 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP() sftpClient, err := sshClient.NewClientSFTP()
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
defer sftpClient.Close() defer sftpClient.Close()
@@ -231,7 +234,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
// 复制到本地 // 复制到本地
localDirFilePath := filepath.Join(localFilePath, "zip") localDirFilePath := filepath.Join(localFilePath, "zip")
if err = sftpClient.CopyDirRemoteToLocal(nePath, localDirFilePath); err != nil { if err = sftpClient.CopyDirRemoteToLocal(nePath, localDirFilePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
@@ -239,7 +242,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
zipFileName := fmt.Sprintf("%s-%s-%s.zip", neInfo.NeType, neInfo.NeId, dirName) zipFileName := fmt.Sprintf("%s-%s-%s.zip", neInfo.NeType, neInfo.NeId, dirName)
zipFilePath := filepath.Join(localFilePath, zipFileName) zipFilePath := filepath.Join(localFilePath, zipFileName)
if err := file.CompressZipByDir(zipFilePath, localDirFilePath); err != nil { if err := file.CompressZipByDir(zipFilePath, localDirFilePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
@@ -258,7 +261,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
// @Tags network_element/action // @Tags network_element/action
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF) // @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF)
// @Param neId query string true "NE ID" default(001) // @Param neId query string true "NE ID" default(001)
// @Param path query string true "file path" default(/var/log) // @Param path query string true "file path" default(/var/log)
// @Param fileName query string true "file name" // @Param fileName query string true "file name"
@@ -268,7 +271,7 @@ func (s *NeActionController) PullDirZip(c *gin.Context) {
// @Description Viewing the contents of a file on the network element side // @Description Viewing the contents of a file on the network element side
// @Router /ne/action/viewFile [get] // @Router /ne/action/viewFile [get]
func (s *NeActionController) ViewFile(c *gin.Context) { func (s *NeActionController) ViewFile(c *gin.Context) {
language := ctx.AcceptLanguage(c) language := reqctx.AcceptLanguage(c)
var querys struct { var querys struct {
NeType string `form:"neType" binding:"required"` NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"` NeID string `form:"neId" binding:"required"`
@@ -276,21 +279,22 @@ func (s *NeActionController) ViewFile(c *gin.Context) {
FileName string `form:"fileName" binding:"required"` FileName string `form:"fileName" binding:"required"`
} }
if err := c.ShouldBindQuery(&querys); err != nil { if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
// 查询网元获取IP // 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID) neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" { if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return return
} }
// 网元主机的SSH客户端 // 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId) sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
defer sshClient.Close() defer sshClient.Close()
@@ -301,10 +305,10 @@ func (s *NeActionController) ViewFile(c *gin.Context) {
output, err := sshClient.RunCMD(fmt.Sprintf("cat %s", nePath)) output, err := sshClient.RunCMD(fmt.Sprintf("cat %s", nePath))
output = strings.TrimSpace(output) output = strings.TrimSpace(output)
if err != nil || strings.HasPrefix(output, "ls: ") { if err != nil || strings.HasPrefix(output, "ls: ") {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "file view cat error"))) c.JSON(200, resp.ErrMsg(i18n.TKey(language, "file view cat error")))
return return
} }
c.JSON(200, result.OkData(output)) c.JSON(200, resp.OkData(output))
} }
// 网元端文件列表 // 网元端文件列表
@@ -314,7 +318,7 @@ func (s *NeActionController) ViewFile(c *gin.Context) {
// @Tags network_element/action // @Tags network_element/action
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC) default(UPF) // @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(UPF)
// @Param neId query string true "NE ID" default(001) // @Param neId query string true "NE ID" default(001)
// @Param path query string true "file path" default(/var/log) // @Param path query string true "file path" default(/var/log)
// @Param pageNum query number true "pageNum" default(1) // @Param pageNum query number true "pageNum" default(1)
@@ -326,7 +330,7 @@ func (s *NeActionController) ViewFile(c *gin.Context) {
// @Description List of files on the network element side // @Description List of files on the network element side
// @Router /ne/action/files [get] // @Router /ne/action/files [get]
func (s *NeActionController) Files(c *gin.Context) { func (s *NeActionController) Files(c *gin.Context) {
language := ctx.AcceptLanguage(c) language := reqctx.AcceptLanguage(c)
var querys struct { var querys struct {
NeType string `form:"neType" binding:"required"` NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"` NeID string `form:"neId" binding:"required"`
@@ -336,21 +340,22 @@ func (s *NeActionController) Files(c *gin.Context) {
Search string `form:"search"` Search string `form:"search"`
} }
if err := c.ShouldBindQuery(&querys); err != nil { if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
// 查询网元获取IP // 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID) neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" { if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return return
} }
// 网元主机的SSH客户端 // 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId) sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
defer sshClient.Close() defer sshClient.Close()
@@ -358,7 +363,7 @@ func (s *NeActionController) Files(c *gin.Context) {
// 获取文件列表 // 获取文件列表
rows, err := ssh.FileList(sshClient, querys.Path, querys.Search) rows, err := ssh.FileList(sshClient, querys.Path, querys.Search)
if err != nil { if err != nil {
c.JSON(200, result.Ok(map[string]any{ c.JSON(200, resp.OkData(map[string]any{
"path": querys.Path, "path": querys.Path,
"total": len(rows), "total": len(rows),
"rows": []ssh.FileListRow{}, "rows": []ssh.FileListRow{},
@@ -379,7 +384,7 @@ func (s *NeActionController) Files(c *gin.Context) {
splitRows = rows[start:end] splitRows = rows[start:end]
} }
c.JSON(200, result.Ok(map[string]any{ c.JSON(200, resp.OkData(map[string]any{
"path": querys.Path, "path": querys.Path,
"total": lenNum, "total": lenNum,
"rows": splitRows, "rows": splitRows,
@@ -400,21 +405,22 @@ func (s *NeActionController) Files(c *gin.Context) {
// @Description Network element service operation // @Description Network element service operation
// @Router /ne/action/service [put] // @Router /ne/action/service [put]
func (s *NeActionController) Service(c *gin.Context) { func (s *NeActionController) Service(c *gin.Context) {
language := ctx.AcceptLanguage(c) language := reqctx.AcceptLanguage(c)
var body struct { var body struct {
NeType string `json:"neType" binding:"required"` NeType string `json:"neType" binding:"required"`
NeID string `json:"neId" binding:"required"` NeID string `json:"neId" binding:"required"`
Action string `json:"action" binding:"required,oneof=start restart stop reboot poweroff"` // 操作行为 Action string `json:"action" binding:"required,oneof=start restart stop reboot poweroff"` // 操作行为
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
// 查询网元获取IP // 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID) neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeID)
if neInfo.NeId != body.NeID || neInfo.IP == "" { if neInfo.NeId != body.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return return
} }
@@ -439,8 +445,8 @@ func (s *NeActionController) Service(c *gin.Context) {
_, err := s.neInfoService.NeRunSSHCmd(body.NeType, body.NeID, cmdStr) _, err := s.neInfoService.NeRunSSHCmd(body.NeType, body.NeID, cmdStr)
if err != nil { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, resp.ErrMsg(err.Error()))
return return
} }
c.JSON(200, result.Ok(nil)) c.JSON(200, resp.Ok(nil))
} }

View File

@@ -75,7 +75,7 @@ func (r *NeConfigBackup) DeleteByIds(ids []string) (int64, error) {
func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string) error { func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string) error {
neTypeLower := strings.ToLower(neInfo.NeType) neTypeLower := strings.ToLower(neInfo.NeType)
// 网管本地路径 // 网管本地路径
omcPath := "/usr/local/etc/omc/ne_config" omcPath := "/usr/local/omc/backup/ne_config"
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
omcPath = fmt.Sprintf("C:%s", omcPath) omcPath = fmt.Sprintf("C:%s", omcPath)
} }
@@ -99,7 +99,7 @@ func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string
// 网元配置端上的临时目录 // 网元配置端上的临时目录
neDirTemp := fmt.Sprintf("/tmp/omc/ne_config/%s/%s", neTypeLower, neInfo.NeId) neDirTemp := fmt.Sprintf("/tmp/omc/ne_config/%s/%s", neTypeLower, neInfo.NeId)
sshClient.RunCMD(fmt.Sprintf("mkdir -p /tmp/omc && sudo chmod 777 -R /tmp/omc && sudo rm -rf %s", neDirTemp)) sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p /tmp/omc/ne_config && sudo chmod 755 -R /tmp/omc && sudo rm -rf %s", neDirTemp))
// 复制到网元端 // 复制到网元端
if err = sftpClient.CopyDirLocalToRemote(localDirPath, neDirTemp); err != nil { if err = sftpClient.CopyDirLocalToRemote(localDirPath, neDirTemp); err != nil {
return fmt.Errorf("copy config to ne err") return fmt.Errorf("copy config to ne err")
@@ -154,14 +154,14 @@ func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error)
neTypeLower := strings.ToLower(neInfo.NeType) neTypeLower := strings.ToLower(neInfo.NeType)
// 网管本地路径 // 网管本地路径
omcPath := "/usr/local/etc/omc/ne_config" omcPath := "/usr/local/omc/backup/ne_config"
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
omcPath = fmt.Sprintf("C:%s", omcPath) omcPath = fmt.Sprintf("C:%s", omcPath)
} }
localDirPath := fmt.Sprintf("%s/%s/%s/backup/tmp_export", omcPath, neTypeLower, neInfo.NeId) localDirPath := fmt.Sprintf("%s/%s/%s/from_ne_tmp", omcPath, neTypeLower, neInfo.NeId)
// 网元配置文件先复制到临时目录 // 网元配置文件先复制到临时目录
sshClient.RunCMD("mkdir -p /tmp/omc && sudo chmod 777 -R /tmp/omc") sshClient.RunCMD("sudo mkdir -p /tmp/omc/ne_config && sudo chmod 755 -R /tmp/omc")
neDirTemp := fmt.Sprintf("/tmp/omc/ne_config/%s/%s", neTypeLower, neInfo.NeId) neDirTemp := fmt.Sprintf("/tmp/omc/ne_config/%s/%s", neTypeLower, neInfo.NeId)
if neTypeLower == "ims" { if neTypeLower == "ims" {
// ims目录 // ims目录
@@ -196,7 +196,7 @@ func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error)
// 压缩zip文件名 // 压缩zip文件名
zipFileName := fmt.Sprintf("%s-%s-etc-%s.zip", neTypeLower, neInfo.NeId, date.ParseDateToStr(time.Now(), date.YYYYMMDDHHMMSS)) zipFileName := fmt.Sprintf("%s-%s-etc-%s.zip", neTypeLower, neInfo.NeId, date.ParseDateToStr(time.Now(), date.YYYYMMDDHHMMSS))
zipFilePath := fmt.Sprintf("%s/%s/%s/backup/%s", omcPath, neTypeLower, neInfo.NeId, zipFileName) zipFilePath := fmt.Sprintf("%s/%s/%s/%s", omcPath, neTypeLower, neInfo.NeId, zipFileName)
if err := file.CompressZipByDir(zipFilePath, localDirPath); err != nil { if err := file.CompressZipByDir(zipFilePath, localDirPath); err != nil {
return "", fmt.Errorf("compress zip err") return "", fmt.Errorf("compress zip err")
} }

View File

@@ -46,7 +46,7 @@ func (s *PacketController) Start(c *gin.Context) {
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs)) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
@@ -68,7 +68,7 @@ func (s *PacketController) Stop(c *gin.Context) {
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs)) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
@@ -90,7 +90,7 @@ func (s *PacketController) Filter(c *gin.Context) {
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs)) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
@@ -112,7 +112,7 @@ func (s *PacketController) KeepAlive(c *gin.Context) {
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs)) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
@@ -137,11 +137,11 @@ func (s *PacketController) FilePull(c *gin.Context) {
} }
if err := c.ShouldBindQuery(&querys); err != nil { if err := c.ShouldBindQuery(&querys); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs)) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
fileName := fmt.Sprintf("%s.pcap", querys.TaskNo) fileName := fmt.Sprintf("%s.pcap", querys.TaskNo)
localFilePath := filepath.Join("/tmp/omc/packet", fileName) localFilePath := filepath.Join("/usr/local/omc/packet", fileName)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
localFilePath = fmt.Sprintf("C:%s", localFilePath) localFilePath = fmt.Sprintf("C:%s", localFilePath)
} }

View File

@@ -36,10 +36,10 @@ type TraceTaskHlrController struct {
// //
// GET /list // GET /list
func (s *TraceTaskHlrController) List(c *gin.Context) { func (s *TraceTaskHlrController) List(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var query model.TraceTaskHlrQuery var query model.TraceTaskHlrQuery
if err := c.ShouldBindQuery(&query); err != nil { if err := c.ShouldBindQuery(&query); err != nil {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
@@ -54,7 +54,7 @@ func (s *TraceTaskHlrController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c) language := reqctx.AcceptLanguage(c)
id := c.Param("id") id := c.Param("id")
if id == "" { if id == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty")) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: id is empty"))
return return
} }
@@ -79,7 +79,6 @@ func (s *TraceTaskHlrController) Remove(c *gin.Context) {
// //
// POST /start // POST /start
func (s *TraceTaskHlrController) Start(c *gin.Context) { func (s *TraceTaskHlrController) Start(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct { var body struct {
IMSI string `json:"imsi"` // IMSI IMSI string `json:"imsi"` // IMSI
MSISDN string `json:"msisdn"` // MSISDN MSISDN string `json:"msisdn"` // MSISDN
@@ -88,12 +87,13 @@ func (s *TraceTaskHlrController) Start(c *gin.Context) {
Remark string `json:"remark"` // 备注说明 Remark string `json:"remark"` // 备注说明
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
if body.IMSI == "" && body.MSISDN == "" { if body.IMSI == "" && body.MSISDN == "" {
c.JSON(400, resp.CodeMsg(400, "imsi amd msisdn is empty")) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "imsi amd msisdn is empty"))
return return
} }
@@ -117,12 +117,12 @@ func (s *TraceTaskHlrController) Start(c *gin.Context) {
// //
// POST /stop // POST /stop
func (s *TraceTaskHlrController) Stop(c *gin.Context) { func (s *TraceTaskHlrController) Stop(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct { var body struct {
ID string `json:"id" binding:"required"` // 任务ID ID string `json:"id" binding:"required"` // 任务ID
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
@@ -162,13 +162,13 @@ func (s *TraceTaskHlrController) File(c *gin.Context) {
} }
if err := c.ShouldBindBodyWithJSON(&body); err != nil { if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs)) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
task := s.traceTaskHlrService.FindById(body.ID) task := s.traceTaskHlrService.FindById(body.ID)
if task.ID == 0 || task.ID != body.ID { if task.ID == 0 || task.ID != body.ID {
c.JSON(200, resp.CodeMsg(400, "task not found")) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "task not found"))
return return
} }
@@ -194,14 +194,14 @@ func (s *TraceTaskHlrController) FilePull(c *gin.Context) {
} }
if err := c.ShouldBindQuery(&querys); err != nil { if err := c.ShouldBindQuery(&querys); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err)) errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs)) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return return
} }
// 查询网元获取IP // 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID) neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" { if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, i18n.TKey(language, "app.common.noNEInfo")))
return return
} }

View File

@@ -119,7 +119,7 @@ func (s *Packet) LiveStart(taskNo, deviceName, filterBPF string, outputPCAP bool
var f *os.File var f *os.File
if outputPCAP { if outputPCAP {
// 网管本地路径 // 网管本地路径
localFilePath := fmt.Sprintf("/tmp/omc/packet/%s.pcap", taskNo) localFilePath := fmt.Sprintf("/usr/local/omc/packet/%s.pcap", taskNo)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
localFilePath = fmt.Sprintf("C:%s", localFilePath) localFilePath = fmt.Sprintf("C:%s", localFilePath)
} }
@@ -203,7 +203,9 @@ func (s *Packet) capturePacketSource(taskInfo *Task) {
if packet == nil { if packet == nil {
continue continue
} }
if packet.Metadata().Timestamp.Before(time.Now()) { // 如果延迟超过1秒跳过
timeDiff := time.Since(packet.Metadata().Timestamp)
if timeDiff > time.Second {
continue continue
} }