feat: 更新多个模块以支持新的数据结构和日志格式

This commit is contained in:
TsMask
2025-02-20 10:08:27 +08:00
parent 045a2b6b01
commit f3c33b31ac
272 changed files with 13246 additions and 15885 deletions

View File

@@ -46,7 +46,7 @@ func (s *BarProcessor) Execute(data any) (any, error) {
// return nil, err
// }
log.Infof("Repeat %v Job ID %s", options.Repeat, sysJob.JobID)
log.Infof("Repeat %v Job ID %d", options.Repeat, sysJob.JobId)
var nes []dborm.NeInfo
_, err := dborm.XormGetAllNeInfo(&nes)

View File

@@ -39,7 +39,7 @@ func (s *BarProcessor) Execute(data any) (any, error) {
if err == nil {
duration = params.Duration
}
log.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
log.Infof("重复 %v 任务ID %d", options.Repeat, sysJob.JobId)
// // 实现任务处理逻辑
// i := 0

View File

@@ -44,7 +44,7 @@ func (s *BarProcessor) Execute(data any) (any, error) {
}
//duration = params.Duration
log.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
log.Infof("重复 %v 任务ID %d", options.Repeat, sysJob.JobId)
// // 实现任务处理逻辑
// i := 0

View File

@@ -15,10 +15,9 @@ import (
"be.ems/src/framework/config"
"be.ems/src/framework/cron"
"be.ems/src/framework/logger"
"be.ems/src/framework/ssh"
"be.ems/src/framework/utils/crypto"
"be.ems/src/framework/utils/ssh"
systemService "be.ems/src/modules/system/service"
"github.com/jlaffaye/ftp"
)
var NewProcessor = &BarProcessor{
@@ -177,11 +176,11 @@ func (s BarProcessor) putFTP(filePath, fileName string) {
Username string `json:"username" binding:"required"`
ToIp string `json:"toIp" binding:"required"`
ToPort int64 `json:"toPort" binding:"required"`
Protocol string `json:"protocol" binding:"required,oneof=ssh ftp"`
Enable bool `json:"enable"`
Dir string `json:"dir" binding:"required"`
}
cfg := systemService.NewSysConfigImpl.SelectConfigByKey("sys.exportTable")
if cfg.ConfigID != "" {
cfg := systemService.NewSysConfig.FindByKey("sys.exportTable")
if cfg.ConfigId > 0 {
// 解密body
appKey := config.Get("aes.appKey").(string)
bodyDe, err := crypto.AESDecryptBase64(cfg.ConfigValue, appKey)
@@ -195,68 +194,37 @@ func (s BarProcessor) putFTP(filePath, fileName string) {
return
}
}
if !cfgData.Enable {
return
}
localFilePath := filepath.Join(filePath, fileName)
if cfgData.Protocol == "ssh" {
connSSH := ssh.ConnSSH{
User: cfgData.Username,
Password: cfgData.Password,
Addr: cfgData.ToIp,
Port: cfgData.ToPort,
AuthMode: "0",
}
sshClient, err := connSSH.NewClient()
if err != nil {
logger.Errorf("putFTP ssh error: %v", err)
return
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
logger.Errorf("putFTP sftp error: %v", err)
return
}
defer sftpClient.Close()
// 远程文件
remotePath := filepath.Join(cfgData.Dir, path.Base(filePath), fileName)
// 复制到远程
if err = sftpClient.CopyFileLocalToRemote(localFilePath, remotePath); err != nil {
logger.Errorf("putFTP uploading error: %v", err)
return
}
connSSH := ssh.ConnSSH{
User: cfgData.Username,
Password: cfgData.Password,
Addr: cfgData.ToIp,
Port: cfgData.ToPort,
AuthMode: "0",
}
if cfgData.Protocol == "ftp" {
// 连接到 FTP 服务器
addr := fmt.Sprintf("%s:%d", cfgData.ToIp, cfgData.ToPort)
ftpComm, err := ftp.Dial(addr, ftp.DialWithTimeout(15*time.Second))
if err != nil {
logger.Errorf("putFTP ftp error: %v", err)
return
}
// 登录到 FTP 服务器
err = ftpComm.Login(cfgData.Username, cfgData.Password)
if err != nil {
logger.Errorf("putFTP login error: %v", err)
return
}
defer ftpComm.Quit()
// 打开本地文件
file, err := os.Open(localFilePath)
if err != nil {
logger.Errorf("putFTP open error: %v", err)
return
}
defer file.Close()
// 远程文件
remotePath := filepath.Join(cfgData.Dir, path.Base(filePath), fileName)
// 上传文件到 FTP 服务器
err = ftpComm.Stor(remotePath, file)
if err != nil {
logger.Errorf("putFTP uploading error: %v", err)
return
}
sshClient, err := connSSH.NewClient()
if err != nil {
logger.Errorf("putFTP ssh error: %v", err)
return
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
logger.Errorf("putFTP sftp error: %v", err)
return
}
defer sftpClient.Close()
// 远程文件
remotePath := filepath.Join(cfgData.Dir, path.Base(filePath), fileName)
// 复制到远程
if err = sftpClient.CopyFileLocalToRemote(localFilePath, remotePath); err != nil {
logger.Errorf("putFTP uploading error: %v", err)
return
}
}

View File

@@ -10,20 +10,27 @@ import (
"be.ems/features/fm"
"be.ems/lib/config"
"be.ems/lib/dborm"
"be.ems/lib/global"
"be.ems/lib/log"
"be.ems/src/framework/cron"
"be.ems/src/framework/database/db"
"be.ems/src/framework/utils/date"
neDataModel "be.ems/src/modules/network_data/model"
neModel "be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
"github.com/go-resty/resty/v2"
)
var NewProcessor = &BarProcessor{
progress: 0,
count: 0,
neInfoService: neService.NewNeInfo,
progress: 0,
count: 0,
}
// bar 队列任务处理
type BarProcessor struct {
neInfoService *neService.NeInfo // 网元信息服务
// 任务进度
progress int
// 执行次数
@@ -31,7 +38,7 @@ type BarProcessor struct {
}
type BarParams struct {
AlarmID string `json:"alarmID"`
AlarmCode int `json:"alarmCode"`
AlarmCode int64 `json:"alarmCode"`
AlarmTitle string `json:"alarmTitle"`
AlarmType string `json:"alarmType"`
OrigSeverity string `json:"origSeverity"`
@@ -44,38 +51,6 @@ type BarParams struct {
Threshold int64 `json:"threshold"`
}
// type BarParams struct {
// Duration int `json:"duration"`
// }
type Alarm struct {
Id int `json:"-" xorm:"pk 'id' autoincr"`
AlarmSeq int `json:"alarmSeq"`
AlarmId string `json:"alarmId" xorm:"alarm_id"`
NeId string `json:"neId"`
AlarmCode int `json:"alarmCode"`
AlarmTitle string `json:"alarmTitle"`
EventTime string `json:"eventTime"`
AlarmType string `json:"alarmType"`
OrigSeverity string `json:"origSeverity"`
PerceivedSeverity string `json:"perceivedSeverity"`
PVFlag string `json:"pvFlag" xorm:"pv_flag"`
NeName string `json:"neName"`
NeType string `json:"neType"`
ObjectUid string `json:"objectUid" xorm:"object_uid"`
ObjectName string `json:"objectName" xorm:"object_name"`
ObjectType string `json:"objectType" xorm:"object_type"`
LocationInfo string `json:"locationInfo"`
Province string `json:"province"`
AlarmStatus int `json:"alarmStatus" xorm:"alarm_status"`
SpecificProblem string `json:"specificProblem"`
SpecificProblemID string `json:"specificProblemID" xorm:"specific_problem_id"`
AddInfo string `json:"addInfo"`
// ClearType int `json:"-" xorm:"clear_type"` // 0: Unclear, 1: Auto clear, 2: Manual clear
// ClearTime sql.NullTime `json:"-" xorm:"clear_time"`
}
var client = resty.New()
func init() {
@@ -97,29 +72,23 @@ func (s *BarProcessor) Execute(data any) (any, error) {
return nil, err
}
var nes []dborm.NeInfo
_, err = dborm.XormGetAllNeInfo(&nes)
if err != nil {
log.Error("Failed to get all ne info:", err)
return nil, err
}
succActiveAlarmNum := 0
failActiveAlarmNum := 0
succClearAlarmNum := 0
failClearAlarmNum := 0
for _, ne := range nes {
neList := s.neInfoService.Find(neModel.NeInfo{}, false, false)
for _, neInfo := range neList {
//log.Debug("ne:", ne)
sql := fmt.Sprintf("select * from ne_state where ne_type='%s' and ne_id='%s' order by `timestamp` desc limit 1", ne.NeType, ne.NeId)
sql := fmt.Sprintf("select * from ne_state where ne_type='%s' and ne_id='%s' order by `timestamp` desc limit 1", neInfo.NeType, neInfo.NeId)
log.Debug("SQL:", sql)
neState, err := dborm.XormGetDataBySQL(sql)
neState, err := db.RawDB("", sql, nil)
if err != nil {
log.Error("Failed to get ne_state:", err)
continue
}
if len(*neState) == 0 {
if len(neState) == 0 {
log.Warn("Not found record in ne_state:")
//continue
}
@@ -139,8 +108,8 @@ func (s *BarProcessor) Execute(data any) (any, error) {
// log.Debug("alarmDefine:", alarmDefine)
sql = fmt.Sprintf("select * from alarm where alarm_id = '%s' and ne_type='%s' and ne_id = '%s' order by event_time desc limit 1",
alarmDefine.AlarmID, ne.NeType, ne.RmUID)
alarm, err := dborm.XormGetDataBySQL(sql)
alarmDefine.AlarmID, neInfo.NeType, neInfo.RmUID)
alarm, err := db.RawDB("", sql, nil)
if err != nil {
log.Error("Failed to get alarm:", err)
continue
@@ -148,11 +117,11 @@ func (s *BarProcessor) Execute(data any) (any, error) {
//log.Debug("alarm:", *alarm)
var timestamp string
if len(*neState) == 0 {
log.Infof("Not found ne_state neType:%s, neId:%s", ne.NeType, ne.NeId)
timestamp = ne.UpdateTime.Format(time.DateTime)
if len(neState) == 0 {
log.Infof("Not found ne_state neType:%s, neId:%s", neInfo.NeType, neInfo.NeId)
timestamp = date.ParseDateToStr(neInfo.UpdateTime, date.YYYYMMDDHHMMSS)
} else {
timestamp = (*neState)[0]["timestamp"]
timestamp = fmt.Sprint(neState[0]["timestamp"])
}
// 解析日期时间字符串为时间对象
@@ -164,44 +133,44 @@ func (s *BarProcessor) Execute(data any) (any, error) {
log.Debugf("timestamp:%s seconds:%d", timestamp, seconds)
if seconds <= alarmDefine.Threshold {
if len(*alarm) == 0 || (*alarm)[0]["alarm_status"] == fm.AlarmStatusClearString {
if len(alarm) == 0 || alarm[0]["alarm_status"] == fm.AlarmStatusClearString {
continue
}
// clear alarm, todo
var alarmSeq int = 1
var alarmSeq int64 = 1
threshold := strconv.FormatInt(alarmDefine.Threshold, 10)
SpecificProblem := strings.ReplaceAll(alarmDefine.SpecificProblem, "{threshold}", threshold)
locationInfo := fmt.Sprintf("SystemManagement.State: NE heartbeat timestamp=%sthreshold=%v", timestamp, alarmDefine.Threshold)
alarmData := &Alarm{
alarmData := &neDataModel.Alarm{
AlarmSeq: alarmSeq,
AlarmId: alarmDefine.AlarmID,
NeId: ne.RmUID,
NeType: ne.NeType,
NeName: ne.NeName,
Province: ne.Province,
PVFlag: ne.PvFlag,
NeId: neInfo.RmUID,
NeType: neInfo.NeType,
NeName: neInfo.NeName,
Province: neInfo.Province,
PvFlag: neInfo.PvFlag,
AlarmCode: alarmDefine.AlarmCode,
AlarmTitle: alarmDefine.AlarmTitle,
AlarmType: alarmDefine.AlarmType,
AlarmStatus: fm.AlarmStatusClear,
AlarmStatus: "0",
OrigSeverity: alarmDefine.OrigSeverity,
ObjectUid: alarmDefine.ObjectUID,
ObjectName: alarmDefine.ObjectName,
ObjectType: alarmDefine.ObjectType,
LocationInfo: locationInfo,
SpecificProblem: SpecificProblem,
SpecificProblemID: alarmDefine.SpecificProblemID,
SpecificProblemId: alarmDefine.SpecificProblemID,
AddInfo: alarmDefine.AddInfo,
EventTime: time.Now().Local().Format(time.RFC3339),
EventTime: time.Now().UnixMilli(),
}
alarmArray := &[]Alarm{*alarmData}
alarmArray := &[]neDataModel.Alarm{*alarmData}
body, _ := json.Marshal(alarmArray)
//log.Debug("body: ", string(body))
var response *resty.Response
requestURI := fmt.Sprintf("/api/rest/faultManagement/v1/elementType/%s/objectType/alarms", ne.NeType)
requestURI := fmt.Sprintf("/api/rest/faultManagement/v1/elementType/%s/objectType/alarms", neInfo.NeType)
//restHost := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port)
restHost := config.GetOMCHostUrl()
requestURL := fmt.Sprintf("%s%s", restHost, requestURI)
@@ -233,8 +202,8 @@ func (s *BarProcessor) Execute(data any) (any, error) {
failClearAlarmNum++
}
} else {
var alarmSeq int = 1
if len(*alarm) > 0 && (*alarm)[0]["alarm_status"] == fm.AlarmStatusActiveString {
var alarmSeq int64 = 1
if len(alarm) > 0 && alarm[0]["alarm_status"] == fm.AlarmStatusActiveString {
log.Info("System state alarm has exist")
continue
}
@@ -242,35 +211,35 @@ func (s *BarProcessor) Execute(data any) (any, error) {
threshold := strconv.FormatInt(alarmDefine.Threshold, 10)
SpecificProblem := strings.ReplaceAll(alarmDefine.SpecificProblem, "{threshold}", threshold)
locationInfo := fmt.Sprintf("SystemManagement.State: NE heartbeat timestamp=%sthreshold=%v", timestamp, alarmDefine.Threshold)
alarmData := &Alarm{
alarmData := &neDataModel.Alarm{
AlarmSeq: alarmSeq,
AlarmId: alarmDefine.AlarmID,
NeId: ne.RmUID,
NeType: ne.NeType,
NeName: ne.NeName,
Province: ne.Province,
PVFlag: ne.PvFlag,
NeId: neInfo.RmUID,
NeType: neInfo.NeType,
NeName: neInfo.NeName,
Province: neInfo.Province,
PvFlag: neInfo.PvFlag,
AlarmCode: alarmDefine.AlarmCode,
AlarmTitle: alarmDefine.AlarmTitle,
AlarmType: alarmDefine.AlarmType,
AlarmStatus: fm.AlarmStatusActive,
AlarmStatus: "1",
OrigSeverity: alarmDefine.OrigSeverity,
ObjectUid: alarmDefine.ObjectUID,
ObjectName: alarmDefine.ObjectName,
ObjectType: alarmDefine.ObjectType,
LocationInfo: locationInfo,
SpecificProblem: SpecificProblem,
SpecificProblemID: alarmDefine.SpecificProblemID,
SpecificProblemId: alarmDefine.SpecificProblemID,
AddInfo: alarmDefine.AddInfo,
EventTime: time.Now().Local().Format(time.RFC3339),
EventTime: time.Now().UnixMilli(),
}
alarmArray := &[]Alarm{*alarmData}
alarmArray := &[]neDataModel.Alarm{*alarmData}
body, _ := json.Marshal(alarmArray)
//log.Debug("body: ", string(body))
var response *resty.Response
requestURI := fmt.Sprintf("/api/rest/faultManagement/v1/elementType/%s/objectType/alarms", ne.NeType)
requestURI := fmt.Sprintf("/api/rest/faultManagement/v1/elementType/%s/objectType/alarms", neInfo.NeType)
//restHost := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port)
restHost := config.GetOMCHostUrl()
requestURL := fmt.Sprintf("%s%s", restHost, requestURI)

View File

@@ -29,7 +29,7 @@ func (s *MonitorSysResourceProcessor) Execute(data any) (any, error) {
s.count++ // 执行次数加一
options := data.(cron.JobData)
sysJob := options.SysJob
logger.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
logger.Infof("重复 %v 任务ID %d", options.Repeat, sysJob.JobId)
// 读取参数值
var params struct {

View File

@@ -27,17 +27,17 @@ func (s *NeConfigBackupProcessor) Execute(data any) (any, error) {
s.count++ // 执行次数加一
options := data.(cron.JobData)
sysJob := options.SysJob
logger.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
logger.Infof("重复 %v 任务ID %d", options.Repeat, sysJob.JobId)
// 返回结果,用于记录执行结果
result := map[string]any{
"count": s.count,
}
neList := s.neInfoService.SelectList(neModel.NeInfo{}, false, false)
neList := s.neInfoService.Find(neModel.NeInfo{}, false, false)
for _, neInfo := range neList {
neTypeAndId := fmt.Sprintf("%s_%s", neInfo.NeType, neInfo.NeId)
// 将网元文件备份到本地
zipFilePath, err := s.neConfigBackupService.NeConfigNeToLocal(neInfo)
zipFilePath, err := s.neConfigBackupService.FileNeToLocal(neInfo)
if err != nil {
result[neTypeAndId] = err.Error()
continue

View File

@@ -29,13 +29,13 @@ func (s *NeDataUDM) Execute(data any) (any, error) {
s.count++ // 执行次数加一
options := data.(cron.JobData)
sysJob := options.SysJob
logger.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
logger.Infof("重复 %v 任务ID %d", options.Repeat, sysJob.JobId)
// 返回结果,用于记录执行结果
result := map[string]any{
"count": s.count,
}
neList := s.neInfoService.SelectList(neModel.NeInfo{NeType: "UDM"}, false, false)
neList := s.neInfoService.Find(neModel.NeInfo{NeType: "UDM"}, false, false)
for _, neInfo := range neList {
result[fmt.Sprintf("AuthNumber_%s", neInfo.NeId)] = s.udmAuthService.ResetData(neInfo.NeId)
result[fmt.Sprintf("SubNumber_%s", neInfo.NeId)] = s.udmSubService.ResetData(neInfo.NeId)