feat: OMC参数配置添加NE信令跟踪服务开关
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
traceService "be.ems/src/modules/trace/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -214,12 +215,17 @@ func (s NeConfigController) DataInfo(c *gin.Context) {
|
||||
}
|
||||
|
||||
if query.NeType == "OMC" {
|
||||
var o *cm_omc.ConfigOMC
|
||||
resData, err := o.Query(query.ParamName)
|
||||
if err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
if query.ParamName == "alarmEmailForward" || query.ParamName == "alarmSMSForward" {
|
||||
var o *cm_omc.ConfigOMC
|
||||
resData, err := o.Query(query.ParamName)
|
||||
if err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, resp.OkData(resData))
|
||||
return
|
||||
}
|
||||
resData := s.neConfigService.GetOMCYaml(query.ParamName)
|
||||
c.JSON(200, resp.OkData(resData))
|
||||
return
|
||||
}
|
||||
@@ -268,13 +274,26 @@ func (s NeConfigController) DataEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if body.NeType == "OMC" {
|
||||
var o *cm_omc.ConfigOMC
|
||||
resData, err := o.Modify(body.ParamName, body.ParamData)
|
||||
if body.ParamName == "alarmEmailForward" || body.ParamName == "alarmSMSForward" {
|
||||
var o *cm_omc.ConfigOMC
|
||||
resData, err := o.Modify(body.ParamName, body.ParamData)
|
||||
if err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, resp.OkData(resData))
|
||||
return
|
||||
}
|
||||
err := s.neConfigService.ModifyOMCYaml(body.ParamName, body.Loc, body.ParamData)
|
||||
if err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, resp.OkData(resData))
|
||||
// 重开跟踪任务信令数据通道UDP
|
||||
if body.ParamName == "trace" {
|
||||
traceService.NewTraceTask.CreateUDP(true)
|
||||
}
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
56
src/modules/network_element/service/ne_config_omc.go
Normal file
56
src/modules/network_element/service/ne_config_omc.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/cmd"
|
||||
"be.ems/src/framework/config"
|
||||
)
|
||||
|
||||
// GetOMCYaml 获取OMC网元配置文件 /usr/local/etc/omc/omc.yaml
|
||||
func (r NeConfig) GetOMCYaml(paramName string) []map[string]any {
|
||||
if paramName == "trace" {
|
||||
traceData := config.Get("trace").(map[string]any)
|
||||
return []map[string]any{traceData}
|
||||
}
|
||||
return []map[string]any{}
|
||||
}
|
||||
|
||||
// ModifyOMCYaml 修改OMC网元配置文件 /usr/local/etc/omc/omc.yaml
|
||||
func (r NeConfig) ModifyOMCYaml(paramName, loc string, paramData any) error {
|
||||
neConfig := r.FindByNeTypeAndParamName("OMC", paramName)
|
||||
if neConfig.ParamType == "list" {
|
||||
if paramName == "trace" {
|
||||
configPath := fmt.Sprint(config.Get("config")) // 获取配置文件路径
|
||||
paramDataMap := paramData.(map[string]any)
|
||||
for k, v := range paramDataMap {
|
||||
config.Set(fmt.Sprintf("trace.%s", strings.ToLower(k)), v)
|
||||
if runtime.GOOS == "windows" {
|
||||
continue // Windows系统不支持sed命令
|
||||
}
|
||||
// 修改参数较少,直接命令改文件内容
|
||||
if k == "enabled" {
|
||||
// sed 's/enabled: \(true\|false\) # trace enabled/enabled: true # trace enabled/' /usr/local/etc/omc/omc.yaml
|
||||
cmd.Execf("sed -i 's/enabled: \\(true\\|false\\) # trace enabled/enabled: %v # trace enabled/' %s", v, configPath)
|
||||
}
|
||||
if k == "host" {
|
||||
// sed 's/host: ".*" # trace host/host: "127.2.2.2" # trace host/' /usr/local/etc/omc/omc.yaml
|
||||
cmd.Execf("sed -i 's/host: \".*\" # trace host/host: \"%v\" # trace host/' %s", v, configPath)
|
||||
}
|
||||
if k == "port" {
|
||||
// sed 's/port: [0-9]\+ # trace port/port: 6964 # trace port/' /usr/local/etc/omc/omc.yaml
|
||||
cmd.Execf("sed -i 's/port: [0-9]\\+ # trace port/port: %v # trace port/' %s", v, configPath)
|
||||
}
|
||||
}
|
||||
// 重开跟踪任务信令数据通道UDP
|
||||
// service.NewTraceTask.CreateUDP(true) 方法导致循环引用,抛给上层调用
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if neConfig.ParamType == "array" {
|
||||
// TODO
|
||||
}
|
||||
return fmt.Errorf("not found method paramName")
|
||||
}
|
||||
Reference in New Issue
Block a user