diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index 94f3bf238..24807784a 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -743,6 +743,80 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { } } +// func testAttributeSProcessEventSentryPeer(t *testing.T) { +// attrPrf1 := &engine.AttributeProfileWithAPIOpts{ +// AttributeProfile: &engine.AttributeProfile{ +// Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, +// ID: "ATTR_SENTRY", +// Contexts: []string{utils.MetaAny}, +// FilterIDs: []string{"*sentrypeer:~*req.IP:ip-addresses"}, +// ActivationInterval: &utils.ActivationInterval{ +// ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), +// }, +// Attributes: []*engine.Attribute{ +// { +// Path: utils.MetaReq + utils.NestingSep + "Field2", +// Value: config.NewRSRParsersMustCompile("BLACKLIST", utils.InfieldSep), +// Type: utils.MetaConstant, +// }, +// }, +// Blocker: true, +// Weight: 5, +// }, +// } +// var result string +// if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { +// t.Error(err) +// } else if result != utils.OK { +// t.Error("Unexpected reply returned", result) +// } + +// var reply *engine.AttributeProfile +// if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, +// utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_SENTRY"}}, &reply); err != nil { +// t.Fatal(err) +// } +// reply.Compile() +// if !reflect.DeepEqual(attrPrf1.AttributeProfile, reply) { +// t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply) +// } +// attrArgs := &utils.CGREvent{ +// Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, +// ID: "HAttribute", +// Event: map[string]any{ +// "IP": "45.155.91.135", +// }, +// APIOpts: map[string]any{ +// utils.OptsAttributesProcessRuns: 1., +// utils.OptsContext: utils.MetaAny, +// }, +// } +// eRply := &engine.AttrSProcessEventReply{ +// MatchedProfiles: []string{"cgrates.org:ATTR_SENTRY"}, +// AlteredFields: []string{"*req.Field2"}, +// CGREvent: &utils.CGREvent{ +// Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, +// ID: "HAttribute", +// Event: map[string]any{ +// "Field2": "BLACKLIST", +// "IP": "45.155.91.135", +// }, +// APIOpts: map[string]any{ +// utils.OptsAttributesProcessRuns: 1., +// utils.OptsContext: utils.MetaAny, +// }, +// }, +// } +// var rplyEv engine.AttrSProcessEventReply +// if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, +// attrArgs, &rplyEv); err != nil { +// t.Error(err) +// } else if !reflect.DeepEqual(eRply, &rplyEv) { +// t.Errorf("Expecting: %s, received: %s", +// utils.ToJSON(eRply), utils.ToJSON(rplyEv)) +// } +// } + func testAttributeSGetAttPrfIDs(t *testing.T) { expected := []string{"ATTR_2", "ATTR_PASS", "ATTR_1", "ATTR_3", "ATTR_Header", "AttributeWithNonSubstitute"} var result []string diff --git a/config/config.go b/config/config.go index 4f7d1e3cc..aa882e89c 100644 --- a/config/config.go +++ b/config/config.go @@ -1883,6 +1883,8 @@ func (cfg *CGRConfig) V1GetConfigAsJSON(args *SectionWithAPIOpts, reply *string) mp = cfg.ConfigSCfg().AsMapInterface() case APIBanCfgJson: mp = cfg.APIBanCfg().AsMapInterface() + case SentryPeerCfgJson: + mp = cfg.SentryPeerCfg().AsMapInterface() case RPCConnsJsonName: mp = cfg.RPCConns().AsMapInterface() case TemplatesJson: @@ -1990,6 +1992,7 @@ func (cfg *CGRConfig) Clone() (cln *CGRConfig) { sipAgentCfg: cfg.sipAgentCfg.Clone(), configSCfg: cfg.configSCfg.Clone(), apiBanCfg: cfg.apiBanCfg.Clone(), + sentryPeerCfg: cfg.sentryPeerCfg.Clone(), coreSCfg: cfg.coreSCfg.Clone(), cacheDP: make(map[string]utils.MapStorage), diff --git a/data/conf/samples/tutinternal/cgrates.json b/data/conf/samples/tutinternal/cgrates.json index 705935671..bbab7e051 100644 --- a/data/conf/samples/tutinternal/cgrates.json +++ b/data/conf/samples/tutinternal/cgrates.json @@ -111,4 +111,9 @@ "apiers_conns": ["*internal"] } +// "sentrypeer":{ +// "addr":"https://sentrypeer.com/api/", +// "token":"put token here", +// }, + } diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json index 3f3de89db..bcd0f4b2e 100644 --- a/data/conf/samples/tutmongo/cgrates.json +++ b/data/conf/samples/tutmongo/cgrates.json @@ -4,7 +4,7 @@ "general": { "log_level": 7, - "reply_timeout": "30s", + "reply_timeout": "1h", }, @@ -54,7 +54,7 @@ "stats_conns": ["*localhost"], "resources_conns": ["*localhost"], "apiers_conns": ["*localhost"], - //"indexed_selects": false, + "indexed_selects": false, }, @@ -127,5 +127,9 @@ "apiers_conns": ["*internal"], }, +// "sentrypeer":{ +// "addr":"https://sentrypeer.com/api/", +// "token":"put token here", +// }, } diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json index 92229e4f3..eef8044b2 100644 --- a/data/conf/samples/tutmysql/cgrates.json +++ b/data/conf/samples/tutmysql/cgrates.json @@ -118,5 +118,9 @@ "apiers_conns": ["*internal"], }, +// "sentrypeer":{ +// "addr":"https://sentrypeer.com/api/", +// "token":"put token here", +// }, } diff --git a/data/conf/samples/tutpostgres/cgrates.json b/data/conf/samples/tutpostgres/cgrates.json index eea667341..08741245c 100644 --- a/data/conf/samples/tutpostgres/cgrates.json +++ b/data/conf/samples/tutpostgres/cgrates.json @@ -103,4 +103,9 @@ "apiers_conns": ["*internal"], }, +// "sentrypeer":{ +// "addr":"https://sentrypeer.com/api/", +// "token":"put token here", +// }, + } diff --git a/engine/datamanager.go b/engine/datamanager.go index 81aacf7a4..b24089df2 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -75,6 +75,7 @@ var ( utils.DispatcherFilterIndexes: {}, utils.FilterIndexPrfx: {}, utils.MetaAPIBan: {}, // not realy a prefix as this is not stored in DB + utils.MetaNotSentryPeer: {}, } ) @@ -119,7 +120,7 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b if dm.cacheCfg.Partitions[utils.CachePrefixToInstance[prfx]].Limit == 0 { return } - if prfx == utils.MetaAPIBan || prfx == utils.MetaDispatchers { // no need for ids in this case + if prfx == utils.MetaAPIBan || prfx == utils.MetaSentryPeer || prfx == utils.MetaDispatchers { // no need for ids in this case ids = []string{utils.EmptyString} } else if len(ids) != 0 && ids[0] == utils.MetaAny { if mustBeCached { @@ -268,6 +269,8 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b _, err = dm.GetItemLoadIDs(utils.EmptyString, true) case utils.MetaAPIBan: _, err = dm.GetAPIBan(utils.EmptyString, config.CgrConfig().APIBanCfg().Keys, false, false, true) + case utils.MetaSentryPeer: + _, err = GetSentryPeer(utils.EmptyString, config.CgrConfig().SentryPeerCfg().Addr, config.CgrConfig().SentryPeerCfg().Token, utils.EmptyString, false, true) } if err != nil { if err != utils.ErrNotFound && err != utils.ErrDSPProfileNotFound && err != utils.ErrDSPHostNotFound { diff --git a/engine/filters.go b/engine/filters.go index 7a601f318..63015cc30 100644 --- a/engine/filters.go +++ b/engine/filters.go @@ -228,19 +228,19 @@ var supportedFiltersType utils.StringSet = utils.NewStringSet([]string{ utils.MetaTimings, utils.MetaRSR, utils.MetaDestinations, utils.MetaEmpty, utils.MetaExists, utils.MetaLessThan, utils.MetaLessOrEqual, utils.MetaGreaterThan, utils.MetaGreaterOrEqual, utils.MetaEqual, - utils.MetaIPNet, utils.MetaAPIBan, utils.MetaActivationInterval, + utils.MetaIPNet, utils.MetaAPIBan, utils.MetaSentryPeer, utils.MetaActivationInterval, utils.MetaRegex}) var needsFieldName utils.StringSet = utils.NewStringSet([]string{ utils.MetaString, utils.MetaPrefix, utils.MetaSuffix, utils.MetaTimings, utils.MetaRSR, utils.MetaDestinations, utils.MetaLessThan, utils.MetaEmpty, utils.MetaExists, utils.MetaLessOrEqual, utils.MetaGreaterThan, - utils.MetaGreaterOrEqual, utils.MetaEqual, utils.MetaIPNet, utils.MetaAPIBan, + utils.MetaGreaterOrEqual, utils.MetaEqual, utils.MetaIPNet, utils.MetaAPIBan, utils.MetaSentryPeer, utils.MetaActivationInterval, utils.MetaRegex}) var needsValues utils.StringSet = utils.NewStringSet([]string{utils.MetaString, utils.MetaPrefix, utils.MetaSuffix, utils.MetaTimings, utils.MetaRSR, utils.MetaDestinations, utils.MetaLessThan, utils.MetaLessOrEqual, utils.MetaGreaterThan, utils.MetaGreaterOrEqual, - utils.MetaEqual, utils.MetaIPNet, utils.MetaAPIBan, utils.MetaActivationInterval, + utils.MetaEqual, utils.MetaIPNet, utils.MetaAPIBan, utils.MetaSentryPeer, utils.MetaActivationInterval, utils.MetaRegex}) // NewFilterRule returns a new filter diff --git a/engine/libtest.go b/engine/libtest.go index 8f546921a..5a85a7fd5 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -538,6 +538,7 @@ func GetDefaultEmptyCacheStats() map[string]*ltcache.CacheStats { utils.CacheEventCharges: {}, utils.CacheReverseFilterIndexes: {}, utils.MetaAPIBan: {}, + utils.MetaSentryPeer: {}, utils.CacheCapsEvents: {}, utils.CacheReplicationHosts: {}, } diff --git a/utils/consts.go b/utils/consts.go index 5ae02affd..2b0a9ed75 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -32,7 +32,7 @@ var ( extraDBPartition = NewStringSet([]string{CacheDispatchers, CacheDispatcherRoutes, CacheDispatcherLoads, CacheDiameterMessages, CacheRPCResponses, CacheClosedSessions, - CacheCDRIDs, CacheRPCConnections, CacheUCH, CacheSTIR, CacheEventCharges, MetaAPIBan, + CacheCDRIDs, CacheRPCConnections, CacheUCH, CacheSTIR, CacheEventCharges, MetaAPIBan, MetaSentryPeer, CacheRatingProfilesTmp, CacheCapsEvents, CacheReplicationHosts}) DataDBPartitions = NewStringSet([]string{CacheDestinations, CacheReverseDestinations, CacheRatingPlans, @@ -87,6 +87,7 @@ var ( CacheLoadIDs: LoadIDPrefix, CacheAccounts: AccountPrefix, CacheReverseFilterIndexes: FilterIndexPrfx, + MetaSentryPeer: MetaSentryPeer, MetaAPIBan: MetaAPIBan, // special case as it is not in a DB CacheDispatchers: MetaDispatchers, }