feat: 网元配置主从Redis客户端连接,定时扫描同步状态发告警
This commit is contained in:
@@ -26,7 +26,7 @@ func (r *Service) dataByRedis(imsi, neId string) []VoLTEUser {
|
|||||||
source := fmt.Sprintf("UDM_%s", neId)
|
source := fmt.Sprintf("UDM_%s", neId)
|
||||||
|
|
||||||
// 网元主机的Redis客户端
|
// 网元主机的Redis客户端
|
||||||
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId)
|
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func (r *IMSUserService) dataByRedis(imsi, neId string) []model.IMSUser {
|
|||||||
source := fmt.Sprintf("UDM_%s", neId)
|
source := fmt.Sprintf("UDM_%s", neId)
|
||||||
|
|
||||||
// 网元主机的Redis客户端
|
// 网元主机的Redis客户端
|
||||||
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId)
|
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func (r *VoIPAuthService) dataByRedis(userName, neId string) []model.VoIPAuth {
|
|||||||
source := fmt.Sprintf("UDM_%s", neId)
|
source := fmt.Sprintf("UDM_%s", neId)
|
||||||
|
|
||||||
// 网元主机的Redis客户端
|
// 网元主机的Redis客户端
|
||||||
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId)
|
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,19 +66,25 @@ func (s *NeAlarmStateCheckUDMDBProcessor) Execute(data any) (any, error) {
|
|||||||
return nil, fmt.Errorf("json params err: %v", err)
|
return nil, fmt.Errorf("json params err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
neList := s.neInfoService.SelectList(neModel.NeInfo{NeType: "UDM"}, true, false)
|
neList := s.neInfoService.SelectList(neModel.NeInfo{NeType: "UDM"}, false, false)
|
||||||
for _, neInfo := range neList {
|
for _, neInfo := range neList {
|
||||||
|
warnMsg := []string{}
|
||||||
// 检查状态
|
// 检查状态
|
||||||
err := s.serverState(neInfo)
|
if err := s.serverState(neInfo.NeId, 2); err != nil {
|
||||||
if err == nil {
|
warnMsg = append(warnMsg, err.Error())
|
||||||
|
}
|
||||||
|
if err := s.serverState(neInfo.NeId, 3); err != nil {
|
||||||
|
warnMsg = append(warnMsg, err.Error())
|
||||||
|
}
|
||||||
|
if len(warnMsg) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 附加信息
|
// 附加信息
|
||||||
addInfo := params.AddInfo
|
addInfo := params.AddInfo
|
||||||
if addInfo != "" {
|
if addInfo != "" {
|
||||||
addInfo = addInfo + ", " + err.Error()
|
addInfo = addInfo + ", " + strings.Join(warnMsg, ", ")
|
||||||
} else {
|
} else {
|
||||||
addInfo = err.Error()
|
addInfo = strings.Join(warnMsg, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
neTypeAndId := fmt.Sprintf("%s_%s", neInfo.NeType, neInfo.NeId)
|
neTypeAndId := fmt.Sprintf("%s_%s", neInfo.NeType, neInfo.NeId)
|
||||||
@@ -128,12 +134,12 @@ func (s *NeAlarmStateCheckUDMDBProcessor) Execute(data any) (any, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// serverState 网元状态
|
// serverState 网元状态
|
||||||
func (s NeAlarmStateCheckUDMDBProcessor) serverState(neInfo neModel.NeInfo) error {
|
func (s NeAlarmStateCheckUDMDBProcessor) serverState(neId string, num int) error {
|
||||||
// 网元主机的Redis客户端
|
// 网元主机的Redis客户端
|
||||||
source := fmt.Sprintf("UDM_%s", neInfo.NeId)
|
source := fmt.Sprintf("UDM_%s", neId)
|
||||||
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neInfo.NeId)
|
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId, num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
redisClient.Close()
|
redisClient.Close()
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ func (r CDREventIMS) CDRMOSHour(rmUID string, timestamp int64) []map[string]any
|
|||||||
"timeGroup": fmt.Sprintf("%d", hour),
|
"timeGroup": fmt.Sprintf("%d", hour),
|
||||||
"total": sums["total"],
|
"total": sums["total"],
|
||||||
"mosSum": sums["mosSum"],
|
"mosSum": sums["mosSum"],
|
||||||
"mosAvg": sums["mosAvg"] / sums["total"],
|
"mosAvg": float64(int(sums["mosSum"]/sums["total"]*100)) / 100,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
@@ -328,7 +328,7 @@ func (r CDREventIMS) CDRCCTHour(rmUID string, timestamp int64) []map[string]any
|
|||||||
"timeGroup": fmt.Sprintf("%d", hour),
|
"timeGroup": fmt.Sprintf("%d", hour),
|
||||||
"total": sums["total"],
|
"total": sums["total"],
|
||||||
"cctSum": sums["cctSum"],
|
"cctSum": sums["cctSum"],
|
||||||
"cctAvg": sums["cctSum"] / sums["total"],
|
"cctAvg": float64(int(sums["cctSum"]/sums["total"]*100)) / 100,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func (r *UDMAuthUser) dataByRedis(imsi, neId string) []model.UDMAuthUser {
|
|||||||
source := fmt.Sprintf("UDM_%s", neId)
|
source := fmt.Sprintf("UDM_%s", neId)
|
||||||
|
|
||||||
// 网元主机的Redis客户端
|
// 网元主机的Redis客户端
|
||||||
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId)
|
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func (r *UDMSubUser) dataByRedis(imsi, neId string) []model.UDMSubUser {
|
|||||||
source := fmt.Sprintf("UDM_%s", neId)
|
source := fmt.Sprintf("UDM_%s", neId)
|
||||||
|
|
||||||
// 网元主机的Redis客户端
|
// 网元主机的Redis客户端
|
||||||
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId)
|
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (r UDMVOIPUser) dataByRedis(username, neId string) []model.UDMVOIPUser {
|
|||||||
source := fmt.Sprintf("UDM_%s", neId)
|
source := fmt.Sprintf("UDM_%s", neId)
|
||||||
|
|
||||||
// 网元主机的Redis客户端
|
// 网元主机的Redis客户端
|
||||||
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId)
|
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (r UDMVolteIMSUser) dataByRedis(imsi, neId string) []model.UDMVolteIMSUser
|
|||||||
source := fmt.Sprintf("UDM_%s", neId)
|
source := fmt.Sprintf("UDM_%s", neId)
|
||||||
|
|
||||||
// 网元主机的Redis客户端
|
// 网元主机的Redis客户端
|
||||||
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId)
|
redisClient, err := neService.NewNeInfo.NeRunRedisClient("UDM", neId, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ func (s *NeInfoController) Add(c *gin.Context) {
|
|||||||
c.JSON(200, result.OkData(insertId))
|
c.JSON(200, result.OkData(insertId))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200, result.Err(nil))
|
c.JSON(200, result.ErrMsg("please check the neType and neId"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网元信息修改
|
// 网元信息修改
|
||||||
|
|||||||
@@ -271,9 +271,9 @@ func (r *NeInfo) SelectById(infoId string, bandHost bool) model.NeInfo {
|
|||||||
func (r *NeInfo) Insert(neInfo model.NeInfo) string {
|
func (r *NeInfo) Insert(neInfo model.NeInfo) string {
|
||||||
// 主机信息新增
|
// 主机信息新增
|
||||||
if neInfo.Hosts != nil {
|
if neInfo.Hosts != nil {
|
||||||
uuid := generate.Code(4)
|
|
||||||
var hostIDs []string
|
var hostIDs []string
|
||||||
for _, host := range neInfo.Hosts {
|
for _, host := range neInfo.Hosts {
|
||||||
|
uuid := generate.Code(4)
|
||||||
host.Title = fmt.Sprintf("%s_%d_%s", neInfo.NeName, host.Port, uuid)
|
host.Title = fmt.Sprintf("%s_%d_%s", neInfo.NeName, host.Port, uuid)
|
||||||
host.GroupID = "1"
|
host.GroupID = "1"
|
||||||
host.CreateBy = neInfo.CreateBy
|
host.CreateBy = neInfo.CreateBy
|
||||||
@@ -297,9 +297,9 @@ func (r *NeInfo) Insert(neInfo model.NeInfo) string {
|
|||||||
func (r *NeInfo) Update(neInfo model.NeInfo) int64 {
|
func (r *NeInfo) Update(neInfo model.NeInfo) int64 {
|
||||||
// 主机信息更新
|
// 主机信息更新
|
||||||
if neInfo.Hosts != nil {
|
if neInfo.Hosts != nil {
|
||||||
uuid := generate.Code(4)
|
|
||||||
for _, host := range neInfo.Hosts {
|
for _, host := range neInfo.Hosts {
|
||||||
if host.HostID != "" {
|
if host.HostID != "" {
|
||||||
|
uuid := generate.Code(4)
|
||||||
host.Title = fmt.Sprintf("%s_%d_%s", neInfo.NeName, host.Port, uuid)
|
host.Title = fmt.Sprintf("%s_%d_%s", neInfo.NeName, host.Port, uuid)
|
||||||
host.GroupID = "1"
|
host.GroupID = "1"
|
||||||
host.UpdateBy = neInfo.UpdateBy
|
host.UpdateBy = neInfo.UpdateBy
|
||||||
@@ -461,7 +461,8 @@ func (r *NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTe
|
|||||||
|
|
||||||
// NeRunRedisClient 网元主机的Redis客户端-为创建相关连接,注意结束后 Close()
|
// NeRunRedisClient 网元主机的Redis客户端-为创建相关连接,注意结束后 Close()
|
||||||
// 暂时只有UDM有Redis配置项
|
// 暂时只有UDM有Redis配置项
|
||||||
func (r *NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error) {
|
// num 是redis 2:master 3:slave
|
||||||
|
func (r *NeInfo) NeRunRedisClient(neType, neId string, num int) (*redis.ConnRedis, error) {
|
||||||
neInfo := r.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
neInfo := r.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||||
if neInfo.NeId != neId {
|
if neInfo.NeId != neId {
|
||||||
logger.Errorf("NeRunRedisClient NeType:%s NeID:%s not found", neType, neId)
|
logger.Errorf("NeRunRedisClient NeType:%s NeID:%s not found", neType, neId)
|
||||||
@@ -474,10 +475,14 @@ func (r *NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error)
|
|||||||
}
|
}
|
||||||
hostIds := strings.Split(neInfo.HostIDs, ",")
|
hostIds := strings.Split(neInfo.HostIDs, ",")
|
||||||
if len(hostIds) <= 2 {
|
if len(hostIds) <= 2 {
|
||||||
logger.Errorf("NeRunRedisClient hosts id %s not found", neInfo.HostIDs)
|
logger.Errorf("NeRunRedisClient hosts id %s not found %d", neInfo.HostIDs, num)
|
||||||
return nil, fmt.Errorf("neinfo host id not found")
|
return nil, fmt.Errorf("neinfo host id not found")
|
||||||
}
|
}
|
||||||
hostId := hostIds[2]
|
if len(hostIds) == 3 && num == 3 {
|
||||||
|
logger.Errorf("NeRunRedisClient hosts id %s not found %d", neInfo.HostIDs, num)
|
||||||
|
return nil, fmt.Errorf("neinfo host id not found")
|
||||||
|
}
|
||||||
|
hostId := hostIds[num]
|
||||||
neHost := NewNeHost.SelectById(hostId)
|
neHost := NewNeHost.SelectById(hostId)
|
||||||
if neHost.HostID == "" || neHost.HostID != hostId {
|
if neHost.HostID == "" || neHost.HostID != hostId {
|
||||||
logger.Errorf("NeRunRedisClient Hosts %s not found", neInfo.HostIDs)
|
logger.Errorf("NeRunRedisClient Hosts %s not found", neInfo.HostIDs)
|
||||||
|
|||||||
Reference in New Issue
Block a user