fix: manual sync alarm failed while abnormal NEs

This commit is contained in:
2024-03-06 17:25:00 +08:00
parent 8e13208363
commit c0f115d97d

View File

@@ -115,6 +115,27 @@ var (
CustomUriAlarmsFmt = config.UriPrefix + "/faultManagement/v1/elementType/%s/objectType/alarms"
)
var client = resty.New()
func init() {
/*
client.
SetTimeout(10 * time.Second).
SetRetryCount(1).
SetRetryWaitTime(1 * time.Second).
SetRetryMaxWaitTime(2 * time.Second).
SetRetryAfter(func(client *resty.Client, resp *resty.Response) (time.Duration, error) {
return 0, errors.New("quota exceeded")
})
*/
client.
SetTimeout(time.Duration(500 * time.Millisecond))
// SetRetryCount(1).
// SetRetryWaitTime(time.Duration(1 * time.Second)).
// SetRetryMaxWaitTime(time.Duration(2 * time.Second))
//client.SetTimeout(2 * time.Second)
}
var xEngine *xorm.Engine
type DatabaseClient struct {
@@ -439,8 +460,8 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) {
if err = AlarmEmailForward(&alarmData); err != nil {
log.Error("Failed to AlarmEmailForward:", err)
}
if err = AlarmForwardBySMS(&alarmData); err != nil {
log.Error("Failed to AlarmForwardBySMS:", err)
if err = AlarmForwardBySMSC(&alarmData); err != nil {
log.Error("Failed to AlarmForwardBySMSC:", err)
}
}
}
@@ -482,7 +503,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
apiUri := fmt.Sprintf(UriAlarmsFmt, strings.ToLower(ne.NeType))
requestURI2NF := fmt.Sprintf("%s%s", hostUri, apiUri)
log.Debug("requestURI2NF: Get ", requestURI2NF)
client := resty.New()
// client := resty.New()
response, err := client.R().
EnableTrace().
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
@@ -498,7 +519,12 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
switch response.StatusCode() {
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
body := response.Body()
log.Debug("Request body:", string(body))
if len(body) == 0 || body == nil {
log.Infof("Empty alarm body from neType=%s, neId=%s", ne.NeType, ne.NeId)
//services.ResponseInternalServerError500ProcessError(w, err)
continue
}
//log.Debug("Request body:", string(body))
err = json.Unmarshal(body, &alarmArray)
if err != nil {
@@ -518,7 +544,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
continue
}
if alarmArray == nil {
log.Info("Not found sync alarms, neType=%s, neId=%s", ne.NeType, ne.NeId)
log.Infof("Not found sync alarms, neType=%s, neId=%s", ne.NeType, ne.NeId)
//services.ResponseInternalServerError500ProcessError(w, err)
continue
}
@@ -536,7 +562,7 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
Where("ne_type=? and ne_id=? and alarm_id=? and alarm_status=1", alarmData.NeType, alarmData.NeId, alarmData.AlarmId).
Exist()
if err == nil || !exist {
log.Info("Not found active alarm: ne_id=%s, alarm_id=%s", alarmData.NeId, alarmData.AlarmId)
log.Infof("Not found active alarm: ne_id=%s, alarm_id=%s", alarmData.NeId, alarmData.AlarmId)
continue
}
alarmData.ClearType = ClearTypeAutoClear
@@ -708,8 +734,8 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
if err = AlarmEmailForward(&alarmData); err != nil {
log.Error("Failed to AlarmEmailForward:", err)
}
if err = AlarmForwardBySMS(&alarmData); err != nil {
log.Error("Failed to AlarmForwardBySMS:", err)
if err = AlarmForwardBySMSC(&alarmData); err != nil {
log.Error("Failed to AlarmForwardBySMSC:", err)
}
}
}
@@ -717,5 +743,5 @@ func GetAlarmFromNF(w http.ResponseWriter, r *http.Request) {
}
}
}
services.ResponseStatusOK200Null(w)
services.ResponseStatusOK204NoContent(w)
}