1
0

feat: 合并代码

This commit is contained in:
TsMask
2023-10-27 09:40:53 +08:00
parent 08a908c3f4
commit 955aba902b
26 changed files with 1057 additions and 53 deletions

View File

@@ -12,11 +12,10 @@ import (
// Setup 模块路由注册
func Setup(router *gin.Engine) {
logger.Infof("开始加载 ====> monitor 模块路由")
logger.Infof("开始加载 ====> crontask 模块路由")
// 启动时需要的初始参数
// 初始定时任务队列
InitCronQueue()
}
// InitCronQueue 初始定时任务队列

View File

@@ -0,0 +1,39 @@
package controller
import (
"ems.agt/src/framework/vo/result"
netElementService "ems.agt/src/modules/net_element/service"
"github.com/gin-gonic/gin"
)
// 实例化控制层 NeInfoController 结构体
var NewNeInfo = &NeInfoController{
NeInfoService: netElementService.NewNeInfoImpl,
}
// 网元信息请求
//
// PATH /ne-info
type NeInfoController struct {
// 网元信息服务
NeInfoService netElementService.INeInfo
}
// 网元neType和neID查询
//
// GET /info
func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
neType := c.Query("neType")
neId := c.Query("neId")
if neType == "" || neId == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
return
}
data := s.NeInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
if data.NeType == neType {
c.JSON(200, result.OkData(data))
return
}
c.JSON(200, result.Err(nil))
}

View File

@@ -0,0 +1,19 @@
package model
// NeInfo 网元信息对象
type NeInfo struct {
ID int64 `json:"id"`
NeType string `json:"neType"`
NeId string `json:"neId"`
RmUID string `json:"rmUid"`
NeName string `json:"neName"`
IP string `json:"ip"`
Port int64 `json:"port"`
PvFlag string `json:"pvFlag"` // enum('PNF','VNF')
Province string `json:"province"`
VendorName string `json:"vendorName"`
Dn string `json:"dn"`
NeAddress string `json:"neAddress"`
Status string `json:"status"` // 0: 在线 1: 下线 2: 备用 3: 工程
UpdateTime string `json:"updateTime"`
}

View File

@@ -0,0 +1,23 @@
package netelement
import (
"ems.agt/src/framework/logger"
"ems.agt/src/framework/middleware"
"ems.agt/src/modules/net_element/controller"
"github.com/gin-gonic/gin"
)
// 模块路由注册
func Setup(router *gin.Engine) {
logger.Infof("开始加载 ====> net_element 模块路由")
// 网元信息
netInfoGroup := router.Group("/ne-info")
{
netInfoGroup.GET("/info",
middleware.PreAuthorize(nil),
controller.NewNeInfo.NeTypeAndID,
)
}
}

View File

@@ -0,0 +1,11 @@
package repository
import (
"ems.agt/src/modules/net_element/model"
)
// 网元信息 数据层接口
type INeInfo interface {
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo
}

View File

@@ -0,0 +1,69 @@
package repository
import (
"ems.agt/src/framework/datasource"
"ems.agt/src/framework/logger"
"ems.agt/src/framework/utils/repo"
"ems.agt/src/modules/net_element/model"
)
// 实例化数据层 NeInfoImpl 结构体
var NewNeInfoImpl = &NeInfoImpl{
selectSql: `select id, ne_type, ne_id, rm_uid, ne_name, ip, port, pv_flag, province, vendor_name, dn, ne_address, status, update_time from ne_info`,
resultMap: map[string]string{
"id": "ID",
"ne_type": "NeType",
"ne_id": "NeId",
"rm_uid": "RmUID",
"ne_name": "NeName",
"ip": "IP",
"port": "Port",
"pv_flag": "PvFlag",
"province": "Province",
"vendor_name": "VendorName",
"dn": "Dn",
"ne_address": "NeAddress",
"status": "Status",
"update_time": "UpdateTime",
},
}
// NeInfoImpl 网元信息表 数据层处理
type NeInfoImpl struct {
// 查询视图对象SQL
selectSql string
// 结果字段与实体映射
resultMap map[string]string
}
// convertResultRows 将结果记录转实体结果组
func (r *NeInfoImpl) convertResultRows(rows []map[string]any) []model.NeInfo {
arr := make([]model.NeInfo, 0)
for _, row := range rows {
item := model.NeInfo{}
for key, value := range row {
if keyMapper, ok := r.resultMap[key]; ok {
repo.SetFieldValue(&item, keyMapper, value)
}
}
arr = append(arr, item)
}
return arr
}
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
querySql := r.selectSql + " where ne_type = ? and ne_id = ?"
results, err := datasource.RawDB("", querySql, []any{neType, neID})
if err != nil {
logger.Errorf("query err => %v", err)
return model.NeInfo{}
}
// 转换实体
rows := r.convertResultRows(results)
if len(rows) > 0 {
return rows[0]
}
return model.NeInfo{}
}

View File

@@ -0,0 +1,9 @@
package service
import "ems.agt/src/modules/net_element/model"
// 网元信息 服务层接口
type INeInfo interface {
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo
}

View File

@@ -0,0 +1,22 @@
package service
import (
"ems.agt/src/modules/net_element/model"
"ems.agt/src/modules/net_element/repository"
)
// 实例化服务层 NeInfoImpl 结构体
var NewNeInfoImpl = &NeInfoImpl{
NeInfoRepository: repository.NewNeInfoImpl,
}
// 网元信息 服务层处理
type NeInfoImpl struct {
// 网元信息数据信息
NeInfoRepository repository.INeInfo
}
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
func (r *NeInfoImpl) SelectNeInfoByNeTypeAndNeID(neType, neID string) model.NeInfo {
return r.NeInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
}

View File

@@ -400,10 +400,11 @@ func (s *SysUserController) Export(c *gin.Context) {
"E1": "手机号码",
"F1": "用户性别",
"G1": "帐号状态",
"H1": "最后登录IP",
"I1": "最后登录时间",
"J1": "部门名称",
"K1": "部门负责人",
"H1": "部门编号",
"I1": "部门名称",
"J1": "部门负责人",
"K1": "最后登录IP",
"L1": "最后登录时间",
}
// 读取用户性别字典数据
dictSysUserSex := s.sysDictDataService.SelectDictDataByType("sys_user_sex")
@@ -432,10 +433,11 @@ func (s *SysUserController) Export(c *gin.Context) {
"E" + idx: row.PhoneNumber,
"F" + idx: sysUserSex,
"G" + idx: statusValue,
"H" + idx: row.LoginIP,
"I" + idx: date.ParseDateToStr(row.LoginDate, date.YYYY_MM_DD_HH_MM_SS),
"J" + idx: row.Dept.DeptName,
"K" + idx: row.Dept.Leader,
"H" + idx: row.Dept.DeptID,
"I" + idx: row.Dept.DeptName,
"J" + idx: row.Dept.Leader,
"K" + idx: row.LoginIP,
"L" + idx: date.ParseDateToStr(row.LoginDate, date.YYYY_MM_DD_HH_MM_SS),
})
}
@@ -455,7 +457,23 @@ func (s *SysUserController) Export(c *gin.Context) {
func (s *SysUserController) Template(c *gin.Context) {
fileName := fmt.Sprintf("user_import_template_%d.xlsx", time.Now().UnixMilli())
asserPath := "assets/template/excel/user_import_template.xlsx"
c.FileAttachment(asserPath, fileName)
// 从 embed.FS 中读取默认配置文件内容
assetsDir := config.GetAssetsDirFS()
// 读取内嵌文件
fileData, err := assetsDir.ReadFile(asserPath)
if err != nil {
c.String(500, "Failed to read file")
return
}
// 设置响应头
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", fileName))
c.Header("Content-Type", "application/octet-stream")
// 返回响应体
c.Data(200, "application/octet-stream", fileData)
}
// 用户信息列表导入

View File

@@ -198,7 +198,7 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
failureNum := 0
successMsgArr := []string{}
failureMsgArr := []string{}
mustItemArr := []string{"C", "D"}
mustItemArr := []string{"B", "C"}
for _, row := range rows {
// 检查必填列
ownItem := true
@@ -218,13 +218,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
// 用户性别转值
sysUserSex := "0"
for _, v := range dictSysUserSex {
if row["G"] == v.DictLabel {
if row["F"] == v.DictLabel {
sysUserSex = v.DictValue
break
}
}
sysUserStatus := common.STATUS_NO
if row["H"] == "正常" {
if row["G"] == "正常" {
sysUserStatus = common.STATUS_YES
}
@@ -232,11 +232,11 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
newSysUser := model.SysUser{
UserType: "sys",
Password: initPassword,
DeptID: row["B"],
UserName: row["C"],
NickName: row["D"],
PhoneNumber: row["F"],
Email: row["E"],
DeptID: row["H"],
UserName: row["B"],
NickName: row["C"],
PhoneNumber: row["E"],
Email: row["D"],
Status: sysUserStatus,
Sex: sysUserSex,
}
@@ -246,13 +246,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
if regular.ValidMobile(newSysUser.PhoneNumber) {
uniquePhone := r.CheckUniquePhone(newSysUser.PhoneNumber, "")
if !uniquePhone {
msg := fmt.Sprintf("序号:%s 手机号码 %s 已存在", row["A"], row["F"])
msg := fmt.Sprintf("序号:%s 手机号码 %s 已存在", row["A"], row["E"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
}
} else {
msg := fmt.Sprintf("序号:%s 手机号码 %s 格式错误", row["A"], row["F"])
msg := fmt.Sprintf("序号:%s 手机号码 %s 格式错误", row["A"], row["E"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
@@ -264,13 +264,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
if regular.ValidEmail(newSysUser.Email) {
uniqueEmail := r.CheckUniqueEmail(newSysUser.Email, "")
if !uniqueEmail {
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 已存在", row["A"], row["E"])
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 已存在", row["A"], row["D"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
}
} else {
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 格式错误", row["A"], row["E"])
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 格式错误", row["A"], row["D"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
@@ -283,11 +283,11 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
newSysUser.CreateBy = operName
insertId := r.InsertUser(newSysUser)
if insertId != "" {
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入成功", row["A"], row["C"])
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入成功", row["A"], row["B"])
successNum++
successMsgArr = append(successMsgArr, msg)
} else {
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入失败", row["A"], row["E"])
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入失败", row["A"], row["B"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
}
@@ -300,11 +300,11 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
newSysUser.UpdateBy = operName
rows := r.UpdateUser(newSysUser)
if rows > 0 {
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新成功", row["A"], row["C"])
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新成功", row["A"], row["B"])
successNum++
successMsgArr = append(successMsgArr, msg)
} else {
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新失败", row["A"], row["E"])
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新失败", row["A"], row["B"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
}

View File

@@ -0,0 +1,262 @@
package controller
import (
"fmt"
"strings"
"ems.agt/src/framework/cmd"
"ems.agt/src/framework/config"
"ems.agt/src/framework/utils/ssh"
"ems.agt/src/framework/vo/result"
netElementService "ems.agt/src/modules/net_element/service"
traceService "ems.agt/src/modules/trace/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 TcpdumpController 结构体
var NewTcpdump = &TcpdumpController{
NeInfoService: netElementService.NewNeInfoImpl,
TcpdumpService: traceService.NewTcpdumpImpl,
}
// 信令抓包请求
//
// PATH /tcpdump
type TcpdumpController struct {
// 网元信息服务
NeInfoService netElementService.INeInfo
// 信令抓包服务
TcpdumpService traceService.ITcpdump
}
// 网元发送执行 pcap
//
// POST /ne
func (s *TcpdumpController) NeTask(c *gin.Context) {
var body struct {
NeType string `json:"neType" binding:"required"` // 网元类型
NeId string `json:"neId" binding:"required"` // 网元ID
Timeout int `json:"timeout" binding:"required"` // 超时时间
Cmd string `json:"cmd" binding:"required"` // 命令
Timestamp string `json:"timestamp" binding:"required"` // 时间戳
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
c.JSON(400, result.CodeMsg(400, "参数错误"))
return
}
// 检查网元信息
neInfo := s.NeInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId {
msg := fmt.Sprintf("找不到 %s %s 对应网元信息", body.NeType, body.NeId)
c.JSON(200, result.ErrMsg(msg))
return
}
filePcapName := fmt.Sprintf("%s_%s_%s.pcap", body.Timestamp, body.NeType, body.NeId)
fileLogName := fmt.Sprintf("%s_%s_%s.log", body.Timestamp, body.NeType, body.NeId)
writeLog := fmt.Sprintf(" > %s 2>&1 \ncat %s", fileLogName, fileLogName) // 执行信息写入日志文件放置弹出code 127
cmdStr := fmt.Sprintf("cd /tmp \nsudo timeout %d tcpdump -i any %s -s0 -w %s", body.Timeout, body.Cmd, filePcapName)
usernameNe := config.Get("ne.user").(string) // 网元统一用户
sshHost := fmt.Sprintf("%s@%s", usernameNe, neInfo.IP)
msg, err := cmd.ExecWithCheck("ssh", sshHost, cmdStr+writeLog)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(map[string]any{
"cmd": cmdStr,
"msg": msg,
"fileName": filePcapName,
}))
}
// 网元抓包pcap文件下载
//
// POST /download
func (s *TcpdumpController) Download(c *gin.Context) {
var body struct {
NeType string `json:"neType" binding:"required"` // 网元类型
NeId string `json:"neId" binding:"required"` // 网元ID
FileName string `form:"fileName" ` // 文件名
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
c.JSON(400, result.CodeMsg(400, "参数错误"))
return
}
// 检查网元信息
neInfo := s.NeInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId {
msg := fmt.Sprintf("找不到 %s %s 对应网元信息", body.NeType, body.NeId)
c.JSON(200, result.ErrMsg(msg))
return
}
nePath := fmt.Sprintf("/tmp/%s", body.FileName)
localPath := fmt.Sprintf("%s/tcpdump/%s", config.Get("ne.scpdir"), body.FileName)
err = ssh.FileSCPNeToLocal(neInfo.IP, nePath, localPath)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
c.FileAttachment(localPath, body.FileName)
}
// 网元发送执行 pcap
//
// POST /neUPF
func (s *TcpdumpController) NeUPFTask(c *gin.Context) {
var body struct {
NeType string `json:"neType" binding:"required"` // 网元类型
NeId string `json:"neId" binding:"required"` // 网元ID
RunType string `json:"runType" binding:"required"` // 执行开始start还是停止stop
Cmd string `json:"cmd" binding:"required"` // 命令
Timestamp string `json:"timestamp" binding:"required"` // 时间戳
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
c.JSON(400, result.CodeMsg(400, "参数错误"))
return
}
// 检查网元信息
neInfo := s.NeInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
if neInfo.NeId != body.NeId {
msg := fmt.Sprintf("找不到 %s %s 对应网元信息", body.NeType, body.NeId)
c.JSON(200, result.ErrMsg(msg))
return
}
// 开始telnet
if body.RunType == "start_telnet" {
filePcapName := fmt.Sprintf("%s_%s_%s.pcap", body.Timestamp, body.NeType, body.NeId)
cmdStr := fmt.Sprintf("%s file %s", body.Cmd, filePcapName)
// 进行连接telnet
resultStr, err := s.TcpdumpService.UPFTelnet(neInfo.IP, cmdStr)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
// 处理结果
s := strings.Index(resultStr, "pcap dispatch trace:")
if s == -1 {
s = strings.Index(resultStr, "Write ")
}
if s != -1 {
e := strings.Index(resultStr, "\r\nupfd1#")
resultStr = resultStr[s:e]
} else {
resultStr = "No stoppable found"
}
c.JSON(200, result.OkData(map[string]any{
"cmd": cmdStr,
"msg": resultStr,
"fileName": filePcapName,
}))
return
}
// 停止telnet
if body.RunType == "stop_telnet" {
filePcapName := fmt.Sprintf("%s_%s_%s.pcap", body.Timestamp, body.NeType, body.NeId)
cmdStr := "pcap dispatch trace off"
// 进行连接telnet
resultStr, err := s.TcpdumpService.UPFTelnet(neInfo.IP, cmdStr)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
// 处理结果
s := strings.Index(resultStr, "pcap dispatch trace:")
if s != -1 {
e := strings.Index(resultStr, "\r\nupfd1#")
resultStr = resultStr[s:e]
} else {
resultStr = "Executed, please stop before proceeding"
}
c.JSON(200, result.OkData(map[string]any{
"cmd": cmdStr,
"msg": resultStr,
"fileName": filePcapName,
}))
return
}
// 开始-脚本字符串
if body.RunType == "start_str" {
fileLogName := fmt.Sprintf("%s_%s_%s.log", body.Timestamp, body.NeType, body.NeId)
filePcapName := fmt.Sprintf("%s_%s_%s.pcap", body.Timestamp, body.NeType, body.NeId)
scriptStr := "set capcmd [lindex $argv 0]\nspawn telnet localhost 5002\nexpect \"upfd1# \"\nsend \"$capcmd\\n\"\nexpect \"upfd1# \"\nsend \"quit\\n\"\nexpect \"eof\""
writeLog := fmt.Sprintf(" > %s 2>&1 \ncat %s", fileLogName, fileLogName) // 执行信息写入日志文件输出避免弹出code 127
capCmdStr := fmt.Sprintf("%s file %s", body.Cmd, filePcapName)
cmdStr := fmt.Sprintf("cd /tmp\n\necho '%s' > cap.sh\n\nchmod +x cap.sh\n\nexpect ./cap.sh '%s'%s", scriptStr, capCmdStr, writeLog)
usernameNe := config.Get("ne.user").(string) // 网元统一用户
sshHost := fmt.Sprintf("%s@%s", usernameNe, neInfo.IP)
msg, err := cmd.ExecWithCheck("ssh", sshHost, cmdStr)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
s := strings.Index(msg, "pcap dispatch trace:")
if s != -1 {
e := strings.Index(msg, "\r\nupfd1#")
msg = msg[s:e]
} else {
msg = "Executed, please stop before proceeding"
}
c.JSON(200, result.OkData(map[string]any{
"cmd": capCmdStr,
"msg": msg,
"fileName": filePcapName,
}))
return
}
// 停止-脚本字符串
if body.RunType == "stop_str" {
fileLogName := fmt.Sprintf("%s_%s_%s.log", body.Timestamp, body.NeType, body.NeId)
filePcapName := fmt.Sprintf("%s_%s_%s.pcap", body.Timestamp, body.NeType, body.NeId)
scriptStr := "set capcmd [lindex $argv 0]\nspawn telnet localhost 5002\nexpect \"upfd1# \"\nsend \"$capcmd\\n\"\nexpect \"upfd1# \"\nsend \"quit\\n\"\nexpect \"eof\""
writeLog := fmt.Sprintf(" > %s 2>&1 \ncat %s", fileLogName, fileLogName) // 执行信息写入日志文件输出避免弹出code 127
capCmdStr := body.Cmd
cmdStr := fmt.Sprintf("cd /tmp\n\necho '%s' > cap.sh\n\nchmod +x cap.sh\n\nexpect ./cap.sh '%s'%s", scriptStr, capCmdStr, writeLog)
usernameNe := config.Get("ne.user").(string) // 网元统一用户
sshHost := fmt.Sprintf("%s@%s", usernameNe, neInfo.IP)
msg, err := cmd.ExecWithCheck("ssh", sshHost, cmdStr)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
s := strings.Index(msg, "pcap dispatch trace:")
if s == -1 {
s = strings.Index(msg, "Write ")
// 停止写入的文件名
startIndex := strings.LastIndex(msg, "/") + 1
endIndex := strings.LastIndex(msg, ",")
filePcapName = msg[startIndex:endIndex]
}
if s != -1 {
e := strings.Index(msg, "\r\nupfd1#")
msg = msg[s:e]
} else {
msg = "No stoppable found"
}
c.JSON(200, result.OkData(map[string]any{
"cmd": capCmdStr,
"msg": msg,
"fileName": filePcapName,
}))
return
}
c.JSON(200, result.ErrMsg("请选择RunType执行start_telnet/stop_telnet/start_str/stop_str"))
}

View File

@@ -0,0 +1,7 @@
package service
// 通用请求 服务层接口
type ITcpdump interface {
// UPFTelnetStart UPF进行telnet抓包
UPFTelnet(neIp, cmdStr string) (string, error)
}

View File

@@ -0,0 +1,41 @@
package service
import (
"fmt"
"net"
"time"
netElementService "ems.agt/src/modules/net_element/service"
)
// 实例化服务层 TcpdumpImpl 结构体
var NewTcpdumpImpl = &TcpdumpImpl{
neInfoService: netElementService.NewNeInfoImpl,
}
// 通用请求 服务层处理
type TcpdumpImpl struct {
// 网元信息服务
neInfoService netElementService.INeInfo
}
// UPFTelnetStart UPF进行telnet抓包
func (s *TcpdumpImpl) UPFTelnet(neIp, cmdStr string) (string, error) {
// 创建TCP连接
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", neIp, 5002))
if err != nil {
return "", err
}
defer conn.Close()
fmt.Fprintln(conn, cmdStr)
// 读取内容
time.Sleep(time.Duration(300) * time.Millisecond)
buf := make([]byte, 1024*8)
n, err := conn.Read(buf)
if err != nil {
return "", err
}
return string(buf[0:n]), nil
}

View File

@@ -0,0 +1,35 @@
package trace
import (
"ems.agt/src/framework/logger"
"ems.agt/src/framework/middleware"
"ems.agt/src/framework/middleware/collectlogs"
"ems.agt/src/modules/trace/controller"
"github.com/gin-gonic/gin"
)
// 模块路由注册
func Setup(router *gin.Engine) {
logger.Infof("开始加载 ====> trace 模块路由")
// 信令抓包
tcpdumpGroup := router.Group("/tcpdump")
{
tcpdumpGroup.POST("/ne",
middleware.PreAuthorize(nil),
collectlogs.OperateLog(collectlogs.OptionNew("信令抓包", collectlogs.BUSINESS_TYPE_OTHER)),
controller.NewTcpdump.NeTask,
)
tcpdumpGroup.POST("/neUPF",
middleware.PreAuthorize(nil),
collectlogs.OperateLog(collectlogs.OptionNew("信令抓包", collectlogs.BUSINESS_TYPE_OTHER)),
controller.NewTcpdump.NeUPFTask,
)
tcpdumpGroup.POST("/download",
middleware.PreAuthorize(nil),
collectlogs.OperateLog(collectlogs.OptionNew("信令抓包", collectlogs.BUSINESS_TYPE_IMPORT)),
controller.NewTcpdump.Download,
)
}
}