fix: 补充缺失代码
This commit is contained in:
@@ -5,7 +5,9 @@ package cm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"time"
|
||||||
|
|
||||||
"ems.agt/lib/log"
|
"ems.agt/lib/log"
|
||||||
)
|
)
|
||||||
@@ -64,3 +66,30 @@ func ExecOsCmd(command, os string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StartSSHCmdWithTimeout(duration int, sshHost, cmdStr string) error {
|
||||||
|
timeout := time.Duration(duration) * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时
|
||||||
|
defer cancel()
|
||||||
|
cmd := exec.CommandContext(ctx, "ssh", sshHost, cmdStr)
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunSSHCmd(sshHost, cmdStr string) error {
|
||||||
|
cmd := exec.Command("ssh", sshHost, cmdStr)
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
package cm
|
package cm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"time"
|
||||||
|
|
||||||
"ems.agt/lib/log"
|
"ems.agt/lib/log"
|
||||||
)
|
)
|
||||||
@@ -51,3 +54,30 @@ func ExecOsCmd(command, os string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StartSSHCmdWithTimeout(duration int, sshHost, cmdStr string) error {
|
||||||
|
timeout := time.Duration(duration) * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时
|
||||||
|
defer cancel()
|
||||||
|
cmd := exec.CommandContext(ctx, "ssh", sshHost, cmdStr)
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunSSHCmd(sshHost, cmdStr string) error {
|
||||||
|
cmd := exec.Command("ssh", sshHost, cmdStr)
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"ems.agt/lib/log"
|
"ems.agt/lib/log"
|
||||||
"ems.agt/lib/services"
|
"ems.agt/lib/services"
|
||||||
"ems.agt/restagent/config"
|
"ems.agt/restagent/config"
|
||||||
|
tokenConst "ems.agt/src/framework/constants/token"
|
||||||
|
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@@ -22,6 +23,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
UriParamOmcNeConfig = config.DefaultUriPrefix + "/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig"
|
UriParamOmcNeConfig = config.DefaultUriPrefix + "/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig"
|
||||||
|
UriOmcNeConfig = config.DefaultUriPrefix + "/systemManagement/v1/elementType/omc/objectType/config/omcNeConfig"
|
||||||
// NE CM export/import
|
// NE CM export/import
|
||||||
NeCmUri = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/cm"
|
NeCmUri = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/cm"
|
||||||
// NE info
|
// NE info
|
||||||
@@ -34,6 +36,7 @@ var (
|
|||||||
UriNeInstance = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/instance/{action}"
|
UriNeInstance = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/instance/{action}"
|
||||||
|
|
||||||
CustomUriParamOmcNeConfig = config.UriPrefix + "/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig"
|
CustomUriParamOmcNeConfig = config.UriPrefix + "/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig"
|
||||||
|
CustomUriOmcNeConfig = config.UriPrefix + "/systemManagement/v1/elementType/omc/objectType/config/omcNeConfig"
|
||||||
CustomNeCmUri = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/cm"
|
CustomNeCmUri = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/cm"
|
||||||
CustomUriNeInfo = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/neInfo"
|
CustomUriNeInfo = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/neInfo"
|
||||||
CustomUriNeCmFile = config.UriPrefix + "/systemManagement/{apiVersion}/{neType}/neBackup/{fileName}"
|
CustomUriNeCmFile = config.UriPrefix + "/systemManagement/{apiVersion}/{neType}/neBackup/{fileName}"
|
||||||
@@ -125,6 +128,7 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
services.ResponseNotFound404UriNotExist(w, r)
|
services.ResponseNotFound404UriNotExist(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
neTypeUpper := strings.ToUpper(neType)
|
||||||
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
|
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
|
||||||
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -145,7 +149,7 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Debug("NE info:", neInfo)
|
log.Debug("NE info:", neInfo)
|
||||||
|
|
||||||
//if !config.GetYamlConfig().OMC.Chk2Ne {
|
//if !config.GetYamlConfig().OMC.Chk2Ne {
|
||||||
if syncFlag == "false" {
|
if syncFlag == "false" || neTypeUpper == config.GetYamlConfig().OMC.NeType {
|
||||||
neInfo.Status = NEStatusMaintain
|
neInfo.Status = NEStatusMaintain
|
||||||
affected, err := dborm.XormInsertNeInfo(neInfo)
|
affected, err := dborm.XormInsertNeInfo(neInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -231,6 +235,8 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
services.ResponseNotFound404UriNotExist(w, r)
|
services.ResponseNotFound404UriNotExist(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
neTypeLower := strings.ToLower(neType)
|
||||||
|
neTypeUpper := strings.ToUpper(neType)
|
||||||
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
|
syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false)
|
||||||
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -246,7 +252,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Debug("NE info:", neInfo)
|
log.Debug("NE info:", neInfo)
|
||||||
|
|
||||||
//if !config.GetYamlConfig().OMC.Chk2Ne {
|
//if !config.GetYamlConfig().OMC.Chk2Ne {
|
||||||
if syncFlag == "false" {
|
if syncFlag == "false" || neTypeUpper == config.GetYamlConfig().OMC.NeType {
|
||||||
neInfo.Status = NEStatusMaintain
|
neInfo.Status = NEStatusMaintain
|
||||||
affected, err := dborm.XormUpdateNeInfo(neInfo)
|
affected, err := dborm.XormUpdateNeInfo(neInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -263,7 +269,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port)
|
hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port)
|
||||||
//hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port)
|
//hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port)
|
||||||
apiUri := fmt.Sprintf(UriParamOmcNeConfig, strings.ToLower(neType))
|
apiUri := fmt.Sprintf(UriParamOmcNeConfig, neTypeLower)
|
||||||
requestURI2NF := fmt.Sprintf("%s%s", hostUri, apiUri)
|
requestURI2NF := fmt.Sprintf("%s%s", hostUri, apiUri)
|
||||||
log.Debug("requestURI2NF:", requestURI2NF)
|
log.Debug("requestURI2NF:", requestURI2NF)
|
||||||
|
|
||||||
@@ -279,6 +285,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
body, _ = json.Marshal(omcNeConfig)
|
body, _ = json.Marshal(omcNeConfig)
|
||||||
response, err := client.R().
|
response, err := client.R().
|
||||||
EnableTrace().
|
EnableTrace().
|
||||||
|
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
|
||||||
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
|
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
|
||||||
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
||||||
SetBody(body).
|
SetBody(body).
|
||||||
@@ -316,6 +323,28 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PutOMCNeConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
neType := vars["elementTypeValue"]
|
||||||
|
if neType == "" {
|
||||||
|
log.Error("elementTypeValue is empty")
|
||||||
|
services.ResponseNotFound404UriNotExist(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to io.ReadAll:", err)
|
||||||
|
services.ResponseNotFound404UriNotExist(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
neInfo := new(dborm.NeInfo)
|
||||||
|
_ = json.Unmarshal(body, neInfo)
|
||||||
|
neInfo.NeType = strings.ToUpper(neType)
|
||||||
|
|
||||||
|
services.ResponseStatusOK204NoContent(w)
|
||||||
|
}
|
||||||
|
|
||||||
func DeleteNeInfo(w http.ResponseWriter, r *http.Request) {
|
func DeleteNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Debug("DeleteNeInfo processing... ")
|
log.Debug("DeleteNeInfo processing... ")
|
||||||
|
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
getNeInfoURI := restHostPort + getNeInfoPattern
|
getNeInfoURI := restHostPort + getNeInfoPattern
|
||||||
neId := services.GetUriParamString(r, "ne_id", ",", true, true)
|
neId := services.GetUriParamString(r, "ne_id", ",", true, true)
|
||||||
if neId == "" {
|
if neId == "" {
|
||||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status='0'+and+ne_type='%s'", neType)
|
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%s'", neType)
|
||||||
} else {
|
} else {
|
||||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status='0'+and+ne_type='%v'+and+ne_id+in+%v", neType, neId)
|
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%v'+and+ne_id+in+%v", neType, neId)
|
||||||
}
|
}
|
||||||
log.Debug("getNeInfoURI:", getNeInfoURI)
|
log.Debug("getNeInfoURI:", getNeInfoURI)
|
||||||
|
|
||||||
@@ -63,11 +63,11 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
||||||
Get(getNeInfoURI)
|
Get(getNeInfoURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Get from database is failure!")
|
log.Error("Failed to Get:", err)
|
||||||
services.ResponseInternalServerError500NFConnectRefused(w)
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug("NE info:", string(resp.Body()))
|
log.Trace("NE info:", string(resp.Body()))
|
||||||
|
|
||||||
// var neList []dborm.NeInfo
|
// var neList []dborm.NeInfo
|
||||||
neList, _ := dborm.XormParseResult(resp.Body())
|
neList, _ := dborm.XormParseResult(resp.Body())
|
||||||
|
|||||||
@@ -699,14 +699,32 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
} else if fileType == 2 {
|
} else if fileType == 2 {
|
||||||
dpkgCmd := fmt.Sprintf("sudo dpkg -i --force-all '%s'", filePath)
|
dpkgCmd := fmt.Sprintf("sudo dpkg -i --force-all '%s'", filePath)
|
||||||
cmd := exec.Command("ssh", sshHost, dpkgCmd)
|
err := RunSSHCmd(sshHost, dpkgCmd)
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
log.Debugf("Exec output: %v", string(out))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Faile to execute dpkg command:", err)
|
log.Error("Faile to execute dpkg command:", err)
|
||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// timeout := time.Duration(config.GetYamlConfig().OMC.CmdTimeout) * time.Second
|
||||||
|
// ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时
|
||||||
|
// defer cancel()
|
||||||
|
// cmd := exec.CommandContext(ctx, "ssh", sshHost, dpkgCmd)
|
||||||
|
// var stdout, stderr bytes.Buffer
|
||||||
|
// cmd.Stdout = &stdout
|
||||||
|
// cmd.Stderr = &stderr
|
||||||
|
// err := cmd.Start()
|
||||||
|
// if err != nil {
|
||||||
|
// log.Error("Faile to execute dpkg command: %v, err: %s", err, stderr.String())
|
||||||
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// out, err := cmd.CombinedOutput()
|
||||||
|
// log.Debugf("Exec output: %v", string(out))
|
||||||
|
// if err != nil {
|
||||||
|
// log.Error("Faile to execute dpkg command:", err)
|
||||||
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
err := global.ErrCMUnknownSoftwareFormat
|
err := global.ErrCMUnknownSoftwareFormat
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
tm, _ := time.Parse(time.RFC3339, alarmData.EventTime)
|
tm, _ := time.Parse(time.RFC3339, alarmData.EventTime)
|
||||||
log.Debugf("EventTime:%s tm:%d tm-datetime:%s", alarmData.EventTime, tm, tm.Local().Format(time.DateTime))
|
log.Debugf("EventTime:%s tm:%d tm-datetime:%s", alarmData.EventTime, tm, tm.Local().Format(time.DateTime))
|
||||||
alarmData.ClearTime.Time = tm
|
alarmData.ClearTime.Time = tm
|
||||||
if IsNeedToAckAlarm(valueJson, &alarmData) == true {
|
if IsNeedToAckAlarm(valueJson, &alarmData) {
|
||||||
SetAlarmAckInfo(valueJson, &alarmData)
|
SetAlarmAckInfo(valueJson, &alarmData)
|
||||||
affected, err := session.Where("ne_type=? and ne_id=? and alarm_id=? and alarm_status=1", alarmData.NeType, alarmData.NeId, alarmData.AlarmId).
|
affected, err := session.Where("ne_type=? and ne_id=? and alarm_id=? and alarm_status=1", alarmData.NeType, alarmData.NeId, alarmData.AlarmId).
|
||||||
Cols("alarm_status", "clear_type", "clear_time", "ack_state", "ack_time", "ack_user").
|
Cols("alarm_status", "clear_type", "clear_time", "ack_state", "ack_time", "ack_user").
|
||||||
@@ -285,7 +285,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Error("Failed to get alarm:", err)
|
log.Error("Failed to get alarm:", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if has == true {
|
if has {
|
||||||
seq, _ = strconv.Atoi(currentSeq)
|
seq, _ = strconv.Atoi(currentSeq)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
log.Debugf("neType=%s, neId=%s, eventTime=%s, severity=%s", alarmData.NeType, alarmData.NeId, alarmData.EventTime, severity)
|
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
|
// update exist record
|
||||||
_, err := session.Table("alarm").
|
_, err := session.Table("alarm").
|
||||||
Where("ne_type=? and ne_id=? and event_time=? and alarm_status=1", alarmData.NeType, alarmData.NeId, alarmData.EventTime).
|
Where("ne_type=? and ne_id=? and event_time=? and alarm_status=1", alarmData.NeType, alarmData.NeId, alarmData.EventTime).
|
||||||
@@ -339,7 +339,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
Where("alarm_id=? and ne_type=? and ne_id=? and alarm_status=1",
|
Where("alarm_id=? and ne_type=? and ne_id=? and alarm_status=1",
|
||||||
alarmData.AlarmId, alarmData.NeType, alarmData.NeId).
|
alarmData.AlarmId, alarmData.NeType, alarmData.NeId).
|
||||||
Exist()
|
Exist()
|
||||||
if err == nil && has == true {
|
if err == nil && has {
|
||||||
log.Warn("Exist the same alarm")
|
log.Warn("Exist the same alarm")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -359,7 +359,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Debugf("neType=%s, neId=%s, currentSeq=%s activeAlarmNum=%d",
|
log.Debugf("neType=%s, neId=%s, currentSeq=%s activeAlarmNum=%d",
|
||||||
alarmData.NeType, alarmData.NeId, currentSeq, activeAlarmNum)
|
alarmData.NeType, alarmData.NeId, currentSeq, activeAlarmNum)
|
||||||
|
|
||||||
if has == true {
|
if has {
|
||||||
seq, _ := strconv.Atoi(currentSeq)
|
seq, _ := strconv.Atoi(currentSeq)
|
||||||
alarmData.AlarmSeq = seq + 1
|
alarmData.AlarmSeq = seq + 1
|
||||||
if alarmData.AlarmSeq > global.MaxInt32Number {
|
if alarmData.AlarmSeq > global.MaxInt32Number {
|
||||||
@@ -384,7 +384,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
log.Debugf("neType=%s, neId=%s, eventTime=%s, severity=%s", alarmData.NeType, alarmData.NeId, alarmData.EventTime, severity)
|
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
|
alarmData.PerceivedSeverity = alarmData.OrigSeverity
|
||||||
} else if severity > alarmData.OrigSeverity {
|
} else if severity > alarmData.OrigSeverity {
|
||||||
alarmData.PerceivedSeverity = alarmData.OrigSeverity
|
alarmData.PerceivedSeverity = alarmData.OrigSeverity
|
||||||
@@ -407,9 +407,9 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
alarmData.LocationInfo = fmt.Sprintf("Host:%s", r.RemoteAddr)
|
alarmData.LocationInfo = fmt.Sprintf("Host:%s", r.RemoteAddr)
|
||||||
}
|
}
|
||||||
if alarmData.AddInfo == "" {
|
if alarmData.AddInfo == "" {
|
||||||
alarmData.LocationInfo = fmt.Sprintf("subNeInfo:%s", alarmData.NeType)
|
alarmData.AddInfo = fmt.Sprintf("subNeInfo:%s", alarmData.NeType)
|
||||||
}
|
}
|
||||||
if IsNeedToAckAlarm(valueJson, &alarmData) == true {
|
if IsNeedToAckAlarm(valueJson, &alarmData) {
|
||||||
SetAlarmAckInfo(valueJson, &alarmData)
|
SetAlarmAckInfo(valueJson, &alarmData)
|
||||||
}
|
}
|
||||||
log.Debug("alarmData:", alarmData)
|
log.Debug("alarmData:", alarmData)
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// const (
|
||||||
//经过测试,linux下,延时需要大于100ms
|
// //经过测试,linux下,延时需要大于100ms
|
||||||
TIME_DELAY_AFTER_WRITE = 200
|
// TIME_DELAY_AFTER_WRITE = 200
|
||||||
)
|
// )
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Data []string `json:"data"`
|
Data []string `json:"data"`
|
||||||
@@ -48,6 +48,15 @@ var (
|
|||||||
CustomUriOmMmlInt = config.UriPrefix + "/omManagement/{apiVersion}/mml/{neType}/{neId}"
|
CustomUriOmMmlInt = config.UriPrefix + "/omManagement/{apiVersion}/mml/{neType}/{neId}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// func init() {
|
||||||
|
// if config.GetYamlConfig().MML.Sleep != 0 {
|
||||||
|
// TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
|
||||||
|
// }
|
||||||
|
// if config.GetYamlConfig().MML.DeadLine != 0 {
|
||||||
|
// TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Debug("PostMMLToNF processing... ")
|
log.Debug("PostMMLToNF processing... ")
|
||||||
|
|
||||||
@@ -56,6 +65,16 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Error("Request error:", err)
|
log.Error("Request error:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 经过测试,linux下,延时需要大于100ms
|
||||||
|
var TIME_DELAY_AFTER_WRITE time.Duration = 200
|
||||||
|
var TIME_DEAD_LINE time.Duration = 10
|
||||||
|
if config.GetYamlConfig().MML.Sleep != 0 {
|
||||||
|
TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
|
||||||
|
}
|
||||||
|
if config.GetYamlConfig().MML.DeadLine != 0 {
|
||||||
|
TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
|
||||||
|
}
|
||||||
|
|
||||||
pack := "mml"
|
pack := "mml"
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
module := vars["managedType"]
|
module := vars["managedType"]
|
||||||
@@ -72,7 +91,8 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Debugf("token:%s, method:%s, managementType:%s dbname:%s, tbname:%s pack:%s",
|
log.Debugf("token:%s, method:%s, managementType:%s dbname:%s, tbname:%s pack:%s",
|
||||||
token, r.Method, module, neType, neId[0], pack)
|
token, r.Method, module, neType, neId[0], pack)
|
||||||
|
|
||||||
var buf [8192]byte
|
var buf [20 * 1024]byte
|
||||||
|
//buf := make([]byte, 0)
|
||||||
var n int
|
var n int
|
||||||
var mmlResult []string
|
var mmlResult []string
|
||||||
|
|
||||||
@@ -215,7 +235,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||||
|
|
||||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||||
_, err = conn.Write([]byte(loginStr))
|
_, err = conn.Write([]byte(loginStr))
|
||||||
@@ -254,7 +274,8 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符
|
re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符
|
||||||
//re := regexp.MustCompile(`[\x00-\x1F\x7F]`)
|
//re := regexp.MustCompile(`[\x00-\x1F\x7F]`)
|
||||||
// upf telnet buffer只能读取一次,需要去掉前面的多余字符
|
// upf telnet buffer只能读取一次,需要去掉前面的多余字符
|
||||||
result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "")
|
//result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "")
|
||||||
|
result := re1.ReplaceAllString(string(buf[0:n-len(neType)-2]), "")
|
||||||
result = re2.ReplaceAllString(result, "")
|
result = re2.ReplaceAllString(result, "")
|
||||||
mmlResult = append(mmlResult, result)
|
mmlResult = append(mmlResult, result)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
@@ -286,7 +307,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
// services.ResponseWithJson(w, http.StatusOK, response)
|
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||||
|
|
||||||
_, err = conn.Write([]byte(config.GetYamlConfig().MML.User + "\r\n"))
|
_, err = conn.Write([]byte(config.GetYamlConfig().MML.User + "\r\n"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -405,7 +426,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
|
|
||||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||||
_, err = conn.Write([]byte(loginStr))
|
_, err = conn.Write([]byte(loginStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package security
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image/color"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -24,6 +25,7 @@ import (
|
|||||||
"ems.agt/restagent/config"
|
"ems.agt/restagent/config"
|
||||||
srcConfig "ems.agt/src/framework/config"
|
srcConfig "ems.agt/src/framework/config"
|
||||||
"ems.agt/src/framework/redis"
|
"ems.agt/src/framework/redis"
|
||||||
|
"github.com/mojocn/base64Captcha"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -308,3 +310,102 @@ func LoginOMC(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
ctx.JSON(w, 200, result.Err(nil))
|
ctx.JSON(w, 200, result.Err(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取验证码
|
||||||
|
//
|
||||||
|
// GET /captchaImage
|
||||||
|
func CaptchaImage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
configService := sysConfigService.NewServiceSysConfig
|
||||||
|
|
||||||
|
// 从数据库配置获取验证码开关 true开启,false关闭
|
||||||
|
captchaEnabledStr := configService.SelectConfigValueByKey("sys.account.captchaEnabled")
|
||||||
|
captchaEnabled, err := strconv.ParseBool(captchaEnabledStr)
|
||||||
|
if err != nil {
|
||||||
|
captchaEnabled = false
|
||||||
|
}
|
||||||
|
if !captchaEnabled {
|
||||||
|
ctx.JSON(w, 200, result.Ok(map[string]any{
|
||||||
|
"captchaEnabled": captchaEnabled,
|
||||||
|
}))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成唯一标识
|
||||||
|
verifyKey := ""
|
||||||
|
data := map[string]any{
|
||||||
|
"captchaEnabled": captchaEnabled,
|
||||||
|
"uuid": "",
|
||||||
|
"img": "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
|
||||||
|
}
|
||||||
|
|
||||||
|
// char 字符验证
|
||||||
|
driverCaptcha := &base64Captcha.DriverString{
|
||||||
|
//Height png height in pixel.
|
||||||
|
Height: 40,
|
||||||
|
// Width Captcha png width in pixel.
|
||||||
|
Width: 120,
|
||||||
|
//NoiseCount text noise count.
|
||||||
|
NoiseCount: 4,
|
||||||
|
//Length random string length.
|
||||||
|
Length: 4,
|
||||||
|
//Source is a unicode which is the rand string from.
|
||||||
|
Source: "023456789abcdefghjkmnprstuvwxyz",
|
||||||
|
//ShowLineOptions := OptionShowHollowLine | OptionShowSlimeLine | OptionShowSineLine .
|
||||||
|
ShowLineOptions: base64Captcha.OptionShowHollowLine,
|
||||||
|
//BgColor captcha image background color (optional)
|
||||||
|
BgColor: &color.RGBA{
|
||||||
|
R: 250,
|
||||||
|
G: 250,
|
||||||
|
B: 250,
|
||||||
|
A: 255, // 不透明
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// 验证码生成
|
||||||
|
id, question, answer := driverCaptcha.GenerateIdQuestionAnswer()
|
||||||
|
// 验证码表达式解析输出
|
||||||
|
item, err := driverCaptcha.DrawCaptcha(question)
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("Generate Id Question Answer %s : %v", question, err)
|
||||||
|
} else {
|
||||||
|
data["uuid"] = id
|
||||||
|
data["img"] = item.EncodeB64string()
|
||||||
|
verifyKey = cachekey.CAPTCHA_CODE_KEY + id
|
||||||
|
cache.SetLocalTTL(verifyKey, answer, 120*time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 本地开发下返回验证码结果,方便接口调试
|
||||||
|
// text, ok := cache.GetLocalTTL(verifyKey)
|
||||||
|
// if ok {
|
||||||
|
// data["text"] = text.(string)
|
||||||
|
// }
|
||||||
|
|
||||||
|
ctx.JSON(w, 200, result.Ok(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录用户信息
|
||||||
|
func UserInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
|
loginUser, err := ctx.LoginUser(r)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(w, 200, result.OkData(err.Error()))
|
||||||
|
}
|
||||||
|
// 角色权限集合,管理员拥有所有权限
|
||||||
|
userId := fmt.Sprint(loginUser.UserID)
|
||||||
|
isAdmin := srcConfig.IsAdmin(userId)
|
||||||
|
roles, perms := service.NewServiceAccount.RoleAndMenuPerms(userId, isAdmin)
|
||||||
|
|
||||||
|
ctx.JSON(w, 200, result.OkData(map[string]any{
|
||||||
|
"user": loginUser.User,
|
||||||
|
"roles": roles,
|
||||||
|
"permissions": perms,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录用户路由信息
|
||||||
|
func Routers(w http.ResponseWriter, r *http.Request) {
|
||||||
|
userID := ctx.LoginUserToUserID(r)
|
||||||
|
|
||||||
|
// 前端路由,管理员拥有所有
|
||||||
|
isAdmin := srcConfig.IsAdmin(userID)
|
||||||
|
buildMenus := service.NewServiceAccount.RouteMenus(userID, isAdmin)
|
||||||
|
ctx.JSON(w, 200, result.OkData(buildMenus))
|
||||||
|
}
|
||||||
|
|||||||
@@ -750,7 +750,7 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
restHostPort := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port)
|
restHostPort := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port)
|
||||||
getNeInfoPattern := fmt.Sprintf(config.DefaultUriPrefix+"/databaseManagement/v1/elementType/%s/objectType/ne_info",
|
getNeInfoPattern := fmt.Sprintf(config.DefaultUriPrefix+"/databaseManagement/v1/elementType/%s/objectType/ne_info",
|
||||||
config.GetYamlConfig().Database.Name)
|
config.GetYamlConfig().Database.Name)
|
||||||
getNeInfoURI := restHostPort + getNeInfoPattern + "?WHERE=status='0'"
|
getNeInfoURI := restHostPort + getNeInfoPattern + "?WHERE=status+in+('0','3')"
|
||||||
log.Debug("getNeInfoPattern:", getNeInfoPattern)
|
log.Debug("getNeInfoPattern:", getNeInfoPattern)
|
||||||
|
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
@@ -774,9 +774,9 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
getNeInfoURI := restHostPort + getNeInfoPattern
|
getNeInfoURI := restHostPort + getNeInfoPattern
|
||||||
neId := services.GetUriParamString(r, "ne_id", ",", true, true)
|
neId := services.GetUriParamString(r, "ne_id", ",", true, true)
|
||||||
if neId == "" {
|
if neId == "" {
|
||||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status='0'+and+ne_type='%s'", neType)
|
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%s'", neType)
|
||||||
} else {
|
} else {
|
||||||
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status='0'+and+ne_type='%v'+and+ne_id+in+%v", neType, neId)
|
getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%v'+and+ne_id+in+%v", neType, neId)
|
||||||
}
|
}
|
||||||
log.Debug("getNeInfoURI:", getNeInfoURI)
|
log.Debug("getNeInfoURI:", getNeInfoURI)
|
||||||
|
|
||||||
@@ -802,7 +802,7 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
for _, ne := range neList {
|
for _, ne := range neList {
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
log.Debugf("r.RemoteAddr: %s omcNeTypeLower: %s", r.RemoteAddr, omcNeTypeLower)
|
log.Debugf("r.RemoteAddr: %s omcNeTypeLower: %s", r.RemoteAddr, omcNeTypeLower)
|
||||||
log.Debug("ne: ", ne)
|
log.Trace("ne: ", ne)
|
||||||
//if strings.ToLower(ne.NeType) != omcNeTypeLower || !strings.Contains(r.RemoteAddr, ne.Ip) {
|
//if strings.ToLower(ne.NeType) != omcNeTypeLower || !strings.Contains(r.RemoteAddr, ne.Ip) {
|
||||||
if strings.ToLower(ne.NeType) != omcNeTypeLower {
|
if strings.ToLower(ne.NeType) != omcNeTypeLower {
|
||||||
hostUri := fmt.Sprintf("http://%s:%v", ne.Ip, ne.Port)
|
hostUri := fmt.Sprintf("http://%s:%v", ne.Ip, ne.Port)
|
||||||
@@ -881,12 +881,13 @@ func GetEMSState(ip string) *SysState {
|
|||||||
version = global.Version
|
version = global.Version
|
||||||
}
|
}
|
||||||
hostName, _ := os.Hostname()
|
hostName, _ := os.Hostname()
|
||||||
|
dbInfo, _ := dborm.XormGetMySQLVersion()
|
||||||
emsState := &SysState{
|
emsState := &SysState{
|
||||||
HostName: hostName,
|
HostName: hostName,
|
||||||
OsInfo: getUnameStr(),
|
OsInfo: getUnameStr(),
|
||||||
DbInfo: "mysql Ver 15.1 Distrib 10.3.35-MariaDB, for Linux (aarch64) using readline 5.1",
|
DbInfo: dbInfo,
|
||||||
IpAddr: []string{ip},
|
IpAddr: []string{ip},
|
||||||
Port: 3030,
|
Port: config.GetYamlConfig().Rest[0].Port,
|
||||||
Version: version,
|
Version: version,
|
||||||
Capability: 9999999,
|
Capability: 9999999,
|
||||||
SerialNum: config.GetYamlConfig().OMC.Sn,
|
SerialNum: config.GetYamlConfig().OMC.Sn,
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func init() {
|
|||||||
return 0, errors.New("quota exceeded")
|
return 0, errors.New("quota exceeded")
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
client.SetTimeout(3 * time.Second)
|
client.SetTimeout(500 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get AvailableAMFs from NSSF
|
// Get AvailableAMFs from NSSF
|
||||||
|
|||||||
Reference in New Issue
Block a user