add: parameter config support alarm forward config
This commit is contained in:
100
config/param/omc_param_config.yaml
Normal file
100
config/param/omc_param_config.yaml
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
omc:
|
||||||
|
alarmEmailForward:
|
||||||
|
display: "Alarm Email Forward Interface"
|
||||||
|
sort: 3
|
||||||
|
list:
|
||||||
|
- name: "enable"
|
||||||
|
type: "bool"
|
||||||
|
value: "true"
|
||||||
|
access: "rw"
|
||||||
|
filter: "true;false"
|
||||||
|
display: "Enable"
|
||||||
|
comment: "Is it enabled forward alarm with Email interface"
|
||||||
|
- name: "emailList"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "Email List"
|
||||||
|
comment: ""
|
||||||
|
- name: "smtp"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "SMTP Server"
|
||||||
|
comment: "Email SMTP server"
|
||||||
|
- name: "port"
|
||||||
|
type: "int"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: "0~65535"
|
||||||
|
display: "Port"
|
||||||
|
comment: ""
|
||||||
|
- name: "user"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "User"
|
||||||
|
comment: ""
|
||||||
|
- name: "password"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "Password"
|
||||||
|
comment: ""
|
||||||
|
- name: "tlsSkipVerify"
|
||||||
|
type: "bool"
|
||||||
|
value: "true"
|
||||||
|
access: "rw"
|
||||||
|
filter: "true;false"
|
||||||
|
display: "TLS Skip Verify"
|
||||||
|
comment: "If skip TLS verify (true/false)"
|
||||||
|
alarmSMSForward:
|
||||||
|
display: "Alarm SMS Forward Interface"
|
||||||
|
sort: 4
|
||||||
|
list:
|
||||||
|
- name: "enable"
|
||||||
|
type: "bool"
|
||||||
|
value: "true"
|
||||||
|
access: "rw"
|
||||||
|
filter: "true;false"
|
||||||
|
display: "Enable"
|
||||||
|
comment: "Is it enabled forward alarm with SMS interface"
|
||||||
|
- name: "mobileList"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "Mobile List"
|
||||||
|
comment: ""
|
||||||
|
- name: "smscAddr"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "SMSC Address"
|
||||||
|
comment: "The SMSC SMPP Address"
|
||||||
|
- name: "systemID"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "System ID"
|
||||||
|
comment: ""
|
||||||
|
- name: "password"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "Password"
|
||||||
|
comment: ""
|
||||||
|
- name: "systemType"
|
||||||
|
type: "string"
|
||||||
|
value: ""
|
||||||
|
access: "rw"
|
||||||
|
filter: ""
|
||||||
|
display: "System Type"
|
||||||
|
comment: ""
|
||||||
46
features/cm/omc/controller.go
Normal file
46
features/cm/omc/controller.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package cm_omc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"be.ems/lib/services"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (o *ConfigOMC) Get(c *gin.Context) {
|
||||||
|
paramName := c.Param("paramName")
|
||||||
|
results, err := o.Query(paramName)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, services.DataResp(results))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ConfigOMC) Post(c *gin.Context) {
|
||||||
|
err := fmt.Errorf("method not allowed")
|
||||||
|
c.JSON(http.StatusMethodNotAllowed, services.ErrResp(err.Error()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ConfigOMC) Put(c *gin.Context) {
|
||||||
|
paramName := c.Param("paramName")
|
||||||
|
var paramData map[string]any
|
||||||
|
|
||||||
|
if err := c.ShouldBindJSON(¶mData); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := o.Modify(paramName, paramData)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, services.DataResp(result))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ConfigOMC) Delete(c *gin.Context) {
|
||||||
|
err := fmt.Errorf("method not allowed")
|
||||||
|
c.JSON(http.StatusMethodNotAllowed, services.ErrResp(err.Error()))
|
||||||
|
}
|
||||||
69
features/cm/omc/implement.go
Normal file
69
features/cm/omc/implement.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package cm_omc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"be.ems/restagent/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PASSWORD_MASK = "********"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (o *ConfigOMC) Query(paramName string) (any, error) {
|
||||||
|
var results []any
|
||||||
|
|
||||||
|
switch paramName {
|
||||||
|
case "alarmEmailForward":
|
||||||
|
result := config.GetYamlConfig().Alarm.EmailForward
|
||||||
|
result.Password = PASSWORD_MASK
|
||||||
|
results = append(results, result)
|
||||||
|
case "alarmSMSForward":
|
||||||
|
result := config.GetYamlConfig().Alarm.SMSCForward
|
||||||
|
result.Password = PASSWORD_MASK
|
||||||
|
results = append(results, result)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid source parameter")
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ConfigOMC) Add() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ConfigOMC) Modify(paramName string, paramData map[string]any) (any, error) {
|
||||||
|
var results []any
|
||||||
|
|
||||||
|
switch paramName {
|
||||||
|
case "alarmEmailForward":
|
||||||
|
param := &(config.GetYamlConfig().Alarm.EmailForward)
|
||||||
|
config.UpdateStructFromMap(param, paramData)
|
||||||
|
result := *param
|
||||||
|
results = append(results, result)
|
||||||
|
err := config.WriteOrignalConfig(config.YamlConfigInfo.FilePath, paramName, paramData)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("failed to write config yaml file:", err)
|
||||||
|
return results, err
|
||||||
|
}
|
||||||
|
case "alarmSMSForward":
|
||||||
|
param := &(config.GetYamlConfig().Alarm.SMSCForward)
|
||||||
|
config.UpdateStructFromMap(param, paramData)
|
||||||
|
result := *param
|
||||||
|
results = append(results, result)
|
||||||
|
err := config.WriteOrignalConfig(config.YamlConfigInfo.FilePath, paramName, paramData)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("failed to write config yaml file:", err)
|
||||||
|
return results, err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid source parameter")
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ConfigOMC) Remove() {
|
||||||
|
|
||||||
|
}
|
||||||
26
features/cm/omc/model.go
Normal file
26
features/cm/omc/model.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package cm_omc
|
||||||
|
|
||||||
|
type ConfigOMC struct{}
|
||||||
|
|
||||||
|
type SystemConfig struct {
|
||||||
|
ForwardFlag bool `json:"forwardFlag"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AlarmEmailForward struct {
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
EmailList string `json:"emailList"`
|
||||||
|
SMTP string `json:"smtp"`
|
||||||
|
Port uint16 `json:"port"`
|
||||||
|
User string `json:"user"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
TLSSkipVerify bool `json:"tlsSkipVerify"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AlarmSMSForward struct {
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
MobileList string `json:"mobileList"`
|
||||||
|
SMSCAddr string `json:"smscAddr"`
|
||||||
|
SystemID string `json:"systemID"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
SystemType string `json:"systemType"`
|
||||||
|
}
|
||||||
30
features/cm/omc/route.go
Normal file
30
features/cm/omc/route.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package cm_omc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"be.ems/src/framework/middleware"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register Routes for file_export
|
||||||
|
func Register(r *gin.RouterGroup) {
|
||||||
|
cmOMC := r.Group("/omc")
|
||||||
|
{
|
||||||
|
var o *ConfigOMC
|
||||||
|
cmOMC.GET("/config/:paramName",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
o.Get,
|
||||||
|
)
|
||||||
|
cmOMC.POST("/config/:paramName",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
o.Post,
|
||||||
|
)
|
||||||
|
cmOMC.PUT("/config/:paramName",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
o.Put,
|
||||||
|
)
|
||||||
|
cmOMC.DELETE("/config/:paramName",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
o.Delete,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
17
features/cm/service.go
Normal file
17
features/cm/service.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package cm
|
||||||
|
|
||||||
|
import (
|
||||||
|
cm_omc "be.ems/features/cm/omc"
|
||||||
|
"be.ems/lib/log"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitSubServiceRoute(r *gin.Engine) {
|
||||||
|
log.Info("======init PM group gin.Engine")
|
||||||
|
|
||||||
|
cmGroup := r.Group("/cm")
|
||||||
|
// register sub modules routes
|
||||||
|
cm_omc.Register(cmGroup)
|
||||||
|
|
||||||
|
// return featuresGroup
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package features
|
package features
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"be.ems/features/cm"
|
||||||
"be.ems/features/lm"
|
"be.ems/features/lm"
|
||||||
"be.ems/features/pm"
|
"be.ems/features/pm"
|
||||||
"be.ems/lib/log"
|
"be.ems/lib/log"
|
||||||
@@ -14,6 +15,7 @@ func InitServiceEngine(r *gin.Engine) {
|
|||||||
// 注册 各个features 模块的路由
|
// 注册 各个features 模块的路由
|
||||||
pm.InitSubServiceRoute(r)
|
pm.InitSubServiceRoute(r)
|
||||||
lm.InitSubServiceRoute(r)
|
lm.InitSubServiceRoute(r)
|
||||||
|
cm.InitSubServiceRoute(r)
|
||||||
|
|
||||||
// return featuresGroup
|
// return featuresGroup
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -466,10 +466,12 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
session.Commit()
|
session.Commit()
|
||||||
}
|
}
|
||||||
if config.GetYamlConfig().Alarm.ForwardAlarm {
|
if config.GetYamlConfig().Alarm.EmailForward.Enable {
|
||||||
if err = AlarmEmailForward(&alarmData); err != nil {
|
if err = AlarmEmailForward(&alarmData); err != nil {
|
||||||
log.Error("Failed to AlarmEmailForward:", err)
|
log.Error("Failed to AlarmEmailForward:", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if config.GetYamlConfig().Alarm.SMSCForward.Enable {
|
||||||
if err = AlarmSMSForward(&alarmData); err != nil {
|
if err = AlarmSMSForward(&alarmData); err != nil {
|
||||||
log.Error("Failed to AlarmSMSForward:", err)
|
log.Error("Failed to AlarmSMSForward:", err)
|
||||||
}
|
}
|
||||||
@@ -776,10 +778,12 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
session.Commit()
|
session.Commit()
|
||||||
if config.GetYamlConfig().Alarm.ForwardAlarm {
|
if config.GetYamlConfig().Alarm.EmailForward.Enable {
|
||||||
if err = AlarmEmailForward(&alarmData); err != nil {
|
if err = AlarmEmailForward(&alarmData); err != nil {
|
||||||
log.Error("Failed to AlarmEmailForward:", err)
|
log.Error("Failed to AlarmEmailForward:", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if config.GetYamlConfig().Alarm.SMSCForward.Enable {
|
||||||
if err = AlarmSMSForward(&alarmData); err != nil {
|
if err = AlarmSMSForward(&alarmData); err != nil {
|
||||||
log.Error("Failed to AlarmSMSForward:", err)
|
log.Error("Failed to AlarmSMSForward:", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package fm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -48,25 +47,25 @@ func AlarmEmailForward(alarmData *Alarm) error {
|
|||||||
// userName := "smtpext@agrandtech.com"
|
// userName := "smtpext@agrandtech.com"
|
||||||
// password := "1000smtp@omc!"
|
// password := "1000smtp@omc!"
|
||||||
|
|
||||||
host := config.GetYamlConfig().Alarm.Email.Smtp
|
host := config.GetYamlConfig().Alarm.EmailForward.SMTP
|
||||||
port := int(config.GetYamlConfig().Alarm.Email.Port)
|
port := int(config.GetYamlConfig().Alarm.EmailForward.Port)
|
||||||
userName := config.GetYamlConfig().Alarm.Email.User
|
userName := config.GetYamlConfig().Alarm.EmailForward.User
|
||||||
password := config.GetYamlConfig().Alarm.Email.Password
|
password := config.GetYamlConfig().Alarm.EmailForward.Password
|
||||||
|
|
||||||
m := gomail.NewMessage()
|
m := gomail.NewMessage()
|
||||||
m.SetHeader("From", userName) // 发件人
|
m.SetHeader("From", userName) // 发件人
|
||||||
//m.SetHeader("From", "alias"+"<"+"aliastest"+">") // 增加发件人别名
|
//m.SetHeader("From", "alias"+"<"+"aliastest"+">") // 增加发件人别名
|
||||||
|
|
||||||
emails, err := dborm.XormGetAlarmForward("Email")
|
// emails, err := dborm.XormGetAlarmForward("Email")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Error("Failed to XormGetAlarmForward:", err)
|
// log.Error("Failed to XormGetAlarmForward:", err)
|
||||||
return err
|
// return err
|
||||||
} else if emails == nil || len(*emails) == 0 {
|
// } else if emails == nil || len(*emails) == 0 {
|
||||||
err := errors.New("not found forward email list")
|
// err := errors.New("not found forward email list")
|
||||||
log.Error(err)
|
// log.Error(err)
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
emails := strings.Split(config.GetYamlConfig().Alarm.EmailForward.EmailList, ",")
|
||||||
forwardLog := &dborm.AlarmForwardLog{
|
forwardLog := &dborm.AlarmForwardLog{
|
||||||
NeType: alarmData.NeType,
|
NeType: alarmData.NeType,
|
||||||
NeID: alarmData.NeId,
|
NeID: alarmData.NeId,
|
||||||
@@ -74,10 +73,10 @@ func AlarmEmailForward(alarmData *Alarm) error {
|
|||||||
AlarmTitle: alarmData.AlarmTitle,
|
AlarmTitle: alarmData.AlarmTitle,
|
||||||
AlarmSeq: alarmData.AlarmSeq,
|
AlarmSeq: alarmData.AlarmSeq,
|
||||||
EventTime: alarmData.EventTime,
|
EventTime: alarmData.EventTime,
|
||||||
ToUser: strings.Join(*emails, ","),
|
ToUser: config.GetYamlConfig().Alarm.EmailForward.EmailList,
|
||||||
}
|
}
|
||||||
|
|
||||||
m.SetHeader("To", *emails...) // 收件人,可以多个收件人,但必须使用相同的 SMTP 连接
|
m.SetHeader("To", emails...) // 收件人,可以多个收件人,但必须使用相同的 SMTP 连接
|
||||||
//m.SetHeader("To", strings.Join(*emails, " ")) // 收件人,可以多个收件人,但必须使用相同的 SMTP 连接
|
//m.SetHeader("To", strings.Join(*emails, " ")) // 收件人,可以多个收件人,但必须使用相同的 SMTP 连接
|
||||||
//m.SetHeader("To", "zhangshuzhong@agrandtech.com", "simonzhangsz@outlook.com") // 收件人,可以多个收件人,但必须使用相同的 SMTP 连接
|
//m.SetHeader("To", "zhangshuzhong@agrandtech.com", "simonzhangsz@outlook.com") // 收件人,可以多个收件人,但必须使用相同的 SMTP 连接
|
||||||
//m.SetHeader("Cc", "******@qq.com") // 抄送,可以多个
|
//m.SetHeader("Cc", "******@qq.com") // 抄送,可以多个
|
||||||
@@ -103,7 +102,7 @@ func AlarmEmailForward(alarmData *Alarm) error {
|
|||||||
)
|
)
|
||||||
// 关闭SSL协议认证
|
// 关闭SSL协议认证
|
||||||
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
if !config.GetYamlConfig().Alarm.Email.TlsSkipVerify {
|
if !config.GetYamlConfig().Alarm.EmailForward.TLSSkipVerify {
|
||||||
// 打开SSL协议认证
|
// 打开SSL协议认证
|
||||||
d.TLSConfig = &tls.Config{InsecureSkipVerify: false}
|
d.TLSConfig = &tls.Config{InsecureSkipVerify: false}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,22 +99,23 @@ func AlarmForwardBySMS(alarmData *Alarm) (string, error) {
|
|||||||
func AlarmForwardBySMPP(alarmData *Alarm) (string, error) {
|
func AlarmForwardBySMPP(alarmData *Alarm) (string, error) {
|
||||||
log.Info("AlarmForwardBySMPP processing... ")
|
log.Info("AlarmForwardBySMPP processing... ")
|
||||||
|
|
||||||
toUsers, err := dborm.XormGetAlarmForward("SMS")
|
// toUsers, err := dborm.XormGetAlarmForward("SMS")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Error("Failed to XormGetAlarmForward:", err)
|
// log.Error("Failed to XormGetAlarmForward:", err)
|
||||||
return "", err
|
// return "", err
|
||||||
} else if toUsers == nil {
|
// } else if toUsers == nil {
|
||||||
err := errors.New("not found forward phone number")
|
// err := errors.New("not found forward phone number")
|
||||||
log.Error(err)
|
// log.Error(err)
|
||||||
return "", err
|
// return "", err
|
||||||
}
|
// }
|
||||||
userList := strings.Join(*toUsers, ",")
|
// userList := strings.Join(*toUsers, ",")
|
||||||
|
|
||||||
|
userList := config.GetYamlConfig().Alarm.SMSCForward.MobileList
|
||||||
auth := gosmpp.Auth{
|
auth := gosmpp.Auth{
|
||||||
SMSC: config.GetYamlConfig().Alarm.SMSC.Addr,
|
SMSC: config.GetYamlConfig().Alarm.SMSCForward.SMSCAddr,
|
||||||
SystemID: config.GetYamlConfig().Alarm.SMSC.SystemID,
|
SystemID: config.GetYamlConfig().Alarm.SMSCForward.SystemID,
|
||||||
Password: config.GetYamlConfig().Alarm.SMSC.Password,
|
Password: config.GetYamlConfig().Alarm.SMSCForward.Password,
|
||||||
SystemType: config.GetYamlConfig().Alarm.SMSC.SystemType,
|
SystemType: config.GetYamlConfig().Alarm.SMSCForward.SystemType,
|
||||||
}
|
}
|
||||||
|
|
||||||
// conn, err := gosmpp.NonTLSDialer(auth.SMSC)
|
// conn, err := gosmpp.NonTLSDialer(auth.SMSC)
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"be.ems/lib/global"
|
"be.ems/lib/global"
|
||||||
"be.ems/lib/log"
|
"be.ems/lib/log"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
//"github.com/go-yaml-comment/yaml"
|
||||||
|
//"github.com/goccy/go-yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Yaml struct of config
|
// Yaml struct of config
|
||||||
@@ -147,29 +151,34 @@ type DbConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AlarmConfig struct {
|
type AlarmConfig struct {
|
||||||
SplitEventAlarm bool `yaml:"splitEventAlarm"`
|
SplitEventAlarm bool `yaml:"splitEventAlarm"`
|
||||||
ForwardAlarm bool `yaml:"forwardAlarm"`
|
//ForwardAlarm bool `yaml:"forwardAlarm"`
|
||||||
SMProxy string `yaml:"smProxy"`
|
|
||||||
Email struct {
|
EmailForward struct {
|
||||||
Smtp string `yaml:"smtp"`
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
Port uint16 `yaml:"port"`
|
EmailList string `yaml:"emailList" json:"emailList"`
|
||||||
User string `yaml:"user"`
|
SMTP string `yaml:"smtp" json:"smtp"`
|
||||||
Password string `yaml:"password"`
|
Port uint16 `yaml:"port" json:"port"`
|
||||||
TlsSkipVerify bool `yaml:"tlsSkipVerify"`
|
User string `yaml:"user" json:"user"`
|
||||||
} `yaml:"email"`
|
Password string `yaml:"password" json:"password"`
|
||||||
|
TLSSkipVerify bool `yaml:"tlsSkipVerify" json:"tlsSkipVerify"`
|
||||||
|
} `yaml:"alarmEmailForward"`
|
||||||
|
SMSCForward struct {
|
||||||
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
|
MobileList string `yaml:"mobileList" json:"mobileList"`
|
||||||
|
SMSCAddr string `yaml:"smscAddr" json:"smscAddr"`
|
||||||
|
SystemID string `yaml:"systemID" json:"systemID"`
|
||||||
|
Password string `yaml:"password" json:"password"`
|
||||||
|
SystemType string `yaml:"systemType" json:"systemType"`
|
||||||
|
} `yaml:"alarmSMSForward"`
|
||||||
SMS struct {
|
SMS struct {
|
||||||
ApiURL string `yaml:"apiURL"`
|
ApiURL string `yaml:"apiURL"`
|
||||||
AccessKeyID string `yaml:"AccessKeyID"`
|
AccessKeyID string `yaml:"AccessKeyID"`
|
||||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||||
SignName string `yaml:"signName"`
|
SignName string `yaml:"signName"`
|
||||||
TemplateCode string `yaml:"templateCode"`
|
TemplateCode string `yaml:"templateCode"`
|
||||||
} `yaml:"sms"`
|
} `yaml:"smsForward"`
|
||||||
SMSC struct {
|
SMProxy string `yaml:"smProxy"`
|
||||||
Addr string `yaml:"addr"`
|
|
||||||
SystemID string `yaml:"systemID"`
|
|
||||||
Password string `yaml:"password"`
|
|
||||||
SystemType string `yaml:"systemType"`
|
|
||||||
} `yaml:"smsc"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MMLParam struct {
|
type MMLParam struct {
|
||||||
@@ -218,6 +227,16 @@ type TestDataMap struct {
|
|||||||
|
|
||||||
var yamlConfig YamlConfig = NewYamlConfig()
|
var yamlConfig YamlConfig = NewYamlConfig()
|
||||||
|
|
||||||
|
type YamlConfigFile struct {
|
||||||
|
FilePath string `json:"filePath"`
|
||||||
|
ConfigLines YamlConfig `json:"configLines"`
|
||||||
|
OrignalLines []string `json:"orignalLines"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var YamlConfigInfo YamlConfigFile = YamlConfigFile{
|
||||||
|
ConfigLines: NewYamlConfig(),
|
||||||
|
}
|
||||||
|
|
||||||
// set default value for yaml config
|
// set default value for yaml config
|
||||||
func NewYamlConfig() YamlConfig {
|
func NewYamlConfig() YamlConfig {
|
||||||
return YamlConfig{
|
return YamlConfig{
|
||||||
@@ -237,6 +256,8 @@ func NewYamlConfig() YamlConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ReadConfig(configFile string) {
|
func ReadConfig(configFile string) {
|
||||||
|
YamlConfigInfo.FilePath = configFile
|
||||||
|
|
||||||
yamlFile, err := os.ReadFile(configFile)
|
yamlFile, err := os.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Read yaml config file error:", err)
|
fmt.Println("Read yaml config file error:", err)
|
||||||
@@ -244,25 +265,85 @@ func ReadConfig(configFile string) {
|
|||||||
}
|
}
|
||||||
// fmt.Println("yamlfile:", string(yamlFile))
|
// fmt.Println("yamlfile:", string(yamlFile))
|
||||||
|
|
||||||
err = yaml.Unmarshal(yamlFile, &yamlConfig)
|
err = yaml.Unmarshal(yamlFile, &YamlConfigInfo.ConfigLines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unmarshal error:", err)
|
fmt.Println("Unmarshal error:", err)
|
||||||
os.Exit(3)
|
os.Exit(3)
|
||||||
}
|
}
|
||||||
|
yamlConfig = YamlConfigInfo.ConfigLines
|
||||||
|
|
||||||
|
ReadOriginalConfig(configFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteYamlConfig(newConfigData YamlConfig, configFile string) {
|
func ReadOriginalConfig(configFile string) {
|
||||||
|
// 读取原始YAML文件
|
||||||
|
inputFile, err := os.Open(configFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("failed to open:", err)
|
||||||
|
os.Exit(3)
|
||||||
|
}
|
||||||
|
defer inputFile.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(inputFile)
|
||||||
|
for scanner.Scan() {
|
||||||
|
YamlConfigInfo.OrignalLines = append(YamlConfigInfo.OrignalLines, scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
fmt.Println("failed to scanner:", err)
|
||||||
|
os.Exit(3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteOrignalConfig(configFile string, paramName string, paramData map[string]any) error {
|
||||||
|
lines := YamlConfigInfo.OrignalLines
|
||||||
|
for i, line := range lines {
|
||||||
|
if strings.Contains(line, paramName) {
|
||||||
|
for k, v := range paramData {
|
||||||
|
// find the first line nearby the paramName
|
||||||
|
for j := i + 1; j < len(lines); j++ {
|
||||||
|
if strings.Contains(lines[j], k+":") {
|
||||||
|
index := strings.Index(lines[j], k)
|
||||||
|
lines[j] = lines[j][:index] + fmt.Sprintf("%s: %v", k, v)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// write back to yaml file
|
||||||
|
outputFile, err := os.Create(configFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer outputFile.Close()
|
||||||
|
|
||||||
|
writer := bufio.NewWriter(outputFile)
|
||||||
|
for _, line := range YamlConfigInfo.OrignalLines {
|
||||||
|
writer.WriteString(line + "\n")
|
||||||
|
}
|
||||||
|
writer.Flush()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteYamlConfig(newConfigData YamlConfig, configFile string) error {
|
||||||
// 将配置转换回YAML数据
|
// 将配置转换回YAML数据
|
||||||
newYamlData, err := yaml.Marshal(&newConfigData)
|
newYamlData, err := yaml.Marshal(&newConfigData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to marshal YAML: %v", err)
|
log.Errorf("Failed to marshal YAML: %v", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将新的YAML数据写入文件
|
// 将新的YAML数据写入文件
|
||||||
err = os.WriteFile(configFile, newYamlData, 0644)
|
err = os.WriteFile(configFile, newYamlData, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to write YAML file: %v", err)
|
log.Errorf("Failed to write YAML file: %v", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapYaml map[string]interface{}
|
var mapYaml map[string]interface{}
|
||||||
@@ -284,8 +365,28 @@ func ReadParamConfig(fileName string) *map[string]interface{} {
|
|||||||
return &mapYaml
|
return &mapYaml
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateStructFromMap(s any, updates map[string]any) {
|
||||||
|
v := reflect.ValueOf(s).Elem()
|
||||||
|
t := v.Type()
|
||||||
|
|
||||||
|
for key, value := range updates {
|
||||||
|
for i := 0; i < t.NumField(); i++ {
|
||||||
|
field := t.Field(i)
|
||||||
|
if field.Tag.Get("json") == key {
|
||||||
|
structField := v.FieldByName(field.Name)
|
||||||
|
if structField.IsValid() && structField.CanSet() {
|
||||||
|
if structField.Type() == reflect.TypeOf(value) {
|
||||||
|
structField.Set(reflect.ValueOf(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetYamlConfig() *YamlConfig {
|
func GetYamlConfig() *YamlConfig {
|
||||||
return &yamlConfig
|
return &YamlConfigInfo.ConfigLines
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAuthFromConfig() interface{} {
|
func GetAuthFromConfig() interface{} {
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ redis:
|
|||||||
# OMC系统使用库
|
# OMC系统使用库
|
||||||
default:
|
default:
|
||||||
port: 6379 # Redis port
|
port: 6379 # Redis port
|
||||||
host: "192.168.8.58" # Redis host
|
host: "127.0.0.1" # Redis host
|
||||||
password: "helloearth"
|
password: "helloearth"
|
||||||
db: 10 # Redis db_num
|
db: 10 # Redis db_num
|
||||||
# UDM网元用户库
|
# UDM网元用户库
|
||||||
udmuser:
|
udmuser:
|
||||||
port: 6379 # Redis port
|
port: 6379 # Redis port
|
||||||
host: "192.168.8.58"
|
host: "127.0.0.1"
|
||||||
password: "helloearth"
|
password: "helloearth"
|
||||||
db: 0 # Redis db_num
|
db: 0 # Redis db_num
|
||||||
# 多个数据源时可以用这个指定默认的数据源
|
# 多个数据源时可以用这个指定默认的数据源
|
||||||
@@ -123,29 +123,32 @@ omc:
|
|||||||
|
|
||||||
# Alarm module setting
|
# Alarm module setting
|
||||||
# Forward interface:
|
# Forward interface:
|
||||||
|
# TLS Skip verify: true/false
|
||||||
# email/sms
|
# email/sms
|
||||||
# smProxy: sms(Short Message Service)/smsc(SMS Centre)
|
# smProxy: sms(Short Message Service)/smsc(SMS Centre)
|
||||||
alarm:
|
alarm:
|
||||||
forwardAlarm: false
|
alarmEmailForward:
|
||||||
email:
|
enable: true
|
||||||
|
emailList:
|
||||||
smtp: mail.agrandtech.com
|
smtp: mail.agrandtech.com
|
||||||
port: 25
|
port: 25
|
||||||
user: smtpext@agrandtech.com
|
user: smtpext@agrandtech.com
|
||||||
password: "1000smtp@omc!"
|
password: "1000smtp@omc!"
|
||||||
# TLS skip verify: true/false
|
|
||||||
tlsSkipVerify: true
|
tlsSkipVerify: true
|
||||||
smProxy: smsc
|
alarmSMSForward:
|
||||||
|
enable: true
|
||||||
|
mobileList:
|
||||||
|
smscAddr: "192.168.13.114:2775"
|
||||||
|
systemID: "omc"
|
||||||
|
password: "omc123"
|
||||||
|
systemType: "UTRAN"
|
||||||
sms:
|
sms:
|
||||||
apiURL: http://smsc.xxx.com/
|
apiURL: http://smsc.xxx.com/
|
||||||
accessKeyID: xxxx
|
accessKeyID: xxxx
|
||||||
accessKeySecret: xxxx
|
accessKeySecret: xxxx
|
||||||
signName: xxx SMSC
|
signName: xxx SMSC
|
||||||
templateCode: 1000
|
templateCode: 1000
|
||||||
smsc:
|
smProxy: smsc
|
||||||
addr: "192.168.13.114:2775"
|
|
||||||
systemID: "omc"
|
|
||||||
password: "omc123"
|
|
||||||
systemType: "UTRAN"
|
|
||||||
|
|
||||||
#User authorized information
|
#User authorized information
|
||||||
# crypt: mysql/md5/bcrypt
|
# crypt: mysql/md5/bcrypt
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
cm_omc "be.ems/features/cm/omc"
|
||||||
"be.ems/src/framework/i18n"
|
"be.ems/src/framework/i18n"
|
||||||
"be.ems/src/framework/utils/ctx"
|
"be.ems/src/framework/utils/ctx"
|
||||||
"be.ems/src/framework/utils/parse"
|
"be.ems/src/framework/utils/parse"
|
||||||
@@ -191,14 +192,25 @@ func (s *NeConfigController) DataInfo(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网元直连
|
if query.NeType == "OMC" {
|
||||||
resData, err := neFetchlink.NeConfigInfo(neInfo, query.ParamName)
|
var o *cm_omc.ConfigOMC
|
||||||
if err != nil {
|
resData, err := o.Query(query.ParamName)
|
||||||
c.JSON(200, result.ErrMsg(err.Error()))
|
if err != nil {
|
||||||
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, result.OkData(resData))
|
||||||
return
|
return
|
||||||
}
|
} else {
|
||||||
|
// 网元直连
|
||||||
|
resData, err := neFetchlink.NeConfigInfo(neInfo, query.ParamName)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(200, result.Ok(resData))
|
c.JSON(200, result.Ok(resData))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网元参数配置数据修改
|
// 网元参数配置数据修改
|
||||||
@@ -223,14 +235,24 @@ func (s *NeConfigController) DataEdit(c *gin.Context) {
|
|||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if body.NeType == "OMC" {
|
||||||
// 网元直连
|
var o *cm_omc.ConfigOMC
|
||||||
resData, err := neFetchlink.NeConfigUpdate(neInfo, body.ParamName, body.Loc, body.ParamData)
|
resData, err := o.Modify(body.ParamName, body.ParamData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, result.ErrMsg(err.Error()))
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, result.OkData(resData))
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
// 网元直连
|
||||||
|
resData, err := neFetchlink.NeConfigUpdate(neInfo, body.ParamName, body.Loc, body.ParamData)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, result.OkData(resData))
|
||||||
}
|
}
|
||||||
c.JSON(200, result.OkData(resData))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网元参数配置数据新增(array)
|
// 网元参数配置数据新增(array)
|
||||||
|
|||||||
Reference in New Issue
Block a user