"strings"
"time"
- "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+ clientruntime "github.com/go-openapi/runtime/client"
+ "github.com/prometheus/alertmanager/api/v2/client"
+ "github.com/prometheus/alertmanager/api/v2/client/alert"
+
apiclient "gerrit.oran-osc.org/r/ric-plt/o1mediator/pkg/appmgrclient"
apixapp "gerrit.oran-osc.org/r/ric-plt/o1mediator/pkg/appmgrclient/xapp"
apimodel "gerrit.oran-osc.org/r/ric-plt/o1mediator/pkg/appmgrmodel"
+
+ "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+
)
type PodStatus struct {
var log = xapp.Logger
-func NewSBIClient(host, baseUrl string, prot []string, timo int) *SBIClient {
- return &SBIClient{host, baseUrl, prot, time.Duration(timo) * time.Second}
+func NewSBIClient(appmgrAddr, alertmgrAddr string, timo int) *SBIClient {
+ return &SBIClient{appmgrAddr, alertmgrAddr, time.Duration(timo) * time.Second}
}
-func (s *SBIClient) CreateTransport() *apiclient.RICAppmgr {
- return apiclient.New(httptransport.New(s.host, s.baseUrl, s.prot), strfmt.Default)
+func (s *SBIClient) CreateTransport(host string) *apiclient.RICAppmgr {
+ return apiclient.New(httptransport.New(host, "/ric/v1/", []string{"http"}), strfmt.Default)
}
func (s *SBIClient) BuildXappDescriptor(name, namespace, release, version string) *apimodel.XappDescriptor {
params := apixapp.NewDeployXappParamsWithTimeout(s.timeout).WithXappDescriptor(xappDesc)
log.Info("SBI: DeployXapp=%v", params)
- result, err := s.CreateTransport().Xapp.DeployXapp(params)
+ result, err := s.CreateTransport(s.appmgrAddr).Xapp.DeployXapp(params)
if err != nil {
log.Error("SBI: DeployXapp unsuccessful: %v", err)
} else {
params := apixapp.NewUndeployXappParamsWithTimeout(s.timeout).WithXAppName(name)
log.Info("SBI: UndeployXapp=%v", params)
- result, err := s.CreateTransport().Xapp.UndeployXapp(params)
+ result, err := s.CreateTransport(s.appmgrAddr).Xapp.UndeployXapp(params)
if err != nil {
log.Error("SBI: UndeployXapp unsuccessful: %v", err)
} else {
func (s *SBIClient) GetDeployedXapps() error {
params := apixapp.NewGetAllXappsParamsWithTimeout(s.timeout)
- result, err := s.CreateTransport().Xapp.GetAllXapps(params)
+ result, err := s.CreateTransport(s.appmgrAddr).Xapp.GetAllXapps(params)
if err != nil {
log.Error("GET unsuccessful: %v", err)
} else {
func (s *SBIClient) ModifyXappConfig(xappConfig *apimodel.XAppConfig) error {
params := apixapp.NewModifyXappConfigParamsWithTimeout(s.timeout).WithXAppConfig(xappConfig)
- result, err := s.CreateTransport().Xapp.ModifyXappConfig(params)
+ result, err := s.CreateTransport(s.appmgrAddr).Xapp.ModifyXappConfig(params)
if err != nil {
log.Error("SBI: ModifyXappConfig unsuccessful: %v", err)
} else {
xapp.Logger.Debug("Command executed successfully!")
return stdout.String(), nil
}
+
+func (s *SBIClient) GetAlerts() (*alert.GetAlertsOK, error) {
+ xapp.Logger.Info("Fetching alerts ...")
+
+ cr := clientruntime.New(s.alertmgrAddr, "/api/v2", []string{"http"})
+ resp, err := client.New(cr, strfmt.Default).Alert.GetAlerts(nil)
+ if err != nil {
+ xapp.Logger.Error("Fetching alerts failed with error: %v", err)
+ return nil, err
+ }
+
+ return resp, nil
+}
\ No newline at end of file