added sars model,tp,api

This commit is contained in:
gezimbll
2024-06-24 11:06:57 -04:00
committed by Dan Christian Bogos
parent 9d7fcdc0c6
commit 6c2fbbec28
43 changed files with 1401 additions and 24 deletions

View File

@@ -598,6 +598,27 @@ func (sqls *SQLStorage) SetTPSags(sgs []*utils.TPSagsProfile) error {
return nil
}
func (sqls *SQLStorage) SetTPSars(srs []*utils.TPSarsProfile) error {
if len(srs) == 0 {
return nil
}
tx := sqls.db.Begin()
for _, sg := range srs {
if err := tx.Where(&SarsMdl{Tpid: sg.TPid, ID: sg.ID}).Delete(SarsMdl{}).Error; err != nil {
tx.Rollback()
return err
}
for _, msg := range APItoModelSars(sg) {
if err := tx.Create(&msg).Error; err != nil {
tx.Rollback()
return err
}
}
}
tx.Commit()
return nil
}
func (sqls *SQLStorage) SetTPThresholds(ths []*utils.TPThresholdProfile) error {
if len(ths) == 0 {
return nil
@@ -1440,6 +1461,25 @@ func (sqls *SQLStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProf
return asts, nil
}
func (sqls *SQLStorage) GetTPSars(tpid, tenant, id string) ([]*utils.TPSarsProfile, error) {
var srs SarsMdls
q := sqls.db.Where("tpid = ?", tpid)
if len(id) != 0 {
q = q.Where("id = ?", id)
}
if len(tenant) != 0 {
q = q.Where("tenant = ?", tenant)
}
if err := q.Find(&srs).Error; err != nil {
return nil, err
}
asrs := srs.AsTPSars()
if len(asrs) == 0 {
return asrs, utils.ErrNotFound
}
return asrs, nil
}
func (sqls *SQLStorage) GetTPSags(tpid string, tenant string, id string) ([]*utils.TPSagsProfile, error) {
var sgs SagsMdls
q := sqls.db.Where("tpid = ?", tpid)