From 14323a9bfca0e64e3710f790a849dbc984dc36dc Mon Sep 17 00:00:00 2001 From: vipin Date: Fri, 25 Sep 2020 10:03:43 +0000 Subject: [PATCH] alarm manager to manage predefined platform alarm definitions in a json file - reads the json file during startup and save the definitions - primarily meant for platform component alarms Change-Id: I522dbafe372c8dc1c0ebfaa7fec9d14615d405e9 Signed-off-by: vipin --- build/Dockerfile | 1 + build/build_ubuntu.sh | 3 +++ build/run.sh | 1 + definitions/alarm-definition.json | 40 +++++++++++++++++++++++++++++++++++++ manager/cmd/manager.go | 42 +++++++++++++++++++++++++++++++++------ manager/cmd/manager_test.go | 22 +++++++++++++++++--- 6 files changed, 100 insertions(+), 9 deletions(-) create mode 100755 definitions/alarm-definition.json diff --git a/build/Dockerfile b/build/Dockerfile index b774e02..6572c49 100755 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -37,6 +37,7 @@ COPY --from=ubuntu-alarm-manager /go/src/am/build/run.sh / COPY --from=ubuntu-alarm-manager /go/src/am/manager/alarm-manager / COPY --from=ubuntu-alarm-manager /go/src/am/config/* / COPY --from=ubuntu-alarm-manager /usr/local/lib /usr/local/lib +COPY --from=ubuntu-alarm-manager /go/src/am/definitions/* / RUN ldconfig diff --git a/build/build_ubuntu.sh b/build/build_ubuntu.sh index 29b9d77..3136eca 100755 --- a/build/build_ubuntu.sh +++ b/build/build_ubuntu.sh @@ -42,6 +42,9 @@ export PATH=$GOPATH/bin:$PATH export CFG_FILE=../config/config-file.json export RMR_SEED_RT=../config/uta_rtg.rt +# xApp stuff +export DEF_FILE=../definitions/alarm-definition.json + GO111MODULE=on GO_ENABLED=0 GOOS=linux # setup version tag diff --git a/build/run.sh b/build/run.sh index db9e0e3..1e1ad85 100755 --- a/build/run.sh +++ b/build/run.sh @@ -24,5 +24,6 @@ # export RMR_SEED_RT=./uta_rtg.rt export RMR_SRC_ID="service-ricplt-alarmmanager-rmr.ricplt" +export DEF_FILE=./alarm-definition.json exec ./alarm-manager -f ./config-file.json diff --git a/definitions/alarm-definition.json b/definitions/alarm-definition.json new file mode 100755 index 0000000..96d255f --- /dev/null +++ b/definitions/alarm-definition.json @@ -0,0 +1,40 @@ +{ + "alarmdefinitions" : [ + { + "alarmId" : 8004, + "alarmText" : "RIC ROUTING TABLE DISTRIBUTION FAILED", + "eventType" : "Processing error", + "operationInstructions" : "Not defined" + }, + { + "alarmId" : 8005, + "alarmText" : "TCP CONNECTIVITY LOST TO DBAAS", + "eventType" : "Communication error", + "operationInstructions" : "Not defined" + }, + { + "alarmId" : 8006, + "alarmText" : "E2 CONNECTIVITY LOST TO G-NODEB", + "eventType" : "Communication error", + "operationInstructions" : "Not defined" + }, + { + "alarmId" : 8007, + "alarmText" : "E2 CONNECTIVITY LOST TO E-NODEB", + "eventType" : "Communication error", + "operationInstructions" : "Not defined" + }, + { + "alarmId" : 8008, + "alarmText" : "ACTIVE ALARM EXCEED MAX THRESHOLD", + "eventType" : "storage warning", + "operationInstructions" : "Clear alarms or raise threshold" + }, + { + "alarmId" : 8009, + "alarmText" : "ALARM HISTORY EXCEED MAX THRESHOLD", + "eventType" : "storage warning", + "operationInstructions" : "Clear alarms or raise threshold" + } + ] +} diff --git a/manager/cmd/manager.go b/manager/cmd/manager.go index 8b4ac74..9d61bd2 100755 --- a/manager/cmd/manager.go +++ b/manager/cmd/manager.go @@ -24,16 +24,16 @@ import ( "encoding/json" "fmt" "time" - + "os" + "gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm" + app "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" clientruntime "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" "github.com/prometheus/alertmanager/api/v2/client" "github.com/prometheus/alertmanager/api/v2/client/alert" "github.com/prometheus/alertmanager/api/v2/models" "github.com/spf13/viper" - - "gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm" - app "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" + "io/ioutil" ) func (a *AlarmManager) StartAlertTimer() { @@ -82,7 +82,7 @@ func (a *AlarmManager) ProcessAlarm(m *alarm.AlarmMessage) (*alert.PostAlertsOK, // Suppress duplicate alarms idx, found := a.IsMatchFound(m.Alarm) - if found && m.AlarmAction == alarm.AlarmActionRaise { + if found && m.AlarmAction == alarm.AlarmActionRaise { app.Logger.Info("Duplicate alarm found, suppressing ...") if m.PerceivedSeverity == a.activeAlarms[idx].PerceivedSeverity { // Duplicate with same severity found @@ -93,7 +93,6 @@ func (a *AlarmManager) ProcessAlarm(m *alarm.AlarmMessage) (*alert.PostAlertsOK, } } - // Clear alarm if found from active alarm list if m.AlarmAction == alarm.AlarmActionClear { if found { @@ -226,6 +225,36 @@ func (a *AlarmManager) ConfigChangeCB(configparam string) { return } +func (a *AlarmManager) ReadAlarmDefinitionFromJson() { + + filename := os.Getenv("DEF_FILE") + file, err := ioutil.ReadFile(filename) + if err == nil { + data := RicAlarmDefinitions{} + err = json.Unmarshal([]byte(file), &data) + if err == nil { + for _, alarmDefinition := range data.AlarmDefinitions { + _, exists := alarm.RICAlarmDefinitions[alarmDefinition.AlarmId] + if exists { + app.Logger.Error("ReadAlarmDefinitionFromJson: alarm definition already exists for %v", alarmDefinition.AlarmId) + } else { + app.Logger.Debug("ReadAlarmDefinitionFromJson: alarm %v", alarmDefinition.AlarmId) + ricAlarmDefintion := new(alarm.AlarmDefinition) + ricAlarmDefintion.AlarmId = alarmDefinition.AlarmId + ricAlarmDefintion.AlarmText = alarmDefinition.AlarmText + ricAlarmDefintion.EventType = alarmDefinition.EventType + ricAlarmDefintion.OperationInstructions = alarmDefinition.OperationInstructions + alarm.RICAlarmDefinitions[alarmDefinition.AlarmId] = ricAlarmDefintion + } + } + } else { + app.Logger.Error("json.Unmarshal failed with error %v", err) + } + } else { + app.Logger.Error("ioutil.ReadFile failed with error %v", err) + } +} + func (a *AlarmManager) Run(sdlcheck bool) { app.Logger.SetMdc("alarmManager", fmt.Sprintf("%s:%s", Version, Hash)) app.SetReadyCB(func(d interface{}) { a.rmrReady = true }, true) @@ -233,6 +262,7 @@ func (a *AlarmManager) Run(sdlcheck bool) { app.AddConfigChangeListener(a.ConfigChangeCB) alarm.RICAlarmDefinitions = make(map[int]*alarm.AlarmDefinition) + a.ReadAlarmDefinitionFromJson() app.Resource.InjectRoute("/ric/v1/alarms", a.RaiseAlarm, "POST") app.Resource.InjectRoute("/ric/v1/alarms", a.ClearAlarm, "DELETE") diff --git a/manager/cmd/manager_test.go b/manager/cmd/manager_test.go index 7398969..f28ff58 100755 --- a/manager/cmd/manager_test.go +++ b/manager/cmd/manager_test.go @@ -50,7 +50,7 @@ func TestMain(M *testing.M) { os.Setenv("ALARM_IF_RMR", "true") alarmManager = NewAlarmManager("localhost:9093", 500) go alarmManager.Run(false) - time.Sleep(time.Duration(2) * time.Second) + time.Sleep(time.Duration(10) * time.Second) // Wait until RMR is up-and-running for !xapp.Rmr.IsReady() { @@ -65,6 +65,22 @@ func TestMain(M *testing.M) { os.Exit(M.Run()) } +func TestGetPreDefinedAlarmDefinitions(t *testing.T) { + xapp.Logger.Info("TestGetPreDefinedAlarmDefinitions") + var alarmDefinition alarm.AlarmDefinition + req, _ := http.NewRequest("GET", "/ric/v1/alarms/define", nil) + vars := map[string]string{"alarmId": strconv.FormatUint(8004, 10)} + req = mux.SetURLVars(req, vars) + handleFunc := http.HandlerFunc(alarmManager.GetAlarmDefinition) + response := executeRequest(req, handleFunc) + checkResponseCode(t, http.StatusOK, response.Code) + json.NewDecoder(response.Body).Decode(&alarmDefinition) + xapp.Logger.Info("alarm definition = %v", alarmDefinition) + if alarmDefinition.AlarmId != alarm.RIC_RT_DISTRIBUTION_FAILED || alarmDefinition.AlarmText != "RIC ROUTING TABLE DISTRIBUTION FAILED" { + t.Errorf("Incorrect alarm definition") + } +} + func TestSetAlarmDefinitions(t *testing.T) { xapp.Logger.Info("TestSetAlarmDefinitions") var alarm8004Definition alarm.AlarmDefinition @@ -95,13 +111,13 @@ func TestSetAlarmDefinitions(t *testing.T) { alarm8008Definition.AlarmId = alarm.ACTIVE_ALARM_EXCEED_MAX_THRESHOLD alarm8008Definition.AlarmText = "ACTIVE ALARM EXCEED MAX THRESHOLD" alarm8008Definition.EventType = "storage warning" - alarm8008Definition.OperationInstructions = "clear alarms or raise threshold" + alarm8008Definition.OperationInstructions = "Clear alarms or raise threshold" var alarm8009Definition alarm.AlarmDefinition alarm8009Definition.AlarmId = alarm.ALARM_HISTORY_EXCEED_MAX_THRESHOLD alarm8009Definition.AlarmText = "ALARM HISTORY EXCEED MAX THRESHOLD" alarm8009Definition.EventType = "storage warning" - alarm8009Definition.OperationInstructions = "clear alarms or raise threshold" + alarm8009Definition.OperationInstructions = "Clear alarms or raise threshold" pbodyParams := RicAlarmDefinitions{AlarmDefinitions: []*alarm.AlarmDefinition{&alarm8004Definition, &alarm8005Definition, &alarm8006Definition, &alarm8007Definition, &alarm8008Definition, &alarm8009Definition}} pbodyEn, _ := json.Marshal(pbodyParams) -- 2.16.6