X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=manager%2Fcmd%2Frestapi.go;h=a4668aab6474df3051279fd4d5382f2d05d2d2b2;hb=44be37f7fc8cc9d52ca454a7a08ac2d6a883561c;hp=b8062a07a20ade2868e42557b44c047cdeddb84e;hpb=3649fae7a06ad3ad099d0aa4e68f7ca3a2ae5a87;p=ric-plt%2Falarm-go.git diff --git a/manager/cmd/restapi.go b/manager/cmd/restapi.go index b8062a0..a4668aa 100755 --- a/manager/cmd/restapi.go +++ b/manager/cmd/restapi.go @@ -22,12 +22,13 @@ package main import ( "encoding/json" - "gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm" - app "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" - "github.com/gorilla/mux" "net/http" "strconv" "time" + + "gerrit.o-ran-sc.org/r/ric-plt/alarm-go/alarm" + app "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" + "github.com/gorilla/mux" ) func (a *AlarmManager) InjectRoutes() { @@ -41,6 +42,8 @@ func (a *AlarmManager) InjectRoutes() { app.Resource.InjectRoute("/ric/v1/alarms/define/{alarmId}", a.DeleteAlarmDefinition, "DELETE") app.Resource.InjectRoute("/ric/v1/alarms/define", a.GetAlarmDefinition, "GET") app.Resource.InjectRoute("/ric/v1/alarms/define/{alarmId}", a.GetAlarmDefinition, "GET") + + app.Resource.InjectRoute("/ric/v1/symptomdata", a.SymptomDataHandler, "GET") } func (a *AlarmManager) respondWithError(w http.ResponseWriter, code int, message string) { @@ -200,6 +203,8 @@ func (a *AlarmManager) doAction(w http.ResponseWriter, r *http.Request, isRaiseA return err } +// HandleViaRmr is defined but not used as of now +/* func (a *AlarmManager) HandleViaRmr(d alarm.Alarm, isRaiseAlarm bool) error { alarmClient, err := alarm.InitAlarm(d.ManagedObjectId, d.ApplicationId) if err != nil { @@ -215,7 +220,7 @@ func (a *AlarmManager) HandleViaRmr(d alarm.Alarm, isRaiseAlarm bool) error { } return nil -} +}*/ func (a *AlarmManager) SetAlarmConfig(w http.ResponseWriter, r *http.Request) { var m alarm.AlarmConfigParams @@ -239,3 +244,49 @@ func (a *AlarmManager) GetAlarmConfig(w http.ResponseWriter, r *http.Request) { a.respondWithJSON(w, http.StatusOK, m) return } + +func (a *AlarmManager) SymptomDataHandler(w http.ResponseWriter, r *http.Request) { + baseDir := "/tmp/symptomdata/" + if err := app.Util.CreateDir(baseDir); err != nil { + app.Resource.SendSymptomDataError(w, r, "CreateDir failed: "+err.Error()) + return + } + + if b, err := json.Marshal(a.activeAlarms); err == nil { + if err := app.Util.WriteToFile(baseDir+"active_alarms.json", string(b)); err != nil { + app.Resource.SendSymptomDataError(w, r, "writeToFile failed: "+err.Error()) + return + } + } + + if b, err := json.Marshal(a.alarmHistory); err == nil { + if err := app.Util.WriteToFile(baseDir+"alarm_history.json", string(b)); err != nil { + app.Resource.SendSymptomDataError(w, r, "writeToFile failed: "+err.Error()) + return + } + } + + var ac alarm.AlarmConfigParams + ac.MaxActiveAlarms = a.maxActiveAlarms + ac.MaxAlarmHistory = a.maxAlarmHistory + + if b, err := json.Marshal(ac); err == nil { + if err := app.Util.WriteToFile(baseDir+"alarm_config.json", string(b)); err != nil { + app.Resource.SendSymptomDataError(w, r, "writeToFile failed: "+err.Error()) + return + } + } + + var ad RicAlarmDefinitions + for _, alarmDefinition := range alarm.RICAlarmDefinitions { + ad.AlarmDefinitions = append(ad.AlarmDefinitions, alarmDefinition) + } + if b, err := json.Marshal(ad); err == nil { + if err := app.Util.WriteToFile(baseDir+"alarm_defs.json", string(b)); err != nil { + app.Resource.SendSymptomDataError(w, r, "writeToFile failed: "+err.Error()) + return + } + } + + app.Resource.SendSymptomDataFile(w, r, baseDir, "symptomdata.zip") +}