1
0

feat: 合并代码

This commit is contained in:
TsMask
2023-10-26 09:33:51 +08:00
parent d63db9dd6c
commit 08a908c3f4
38 changed files with 780 additions and 203 deletions

View File

@@ -455,13 +455,23 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
log.Error("Request error:", err)
return
}
vars := mux.Vars(r)
neType := vars["elementTypeValue"]
neTypeLower := strings.ToLower(neType)
// Get alarms from OMC return 204
if neTypeLower == strings.ToLower(config.GetYamlConfig().OMC.NeType) {
log.Infof("Return no content alarms from %s", neType)
services.ResponseStatusOK204NoContent(w)
return
}
//var neInfo *dborm.NeInfo
var nes []dborm.NeInfo
_, err = dborm.XormGetAllNeInfo(&nes)
if err != nil {
log.Error("Failed to get all ne info:", err)
services.ResponseInternalServerError500DatabaseOperationFailed(w)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
@@ -481,15 +491,24 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
//services.ResponseInternalServerError500ProcessError(w, err)
continue
}
body := response.Body()
log.Debug("Request body:", string(body))
alarmArray := new([]Alarm)
err = json.Unmarshal(body, &alarmArray)
if err != nil {
log.Error("Failed to Unmarshal:", err)
//services.ResponseInternalServerError500ProcessError(w, err)
switch response.StatusCode() {
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
body := response.Body()
log.Debug("Request body:", string(body))
err = json.Unmarshal(body, &alarmArray)
if err != nil {
log.Error("Failed to Unmarshal:", err)
//services.ResponseInternalServerError500ProcessError(w, err)
continue
}
default:
log.Error("Failed to get alarms:", response.Status)
continue
}
valueJson, err := dborm.XormGetAAConfig()
if err != nil {
log.Error("Failed to XormGetAAConfig:", err)
@@ -514,7 +533,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
exist, err := session.Table("alarm").
Where("ne_type=? and ne_id=? and alarm_id=? and alarm_status=1", alarmData.NeType, alarmData.NeId, alarmData.AlarmId).
Exist()
if err == nil || exist == false {
if err == nil || !exist {
log.Info("Not found active alarm: ne_id=%s, alarm_id=%s", alarmData.NeId, alarmData.AlarmId)
continue
}
@@ -523,7 +542,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
tm, _ := time.Parse(time.RFC3339, alarmData.EventTime)
log.Debugf("EventTime:%s tm:%d tm-datetime:%s", alarmData.EventTime, tm, tm.Local().Format(time.DateTime))
alarmData.ClearTime.Time = tm
if IsNeedToAckAlarm(valueJson, &alarmData) == true {
if IsNeedToAckAlarm(valueJson, &alarmData) {
SetAlarmAckInfo(valueJson, &alarmData)
log.Debug("alarmData:", alarmData)
affected, err := session.
@@ -578,7 +597,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
}
log.Debugf("neType=%s, neId=%s, eventTime=%s, severity=%s", alarmData.NeType, alarmData.NeId, alarmData.EventTime, severity)
if has == true && severity > alarmData.OrigSeverity {
if has && severity > alarmData.OrigSeverity {
// update exist record
_, err := session.Table("alarm").
Where("ne_type=? and ne_id=? and event_time=?", alarmData.NeType, alarmData.NeId, alarmData.EventTime).
@@ -597,7 +616,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
Where("alarm_id=? and ne_type=? and ne_id=? and alarm_status=1",
alarmData.AlarmId, alarmData.NeType, alarmData.NeId).
Exist()
if err == nil && has == true {
if err == nil && has {
log.Warn("Exist the same alarm")
continue
}
@@ -617,7 +636,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
log.Debugf("neType=%s, neId=%s, currentSeq=%s, activeAlarmNum=%d",
alarmData.NeType, alarmData.NeId, currentSeq, activeAlarmNum)
if has == true {
if has {
seq, _ := strconv.Atoi(currentSeq)
alarmData.AlarmSeq = seq + 1
if alarmData.AlarmSeq > global.MaxInt32Number {
@@ -642,7 +661,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
}
log.Debugf("neType=%s, neId=%s, eventTime=%s, severity=%s", alarmData.NeType, alarmData.NeId, alarmData.EventTime, severity)
if has == false || severity == alarmData.OrigSeverity {
if !has || severity == alarmData.OrigSeverity {
alarmData.PerceivedSeverity = alarmData.OrigSeverity
} else if severity > alarmData.OrigSeverity {
alarmData.PerceivedSeverity = alarmData.OrigSeverity
@@ -661,7 +680,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
alarmData.ObjectUid = alarmData.NeId
alarmData.ObjectType = "VNFM"
alarmData.EventTime = global.GetFmtTimeString(time.RFC3339, alarmData.EventTime, time.DateTime)
if IsNeedToAckAlarm(valueJson, &alarmData) == true {
if IsNeedToAckAlarm(valueJson, &alarmData) {
SetAlarmAckInfo(valueJson, &alarmData)
}
log.Trace("alarmData:", alarmData)

View File

@@ -272,12 +272,12 @@ func TcpdumpNeUPFTask(w http.ResponseWriter, r *http.Request) {
if body.RunType == "start_str" {
fileLogName := fmt.Sprintf("tmp_%s_%s.log", body.NeType, body.NeId)
filePcapName := fmt.Sprintf("tmp_%s_%s.pcap", body.NeType, body.NeId)
scriptStr := "#!/bin/expect\nset capcmd [lindex $argv 0]\nspawn telnet localhost 5002\nexpect \"upfd1# \"\nsend \"$capcmd\\n\"\nexpect \"upfd1# \"\nsend \"quit\\n\"\nexpect \"eof\""
scriptStr := "set capcmd [lindex $argv 0]\nspawn telnet localhost 5002\nexpect \"upfd1# \"\nsend \"$capcmd\\n\"\nexpect \"upfd1# \"\nsend \"quit\\n\"\nexpect \"eof\""
writeLog := fmt.Sprintf(" > %s 2>&1 \ncat %s", fileLogName, fileLogName) // 执行信息写入日志文件输出避免弹出code 127
capCmdStr := fmt.Sprintf("%s file %s", body.Cmd, filePcapName)
cmdStr := fmt.Sprintf("cd /tmp\n\necho '%s' > cap.sh\n\nchmod +x cap.sh\n\n./cap.sh '%s'%s", scriptStr, capCmdStr, writeLog)
cmdStr := fmt.Sprintf("cd /tmp\n\necho '%s' > cap.sh\n\nchmod +x cap.sh\n\nexpect ./cap.sh '%s'%s", scriptStr, capCmdStr, writeLog)
usernameNe := conf.Get("ne.user").(string) // 网元统一用户
sshHost := fmt.Sprintf("%s@%s", usernameNe, neInfo.Ip)
msg, err := cmd.ExecWithCheck("ssh", sshHost, cmdStr)
@@ -303,12 +303,12 @@ func TcpdumpNeUPFTask(w http.ResponseWriter, r *http.Request) {
if body.RunType == "stop_str" {
fileLogName := fmt.Sprintf("tmp_%s_%s.log", body.NeType, body.NeId)
filePcapName := fmt.Sprintf("tmp_%s_%s.pcap", body.NeType, body.NeId)
scriptStr := "#!/bin/expect\nset capcmd [lindex $argv 0]\nspawn telnet localhost 5002\nexpect \"upfd1# \"\nsend \"$capcmd\\n\"\nexpect \"upfd1# \"\nsend \"quit\\n\"\nexpect \"eof\""
scriptStr := "set capcmd [lindex $argv 0]\nspawn telnet localhost 5002\nexpect \"upfd1# \"\nsend \"$capcmd\\n\"\nexpect \"upfd1# \"\nsend \"quit\\n\"\nexpect \"eof\""
writeLog := fmt.Sprintf(" > %s 2>&1 \ncat %s", fileLogName, fileLogName) // 执行信息写入日志文件输出避免弹出code 127
capCmdStr := body.Cmd
cmdStr := fmt.Sprintf("cd /tmp\n\necho '%s' > cap.sh\n\nchmod +x cap.sh\n\n./cap.sh '%s'%s", scriptStr, capCmdStr, writeLog)
cmdStr := fmt.Sprintf("cd /tmp\n\necho '%s' > cap.sh\n\nchmod +x cap.sh\n\nexpect ./cap.sh '%s'%s", scriptStr, capCmdStr, writeLog)
usernameNe := conf.Get("ne.user").(string) // 网元统一用户
sshHost := fmt.Sprintf("%s@%s", usernameNe, neInfo.Ip)