feat: 网元配置主从Redis客户端连接,定时扫描同步状态发告警
This commit is contained in:
@@ -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 2:master 3:slave
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user