feat: 网元配置主从Redis客户端连接,定时扫描同步状态发告警

This commit is contained in:
TsMask
2025-09-12 17:43:41 +08:00
parent ed4ea06e2e
commit 0aeec738ba
11 changed files with 35 additions and 24 deletions

View File

@@ -271,9 +271,9 @@ func (r *NeInfo) SelectById(infoId string, bandHost bool) model.NeInfo {
func (r *NeInfo) Insert(neInfo model.NeInfo) string {
// 主机信息新增
if neInfo.Hosts != nil {
uuid := generate.Code(4)
var hostIDs []string
for _, host := range neInfo.Hosts {
uuid := generate.Code(4)
host.Title = fmt.Sprintf("%s_%d_%s", neInfo.NeName, host.Port, uuid)
host.GroupID = "1"
host.CreateBy = neInfo.CreateBy
@@ -297,9 +297,9 @@ func (r *NeInfo) Insert(neInfo model.NeInfo) string {
func (r *NeInfo) Update(neInfo model.NeInfo) int64 {
// 主机信息更新
if neInfo.Hosts != nil {
uuid := generate.Code(4)
for _, host := range neInfo.Hosts {
if host.HostID != "" {
uuid := generate.Code(4)
host.Title = fmt.Sprintf("%s_%d_%s", neInfo.NeName, host.Port, uuid)
host.GroupID = "1"
host.UpdateBy = neInfo.UpdateBy
@@ -461,7 +461,8 @@ func (r *NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTe
// NeRunRedisClient 网元主机的Redis客户端-为创建相关连接,注意结束后 Close()
// 暂时只有UDM有Redis配置项
func (r *NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error) {
// num 是redis 2master 3slave
func (r *NeInfo) NeRunRedisClient(neType, neId string, num int) (*redis.ConnRedis, error) {
neInfo := r.SelectNeInfoByNeTypeAndNeID(neType, neId)
if neInfo.NeId != 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, ",")
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")
}
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)
if neHost.HostID == "" || neHost.HostID != hostId {
logger.Errorf("NeRunRedisClient Hosts %s not found", neInfo.HostIDs)