fix: cm_version filled by ne version

This commit is contained in:
simon
2025-07-24 09:53:36 +08:00
parent f7f9572aef
commit 3e7c60ecd0
6 changed files with 188 additions and 188 deletions

View File

@@ -64,28 +64,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastJson).Error
newValueJson := string(meJSON)
if err != nil || lastJson == "" {
common.InsertNbiCm(ne, "ManagedElement", newValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "ManagedElement", newValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "ManagedElement", newValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "ManagedElement", newValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastJson, newValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "ManagedElement", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "ManagedElement", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "ManagedElement", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "ManagedElement", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "ManagedElement", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "ManagedElement", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "ManagedElement", newValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "ManagedElement", newValueJson, common.ObjectOriginalEvent)
}
}
@@ -113,28 +113,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastRackJson).Error
newRackValueJson := string(rackJSON)
if err != nil || lastRackJson == "" {
common.InsertNbiCm(ne, "InventoryUnitRack", newRackValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "InventoryUnitRack", newRackValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "InventoryUnitRack", newRackValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitRack", newRackValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastRackJson, newRackValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitRack", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitRack", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitRack", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitRack", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitRack", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitRack", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "InventoryUnitRack", newRackValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "InventoryUnitRack", newRackValueJson, common.ObjectOriginalEvent)
}
}
}
@@ -163,28 +163,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastShelfJson).Error
newShelfValueJson := string(shelfJSON)
if err != nil || lastShelfJson == "" {
common.InsertNbiCm(ne, "InventoryUnitShelf", newShelfValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "InventoryUnitShelf", newShelfValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "InventoryUnitShelf", newShelfValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitShelf", newShelfValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastShelfJson, newShelfValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitShelf", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitShelf", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitShelf", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitShelf", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitShelf", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitShelf", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "InventoryUnitShelf", newShelfValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "InventoryUnitShelf", newShelfValueJson, common.ObjectOriginalEvent)
}
}
}
@@ -213,28 +213,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastPackJson).Error
newPackValueJson := string(packJSON)
if err != nil || lastPackJson == "" {
common.InsertNbiCm(ne, "InventoryUnitPack", newPackValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "InventoryUnitPack", newPackValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "InventoryUnitPack", newPackValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitPack", newPackValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastPackJson, newPackValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitPack", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitPack", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitPack", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitPack", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitPack", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitPack", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "InventoryUnitPack", newPackValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "InventoryUnitPack", newPackValueJson, common.ObjectOriginalEvent)
}
}
}
@@ -266,28 +266,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastHostJson).Error
newHostValueJson := string(hostJSON)
if err != nil || lastHostJson == "" {
common.InsertNbiCm(ne, "InventoryUnitHost", newHostValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "InventoryUnitHost", newHostValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "InventoryUnitHost", newHostValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitHost", newHostValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastHostJson, newHostValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitHost", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitHost", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitHost", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitHost", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitHost", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitHost", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "InventoryUnitHost", newHostValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "InventoryUnitHost", newHostValueJson, common.ObjectOriginalEvent)
}
}
}
@@ -318,28 +318,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastAccJson).Error
newAccValueJson := string(accJSON)
if err != nil || lastAccJson == "" {
common.InsertNbiCm(ne, "InventoryUnitAccessory", newAccValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "InventoryUnitAccessory", newAccValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "InventoryUnitAccessory", newAccValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitAccessory", newAccValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastAccJson, newAccValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitAccessory", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitAccessory", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitAccessory", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitAccessory", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "InventoryUnitAccessory", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "InventoryUnitAccessory", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "InventoryUnitAccessory", newAccValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "InventoryUnitAccessory", newAccValueJson, common.ObjectOriginalEvent)
}
}
}
@@ -372,28 +372,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastUpfJson).Error
newUpfValueJson := string(upfJSON)
if err != nil || lastUpfJson == "" {
common.InsertNbiCm(ne, "UpfFunction", newUpfValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "UpfFunction", newUpfValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "UpfFunction", newUpfValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "UpfFunction", newUpfValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastUpfJson, newUpfValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "UpfFunction", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "UpfFunction", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "UpfFunction", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "UpfFunction", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "UpfFunction", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "UpfFunction", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "UpfFunction", newUpfValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "UpfFunction", newUpfValueJson, common.ObjectOriginalEvent)
}
}
}
@@ -415,28 +415,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastN3Json).Error
newN3ValueJson := string(n3JSON)
if err != nil || lastN3Json == "" {
common.InsertNbiCm(ne, "EpRpDynN3Upf", newN3ValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "EpRpDynN3Upf", newN3ValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "EpRpDynN3Upf", newN3ValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "EpRpDynN3Upf", newN3ValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastN3Json, newN3ValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "EpRpDynN3Upf", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "EpRpDynN3Upf", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "EpRpDynN3Upf", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "EpRpDynN3Upf", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "EpRpDynN3Upf", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "EpRpDynN3Upf", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "EpRpDynN3Upf", newN3ValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "EpRpDynN3Upf", newN3ValueJson, common.ObjectOriginalEvent)
}
}
}
@@ -458,28 +458,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastN9Json).Error
newN9ValueJson := string(n9JSON)
if err != nil || lastN9Json == "" {
common.InsertNbiCm(ne, "EpRpDynN9Upf", newN9ValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "EpRpDynN9Upf", newN9ValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "EpRpDynN9Upf", newN9ValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "EpRpDynN9Upf", newN9ValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastN9Json, newN9ValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "EpRpDynN9Upf", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "EpRpDynN9Upf", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "EpRpDynN9Upf", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "EpRpDynN9Upf", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "EpRpDynN9Upf", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "EpRpDynN9Upf", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "EpRpDynN9Upf", newN9ValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "EpRpDynN9Upf", newN9ValueJson, common.ObjectOriginalEvent)
}
}
}
@@ -502,28 +502,28 @@ func SyncNbiCM() error {
Order("timestamp ASC").Pluck("value_json", &lastIpJson).Error
newIpValueJson := string(ipJSON)
if err != nil || lastIpJson == "" {
common.InsertNbiCm(ne, "IPResource", newIpValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, "IPResource", newIpValueJson, common.ObjectCreationEvent)
common.InsertNbiCm(ne, version, "IPResource", newIpValueJson, common.ObjectOriginalEvent)
nbiCm := common.InsertNbiCm(ne, version, "IPResource", newIpValueJson, common.ObjectCreationEvent)
redisqueue.AddNbiCMQueue([]string{strconv.Itoa(nbiCm.Id)})
} else {
var ids []string
added, modified, deleted, _ := common.CompareJSON(lastIpJson, newIpValueJson)
if len(added) > 0 {
nbiCm := common.InsertNbiCm(ne, "IPResource", common.ToJson(added), common.ObjectCreationEvent)
nbiCm := common.InsertNbiCm(ne, version, "IPResource", common.ToJson(added), common.ObjectCreationEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(modified) > 0 {
nbiCm := common.InsertNbiCm(ne, "IPResource", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
nbiCm := common.InsertNbiCm(ne, version, "IPResource", common.ToJson(modified), common.ObjectAttributeValueChangeEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(deleted) > 0 {
nbiCm := common.InsertNbiCm(ne, "IPResource", common.ToJson(deleted), common.ObjectDeletionEvent)
nbiCm := common.InsertNbiCm(ne, version, "IPResource", common.ToJson(deleted), common.ObjectDeletionEvent)
ids = append(ids, strconv.Itoa(nbiCm.Id))
}
if len(ids) > 0 {
redisqueue.AddNbiCMQueue(ids)
common.InsertNbiCm(ne, "IPResource", newIpValueJson, common.ObjectOriginalEvent)
common.InsertNbiCm(ne, version, "IPResource", newIpValueJson, common.ObjectOriginalEvent)
}
}
}