Merge remote-tracking branch 'origin/main' into lichang

This commit is contained in:
TsMask
2024-05-24 21:08:10 +08:00
25 changed files with 322 additions and 97 deletions

View File

@@ -697,19 +697,27 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
if !config.GetYamlConfig().OMC.TestMode {
filePath := (*neVersion)[0]["path"]
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
srcFile := fmt.Sprintf("%s/actpkg.sh", config.GetYamlConfig().OMC.BinDir)
runCmd := fmt.Sprintf("sudo rm -f %s/actpkg.sh", config.GetYamlConfig().NE.ScpDir)
err = RunSSHCmd(sshHost, runCmd)
if err != nil {
log.Errorf("Failed to run cmd: %s", runCmd)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
srcFile := fmt.Sprintf("%s/actpkg.sh", config.GetYamlConfig().OMC.BinDir)
scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
cmd := exec.Command("scp", "-r", srcFile, scpDir)
_, err := cmd.CombinedOutput()
if err != nil {
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
log.Errorf("Failed to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
runCmd := fmt.Sprintf("sudo %s/actpkg.sh '%s' %s",
runCmd = fmt.Sprintf("sudo %s/actpkg.sh '%s' %s",
config.GetYamlConfig().NE.ScpDir, filePath, neTypeUpper)
if neTypeLower == "omc" {
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
@@ -897,6 +905,14 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
if !config.GetYamlConfig().OMC.TestMode {
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
runCmd := fmt.Sprintf("sudo rm -f %s/rbkpkg.sh", config.GetYamlConfig().NE.ScpDir)
err = RunSSHCmd(sshHost, runCmd)
if err != nil {
log.Errorf("Failed to run cmd: %s", runCmd)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
srcFile := fmt.Sprintf("%s/rbkpkg.sh", config.GetYamlConfig().OMC.BinDir)
scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
@@ -909,7 +925,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
return
}
runCmd := fmt.Sprintf("sudo %s/rbkpkg.sh '%s' %s",
runCmd = fmt.Sprintf("sudo %s/rbkpkg.sh '%s' %s",
config.GetYamlConfig().NE.ScpDir, filePath, neTypeUpper)
if neTypeLower == "omc" {
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])

View File

@@ -435,11 +435,20 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
SetAlarmAckInfo(valueJson, &alarmData)
}
log.Debug("alarmData:", alarmData)
affected, err := session.Insert(alarmData)
if err != nil && affected <= 0 {
log.Error("Failed to insert alarm data:", err)
services.ResponseInternalServerError500DatabaseOperationFailed(w)
continue
if alarmData.OrigSeverity == "Event" && config.GetYamlConfig().Alarm.SplitEventAlarm {
affected, err := xEngine.Table("alarm_event").InsertOne(alarmData)
if err != nil && affected <= 0 {
log.Error("Failed to insert alarm_event:", err)
services.ResponseInternalServerError500ProcessError(w, err)
continue
}
} else {
affected, err := session.Insert(alarmData)
if err != nil && affected <= 0 {
log.Error("Failed to insert alarm data:", err)
services.ResponseInternalServerError500DatabaseOperationFailed(w)
continue
}
}
alarmLog := new(AlarmLog)
alarmLog.NeType = alarmData.NeType
@@ -451,7 +460,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
alarmLog.EventTime = eventTime
log.Trace("alarmLog:", alarmLog)
affected, err = session.Insert(alarmLog)
affected, err := session.Insert(alarmLog)
if err != nil && affected <= 0 {
log.Error("Failed to insert alarm_log:", err)
}
@@ -470,6 +479,28 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
services.ResponseStatusOK200Null(w)
}
type AlarmEvent struct {
AlarmSeq int `json:"alarmSeq"`
AlarmId string `json:"alarmId" xorm:"alarm_id"`
NeId string `json:"neId"`
AlarmCode int `json:"alarmCode"`
AlarmTitle string `json:"alarmTitle"`
EventTime string `json:"eventTime"`
AlarmType string `json:"alarmType"`
OrigSeverity string `json:"origSeverity"`
PVFlag string `json:"pvFlag" xorm:"pv_flag"`
NeName string `json:"neName"`
NeType string `json:"neType"`
ObjectUid string `json:"objectUid" xorm:"object_uid"`
ObjectName string `json:"objectName" xorm:"object_name"`
ObjectType string `json:"objectType" xorm:"object_type"`
LocationInfo string `json:"locationInfo"`
Province string `json:"province"`
SpecificProblem string `json:"specificProblem"`
SpecificProblemID string `json:"specificProblemID" xorm:"specific_problem_id"`
AddInfo string `json:"addInfo"`
}
// process alarm get from NFs
func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
log.Debug("GetAlarmFromNF processing... ")