fix: generate ne state alarm
This commit is contained in:
@@ -128,7 +128,7 @@ tasks:
|
||||
at: 00:30
|
||||
do: TaskGenLicenseAlarm
|
||||
- name: Task of Generate NE system state alarm
|
||||
status: Active
|
||||
status: Inactive
|
||||
uri: /api/rest/faultManagement/v1/elementType/%s/objectType/alarms
|
||||
params: 10000
|
||||
interval: 5
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ems.agt/features/fm"
|
||||
@@ -11,6 +13,7 @@ import (
|
||||
"ems.agt/lib/global"
|
||||
"ems.agt/lib/log"
|
||||
"ems.agt/restagent/config"
|
||||
"ems.agt/src/framework/cron"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
@@ -26,11 +29,25 @@ type BarProcessor struct {
|
||||
// 执行次数
|
||||
count int
|
||||
}
|
||||
|
||||
type BarParams struct {
|
||||
Duration int `json:"duration"`
|
||||
AlarmID string `json:"alarmID"`
|
||||
AlarmCode int `json:"alarmCode"`
|
||||
AlarmTitle string `json:"alarmTitle"`
|
||||
AlarmType string `json:"alarmType"`
|
||||
OrigSeverity string `json:"origSeverity"`
|
||||
ObjectUID string `json:"objectUID"`
|
||||
ObjectName string `json:"objectName"`
|
||||
ObjectType string `json:"objectType"`
|
||||
SpecificProblem string `json:"specificProblem"`
|
||||
SpecificProblemID string `json:"specificProblemID"`
|
||||
AddInfo string `json:"AddInfo"`
|
||||
Threshold int64 `json:"threshold"`
|
||||
}
|
||||
|
||||
// type BarParams struct {
|
||||
// Duration int `json:"duration"`
|
||||
// }
|
||||
|
||||
type Alarm struct {
|
||||
Id int `json:"-" xorm:"pk 'id' autoincr"`
|
||||
AlarmSeq int `json:"alarmSeq"`
|
||||
@@ -62,42 +79,31 @@ type Alarm struct {
|
||||
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(400 * time.Millisecond))
|
||||
// SetRetryCount(1).
|
||||
// SetRetryWaitTime(time.Duration(1 * time.Second)).
|
||||
// SetRetryMaxWaitTime(time.Duration(2 * time.Second))
|
||||
//client.SetTimeout(2 * time.Second)
|
||||
}
|
||||
|
||||
func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
var err error
|
||||
|
||||
s.count++
|
||||
// options := data.(cron.JobData)
|
||||
// // sysJob := options.SysJob
|
||||
// // var params BarParams
|
||||
options := data.(cron.JobData)
|
||||
sysJob := options.SysJob
|
||||
var alarmDefine BarParams
|
||||
|
||||
// // // err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
||||
// // // if err == nil {
|
||||
// // // duration = params.Duration
|
||||
// // // }
|
||||
err = json.Unmarshal([]byte(sysJob.TargetParams), &alarmDefine)
|
||||
if err == nil {
|
||||
log.Error("Failed to Unmarshal:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var nes []dborm.NeInfo
|
||||
_, err = dborm.XormGetAllNeInfo(&nes)
|
||||
if err != nil {
|
||||
log.Error("Failed to get all ne info:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
succActiveAlarmNum := 0
|
||||
failActiveAlarmNum := 0
|
||||
succClearAlarmNum := 0
|
||||
@@ -118,21 +124,21 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
}
|
||||
log.Debug("neState:", *neState)
|
||||
|
||||
params := "10000"
|
||||
// params := "10000"
|
||||
|
||||
alarmDefine, err := dborm.XormGetAlarmDefine(params)
|
||||
if err != nil {
|
||||
log.Error("Failed to get alarm_define:", err)
|
||||
continue
|
||||
} else if alarmDefine == nil {
|
||||
log.Error("Not found data from alarm_define")
|
||||
continue
|
||||
}
|
||||
// alarmDefine, err := dborm.XormGetAlarmDefine(params)
|
||||
// if err != nil {
|
||||
// log.Error("Failed to get alarm_define:", err)
|
||||
// continue
|
||||
// } else if alarmDefine == nil {
|
||||
// log.Error("Not found data from alarm_define")
|
||||
// continue
|
||||
// }
|
||||
|
||||
log.Debug("alarmDefine:", alarmDefine)
|
||||
// log.Debug("alarmDefine:", alarmDefine)
|
||||
|
||||
sql = fmt.Sprintf("select * from alarm where alarm_id = '%s' and ne_type='%s' and ne_id = '%s' order by event_time desc limit 1",
|
||||
alarmDefine.AlarmId, ne.NeType, ne.RmUID)
|
||||
alarmDefine.AlarmID, ne.NeType, ne.RmUID)
|
||||
alarm, err := dborm.XormGetDataBySQL(sql)
|
||||
if err != nil {
|
||||
log.Error("Failed to get alarm:", err)
|
||||
@@ -163,11 +169,12 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
|
||||
// clear alarm, todo
|
||||
var alarmSeq int = 1
|
||||
SpecificProblem := fmt.Sprintf(alarmDefine.SpecificProblem, alarmDefine.Threshold)
|
||||
threshold := strconv.FormatInt(alarmDefine.Threshold, 10)
|
||||
SpecificProblem := strings.ReplaceAll(alarmDefine.SpecificProblem, "{threshold}", threshold)
|
||||
locationInfo := fmt.Sprintf("SystemManagement.State: NE heartbeat timestamp=%s,threshold=%v", timestamp, alarmDefine.Threshold)
|
||||
alarmData := &Alarm{
|
||||
AlarmSeq: alarmSeq,
|
||||
AlarmId: alarmDefine.AlarmId,
|
||||
AlarmId: alarmDefine.AlarmID,
|
||||
NeId: ne.RmUID,
|
||||
NeType: ne.NeType,
|
||||
NeName: ne.NeName,
|
||||
@@ -178,12 +185,12 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
AlarmType: alarmDefine.AlarmType,
|
||||
AlarmStatus: fm.AlarmStatusClear,
|
||||
OrigSeverity: alarmDefine.OrigSeverity,
|
||||
ObjectUid: alarmDefine.ObjectUid,
|
||||
ObjectUid: alarmDefine.ObjectUID,
|
||||
ObjectName: alarmDefine.ObjectName,
|
||||
ObjectType: alarmDefine.ObjectType,
|
||||
LocationInfo: locationInfo,
|
||||
SpecificProblem: SpecificProblem,
|
||||
SpecificProblemID: alarmDefine.SpecificProblemId,
|
||||
SpecificProblemID: alarmDefine.SpecificProblemID,
|
||||
AddInfo: alarmDefine.AddInfo,
|
||||
EventTime: time.Now().Local().Format(time.RFC3339),
|
||||
}
|
||||
@@ -229,11 +236,12 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
SpecificProblem := fmt.Sprintf(alarmDefine.SpecificProblem, alarmDefine.Threshold)
|
||||
threshold := strconv.FormatInt(alarmDefine.Threshold, 10)
|
||||
SpecificProblem := strings.ReplaceAll(alarmDefine.SpecificProblem, "{threshold}", threshold)
|
||||
locationInfo := fmt.Sprintf("SystemManagement.State: NE heartbeat timestamp=%s,threshold=%v", timestamp, alarmDefine.Threshold)
|
||||
alarmData := &Alarm{
|
||||
AlarmSeq: alarmSeq,
|
||||
AlarmId: alarmDefine.AlarmId,
|
||||
AlarmId: alarmDefine.AlarmID,
|
||||
NeId: ne.RmUID,
|
||||
NeType: ne.NeType,
|
||||
NeName: ne.NeName,
|
||||
@@ -244,12 +252,12 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
AlarmType: alarmDefine.AlarmType,
|
||||
AlarmStatus: fm.AlarmStatusActive,
|
||||
OrigSeverity: alarmDefine.OrigSeverity,
|
||||
ObjectUid: alarmDefine.ObjectUid,
|
||||
ObjectUid: alarmDefine.ObjectUID,
|
||||
ObjectName: alarmDefine.ObjectName,
|
||||
ObjectType: alarmDefine.ObjectType,
|
||||
LocationInfo: locationInfo,
|
||||
SpecificProblem: SpecificProblem,
|
||||
SpecificProblemID: alarmDefine.SpecificProblemId,
|
||||
SpecificProblemID: alarmDefine.SpecificProblemID,
|
||||
AddInfo: alarmDefine.AddInfo,
|
||||
EventTime: time.Now().Local().Format(time.RFC3339),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user