cm
This commit is contained in:
129
config/temp.json
129
config/temp.json
@@ -14,3 +14,132 @@
|
||||
"OperationalState": "Enabled"
|
||||
}
|
||||
|
||||
|
||||
[
|
||||
{
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 ManagedElement PNF Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 SmfFunction PNF {
|
||||
"AdministrativeState": "Unlocked",
|
||||
"Id": "cm sz",
|
||||
"MaxPduSessions": 100000,
|
||||
"MaxQfi": 600,
|
||||
"OperationalState": "Enabled",
|
||||
"SbiServiceList": [
|
||||
"nsmf-pdusession"
|
||||
],
|
||||
"UpfList": [
|
||||
"upf-1:192.168.4.136:8805",
|
||||
"upf-2:192.168.5.19:8805"
|
||||
],
|
||||
"UserLabel": "SMF_SZ_01",
|
||||
"VnfInstanceId": "074fc555-1096-11ec-aa4b-000c298b5bde"
|
||||
} Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 IPResource PNF {} Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 EpRpDynN10Smf PNF {
|
||||
"FarIpSubnetworkList": {
|
||||
"Ipv4": [
|
||||
{
|
||||
"Mask": "255.255.255.255",
|
||||
"Subnetwork": "192.168.4.139"
|
||||
}
|
||||
],
|
||||
"Ipv6": null
|
||||
},
|
||||
"Id": "cm sz",
|
||||
"LocIpAddrList": [
|
||||
"192.168.4.134"
|
||||
],
|
||||
"UserLabel": "SMF_SZ_01"
|
||||
} Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 EpRpDynN7Smf PNF {
|
||||
"FarIpSubnetworkList": {
|
||||
"Ipv4": [
|
||||
{
|
||||
"Mask": "255.255.255.255",
|
||||
"Subnetwork": "192.168.4.139"
|
||||
}
|
||||
],
|
||||
"Ipv6": null
|
||||
},
|
||||
"Id": "cm sz",
|
||||
"LocIpAddrList": [
|
||||
"192.168.4.134"
|
||||
],
|
||||
"UserLabel": "SMF_SZ_01"
|
||||
} Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 ManagedElement PNF {
|
||||
"FarIpSubnetworkList": {
|
||||
"Ipv4": [
|
||||
{
|
||||
"Mask": "255.255.255.255",
|
||||
"Subnetwork": "192.168.4.139"
|
||||
}
|
||||
],
|
||||
"Ipv6": null
|
||||
},
|
||||
"Id": "cm sz",
|
||||
"LocIpAddrList": [
|
||||
"192.168.4.134"
|
||||
],
|
||||
"UserLabel": "SMF_SZ_01"
|
||||
} Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 SmfFunction PNF {
|
||||
"AdministrativeState": "Unlocked",
|
||||
"Id": "cm sz",
|
||||
"MaxPduSessions": 100000,
|
||||
"MaxQfi": 600,
|
||||
"OperationalState": "Enabled",
|
||||
"SbiServiceList": [
|
||||
"nsmf-pdusession"
|
||||
],
|
||||
"UpfList": [
|
||||
"upf-1:192.168.4.136:8805",
|
||||
"upf-2:192.168.5.19:8805"
|
||||
],
|
||||
"UserLabel": "SMF_SZ_01",
|
||||
"VnfInstanceId": "074fc555-1096-11ec-aa4b-000c298b5bde"
|
||||
} Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 IPResource PNF {} Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 EpRpDynN10Smf PNF {
|
||||
"FarIpSubnetworkList": {
|
||||
"Ipv4": [
|
||||
{
|
||||
"Mask": "255.255.255.255",
|
||||
"Subnetwork": "192.168.4.139"
|
||||
}
|
||||
],
|
||||
"Ipv6": null
|
||||
},
|
||||
"Id": "cm sz",
|
||||
"LocIpAddrList": [
|
||||
"192.168.4.134"
|
||||
],
|
||||
"UserLabel": "SMF_SZ_01"
|
||||
} Original
|
||||
} {
|
||||
0 2023-08-24 11: 30: 20 +0800 CST UTC+8 Ruijie Network SMF 16.1.1 1101RJHX1SMF01 001 SMF_001 EpRpDynN7Smf PNF {
|
||||
"FarIpSubnetworkList": {
|
||||
"Ipv4": [
|
||||
{
|
||||
"Mask": "255.255.255.255",
|
||||
"Subnetwork": "192.168.4.139"
|
||||
}
|
||||
],
|
||||
"Ipv6": null
|
||||
},
|
||||
"Id": "cm sz",
|
||||
"LocIpAddrList": [
|
||||
"192.168.4.134"
|
||||
],
|
||||
"UserLabel": "SMF_SZ_01"
|
||||
} Original
|
||||
}
|
||||
]
|
||||
@@ -43,7 +43,7 @@ type FieldValue struct {
|
||||
}
|
||||
|
||||
// Objects ...
|
||||
type Objects struct {
|
||||
type ObjectData struct {
|
||||
ObjectType string `xml:"ObjectType"`
|
||||
FieldName FieldName `xml:"FieldName"`
|
||||
FieldValue FieldValue `xml:"FieldValue"`
|
||||
@@ -52,7 +52,8 @@ type Objects struct {
|
||||
// DataFile ...
|
||||
type DataFile struct {
|
||||
FileHeader FileHeader `xml:"FileHeader"`
|
||||
Objects []Objects `xml:"Objects"`
|
||||
//Objects []Objects `xml:"Objects"`
|
||||
ObjectData ObjectData `xml:"objectData"`
|
||||
XsiAttr string `xml:"xmlns:xsi,attr"`
|
||||
XsiLoc string `xml:"xsi:noNamespaceSchemaLocation,attr"`
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ database:
|
||||
type: mysql
|
||||
user: root
|
||||
password: 1000omc@kp!
|
||||
host: 127.0.0.1
|
||||
host: 172.25.97.150
|
||||
port: 33066
|
||||
name: omc_db
|
||||
backup: d:/local.git/ems.agt/restagent/database
|
||||
@@ -35,10 +35,10 @@ nbi:
|
||||
cm:
|
||||
cfgfiledir: ./etc/cm
|
||||
xmlfiledir: ./ftp/cm
|
||||
version: V1.0.1
|
||||
version: V2.5.0
|
||||
duration: 30
|
||||
pm:
|
||||
cfgfiledir: ./etc/pm
|
||||
xmlfiledir: ./ftp/pm
|
||||
version: V1.0.1
|
||||
version: V2.5.0
|
||||
duration: 30
|
||||
|
||||
@@ -97,7 +97,7 @@ tasks:
|
||||
params:
|
||||
interval: 1
|
||||
unit: Day
|
||||
at: 00:00,06:00,12:00,18:00
|
||||
at: 00:00,06:00,12:00,18:00,20:43
|
||||
do: GenCmXmlFile
|
||||
- name: Task of Generate measure threshold alarm
|
||||
status: Inactive
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -70,9 +71,6 @@ func (t *TaskFunc) GenNFXmlFile(neType string) error {
|
||||
|
||||
resultMap, _ := t.ReadCmYaml(cmfile)
|
||||
|
||||
var cmResults []dborm.NorthboundCm
|
||||
err = dborm.XormGetNorthboundCm(neType, &cmResults)
|
||||
|
||||
ti := time.Now()
|
||||
timestamp := ti.Format("2006-01-02 15:04:05")
|
||||
timefile := ti.Format("20060102150405")
|
||||
@@ -86,20 +84,24 @@ func (t *TaskFunc) GenNFXmlFile(neType string) error {
|
||||
}
|
||||
|
||||
nrmFile := new(cmschema.DataFile)
|
||||
//创建目录
|
||||
path := fmt.Sprintf("%s/HX/%s/%s/CM/%s", yamlConfig.OMC.Province, yamlConfig.OMC.Vendor, yamlConfig.OMC.Name, date)
|
||||
folderPath := global.CreateDir(path, yamlConfig.NBI.CM.XmlFileDir)
|
||||
|
||||
nrmFile.FileHeader = cmschema.FileHeader{
|
||||
TimeStamp: timestamp,
|
||||
TimeZone: tzOffset,
|
||||
VendorName: "RJ",
|
||||
VendorName: yamlConfig.OMC.Vendor,
|
||||
ElementType: neType,
|
||||
CmVersion: global.Version,
|
||||
CmVersion: yamlConfig.NBI.CM.Version,
|
||||
}
|
||||
|
||||
nrmFile.XsiAttr = "http://www.w3.org/2001/XMLSchema-instance"
|
||||
nrmFile.XsiLoc = "file:///usr/loal/omc/etc/schema/cm-schema.xsd"
|
||||
|
||||
for k, e := range resultMap {
|
||||
objects := cmschema.Objects{ObjectType: k}
|
||||
for objectType, e := range resultMap {
|
||||
//objects := cmschema.Objects{ObjectType: objectType}
|
||||
objectData := cmschema.ObjectData{ObjectType: objectType}
|
||||
|
||||
sortResult := make(map[string]string)
|
||||
keys := make([]string, 0)
|
||||
@@ -109,61 +111,99 @@ func (t *TaskFunc) GenNFXmlFile(neType string) error {
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
|
||||
for s, ne := range nes {
|
||||
rmUID := fmt.Sprintf("01000HX%sBJ0D0%d", neType, s+1)
|
||||
cmResult, err := dborm.XormGetNorthboundCmLatestObject(neType, ne.NeId, objectType)
|
||||
if err != nil {
|
||||
log.Error("Failed to XormGetNorthboundCmLatestObject:", err)
|
||||
continue
|
||||
}
|
||||
log.Trace("cmResult:", cmResult)
|
||||
valueMap := make(map[string]interface{})
|
||||
if cmResult.ValueJSON != "" {
|
||||
err = json.Unmarshal([]byte(cmResult.ValueJSON), &valueMap)
|
||||
if err != nil {
|
||||
log.Error("Failed to json.Unmarshal:", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
log.Trace("valueMap:", valueMap)
|
||||
rmUID := ne.RmUID
|
||||
var object cmschema.Object
|
||||
if ne.PvFlag == "VNF" {
|
||||
vmId := fmt.Sprintf("kylin10.0-00%d-%s", s+1, neType)
|
||||
vnfInstanceID := fmt.Sprintf("2%xd55b4-%d018-41f4-af%d5-28b%d828788", s+10, s+6, s+4, s+3)
|
||||
object := cmschema.Object{RmUIDAttr: rmUID,
|
||||
object = cmschema.Object{RmUIDAttr: rmUID,
|
||||
DnAttr: "DC=www.ruijie.com.cn,SubNetwork=10001,SubNetwork=114214,ManagedElement=325",
|
||||
UserLabelAttr: ne.NeName, PVFlagAttr: ne.PvFlag, VMIDAttr: vmId, VNFInstanceIDAttr: vnfInstanceID}
|
||||
} else {
|
||||
object = cmschema.Object{RmUIDAttr: rmUID,
|
||||
DnAttr: "DC=www.ruijie.com.cn,SubNetwork=10001,SubNetwork=114214,ManagedElement=325",
|
||||
UserLabelAttr: ne.NeName, PVFlagAttr: ne.PvFlag}
|
||||
}
|
||||
|
||||
i := 1
|
||||
for _, p := range keys {
|
||||
if s == 0 {
|
||||
objects.FieldName.N = append(objects.FieldName.N, cmschema.N{IAttr: i, Value: p})
|
||||
//objects.FieldName.N = append(objects.FieldName.N, cmschema.N{IAttr: i, Value: p})
|
||||
objectData.FieldName.N = append(objectData.FieldName.N, cmschema.N{IAttr: i, Value: p})
|
||||
}
|
||||
var v string
|
||||
switch p {
|
||||
case "Id":
|
||||
v = ne.NeId
|
||||
case "UserLabel":
|
||||
v = ne.NeName
|
||||
case "VendorName":
|
||||
v = "RJ"
|
||||
case "SwVersion":
|
||||
v = global.Version
|
||||
case "PatchInfo":
|
||||
v = "-"
|
||||
case "AdministrativeState":
|
||||
v = AdminStateUnlocked
|
||||
case "OperationalState":
|
||||
v = OperationStateEnabled
|
||||
case "VnfInstanceId":
|
||||
v = vnfInstanceID
|
||||
default:
|
||||
if sortResult[p] == "" {
|
||||
v = "-"
|
||||
} else {
|
||||
v = fmt.Sprintf("%s", sortResult[p])
|
||||
}
|
||||
}
|
||||
object.V = append(object.V, cmschema.V{IAttr: i, Value: v})
|
||||
// var v string
|
||||
// switch p {
|
||||
// case "Id":
|
||||
// v = ne.RmUID
|
||||
// case "UserLabel":
|
||||
// v = ne.NeName
|
||||
// case "VendorName":
|
||||
// v = ne.VendorName
|
||||
// case "SwVersion":
|
||||
// v = cmResult.CmVersion
|
||||
// case "PatchInfo":
|
||||
// v = "-"
|
||||
// case "AdministrativeState":
|
||||
// v = AdminStateUnlocked
|
||||
// case "OperationalState":
|
||||
// v = OperationStateEnabled
|
||||
// case "VnfInstanceId":
|
||||
// v = "" //vnfInstanceID
|
||||
// default:
|
||||
// if sortResult[p] == "" {
|
||||
// v = "-"
|
||||
// } else {
|
||||
// v = fmt.Sprintf("%s", sortResult[p])
|
||||
// }
|
||||
// }
|
||||
object.V = append(object.V, cmschema.V{IAttr: i, Value: fmt.Sprintf("%v", valueMap[p])})
|
||||
i++
|
||||
}
|
||||
objects.FieldValue.Object = append(objects.FieldValue.Object, object)
|
||||
}
|
||||
nrmFile.Objects = append(nrmFile.Objects, objects)
|
||||
//objects.FieldValue.Object = append(objects.FieldValue.Object, object)
|
||||
objectData.FieldValue.Object = append(objectData.FieldValue.Object, object)
|
||||
}
|
||||
//nrmFile.Objects = append(nrmFile.Objects, objects)
|
||||
nrmFile.ObjectData = objectData
|
||||
|
||||
folderPath := global.CreateDir(date, yamlConfig.NBI.CM.XmlFileDir)
|
||||
x, _ := xml.MarshalIndent(nrmFile, "", " ")
|
||||
x = append([]byte(xml.Header), x...)
|
||||
xmlfile := fmt.Sprintf("%s/CM-HX-%s-%s-%s.xml", folderPath, neType, global.Version, timefile)
|
||||
err = os.WriteFile(xmlfile, x, 0664)
|
||||
|
||||
xmlfile := fmt.Sprintf("%s/%s-CM-%s-%s-%s-%s-%s-001.xml",
|
||||
folderPath, yamlConfig.OMC.Province, neType, objectType, yamlConfig.OMC.HostNo, yamlConfig.NBI.CM.Version, timefile)
|
||||
tmpXmlfile := xmlfile + ".tmp"
|
||||
err := os.WriteFile(tmpXmlfile, x, 0664)
|
||||
if err != nil {
|
||||
log.Error("Failed to write xml file:", err)
|
||||
return err
|
||||
log.Error("Failed to WriteFile xml file:", err)
|
||||
continue
|
||||
}
|
||||
// err := os.Create(tmpXmlfile)
|
||||
// if err != nil {
|
||||
// log.Error("Failed to WriteFile xml file:", err)
|
||||
// continue
|
||||
// }
|
||||
|
||||
err = os.Rename(tmpXmlfile, xmlfile)
|
||||
if err != nil {
|
||||
log.Error("Failed to Rename xml file:", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1375,7 +1375,7 @@ func (t *TaskFunc) TaskWriteSystemLog(uri, params, body string) {
|
||||
}
|
||||
sysLogs := &[]dborm.SystemLog{}
|
||||
sysLog := &dborm.SystemLog{
|
||||
User: userName,
|
||||
UserName: userName,
|
||||
ProcessName: newProcInfo.Name,
|
||||
ProcessID: newProcInfo.Pid,
|
||||
Operation: operation,
|
||||
|
||||
@@ -1541,7 +1541,7 @@ func XormInsertAlarmForwardLog(logData *AlarmForwardLog) (int64, error) {
|
||||
|
||||
type SystemLog struct {
|
||||
ID int `json:"-" xorm:"pk 'id' autoincr"`
|
||||
User string `json:"user" xorm:"user"`
|
||||
UserName string `json:"user_name" xorm:"user_name"`
|
||||
ProcessName string `json:"process_name" xorm:"process_name"`
|
||||
ProcessID int32 `json:"process_id" xorm:"process_id"`
|
||||
Operation string `json:"operation" xorm:"operation"`
|
||||
@@ -1624,7 +1624,7 @@ func XormUpdateNeLicense(neType, neID string, capcity int) (int64, error) {
|
||||
}
|
||||
|
||||
type NorthboundCm struct {
|
||||
ID int `json:"-" xorm:"pk 'id' autoincr"`
|
||||
ID int `json:"-" xorm:"pk '-' autoincr"`
|
||||
Timestamp string `json:"timestamp" xorm:"timestamp"`
|
||||
TimeZone string `json:"timeZone" xorm:"time_zone"`
|
||||
VendorName string `json:"vendorName" xorm:"vendor_name"`
|
||||
@@ -1637,7 +1637,7 @@ type NorthboundCm struct {
|
||||
PvFlag string `json:"pvFlag" xorm:"pv_flag"`
|
||||
VMID string `json:"vmID" xorm:"vm_id"`
|
||||
VnfInstanceID string `json:"vnf_instance_id"`
|
||||
ValueJSON interface{} `json:"valueJson" xorm:"value_json"`
|
||||
ValueJSON string `json:"valueJson" xorm:"value_json"`
|
||||
Status string `json:"status" xorm:"status"`
|
||||
}
|
||||
|
||||
@@ -1646,9 +1646,10 @@ func XormGetNorthboundCm(neType string, cmResults *[]NorthboundCm) error {
|
||||
|
||||
cmResult := new(NorthboundCm)
|
||||
rows, err := xEngine.Table("northbound_cm").
|
||||
Where("`ne_type` = ?", neType).
|
||||
Distinct("object_type").
|
||||
Where("`ne_type` = ?", neType).
|
||||
Desc("timestamp").
|
||||
Cols("*").
|
||||
Rows(cmResult)
|
||||
if err != nil {
|
||||
log.Error("Failed to get table northbound_cm:", err)
|
||||
@@ -1665,3 +1666,21 @@ func XormGetNorthboundCm(neType string, cmResults *[]NorthboundCm) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func XormGetNorthboundCmLatestObject(neType, neID, objectType string) (*NorthboundCm, error) {
|
||||
log.Info("XormGetNorthboundCmLatestObject processing... ")
|
||||
|
||||
cmResult := new(NorthboundCm)
|
||||
_, err := xEngine.Table("northbound_cm").
|
||||
Where("`ne_type`=? and `ne_id`=? and `object_type`=?", neType, neID, objectType).
|
||||
Desc("timestamp").
|
||||
Cols("*").
|
||||
Limit(1).
|
||||
Get(cmResult)
|
||||
if err != nil {
|
||||
log.Error("Failed to get table northbound_cm:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cmResult, nil
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ func CreateDir(folderName string, path string) string {
|
||||
folderPath := filepath.Join(path, folderName)
|
||||
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
|
||||
// 必须分成两步:先创建文件夹、再修改权限
|
||||
os.Mkdir(folderPath, 0664) //0644也可以os.ModePerm
|
||||
os.MkdirAll(folderPath, 0664) //0644也可以os.ModePerm
|
||||
os.Chmod(folderPath, 0664)
|
||||
}
|
||||
return folderPath
|
||||
|
||||
Reference in New Issue
Block a user