mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Config options for thresholds
This commit is contained in:
@@ -269,6 +269,7 @@ type CGRConfig struct {
|
||||
UserServerIndexes []string // List of user profile field indexes
|
||||
resourceSCfg *ResourceSConfig // Configuration for resource limiter
|
||||
statsCfg *StatSCfg // Configuration for StatS
|
||||
thresholdSCfg *ThresholdSCfg // configuration for ThresholdS
|
||||
MailerServer string // The server to use when sending emails out
|
||||
MailerAuthUser string // Authenticate to email server using this user
|
||||
MailerAuthPass string // Authenticate to email server with this password
|
||||
@@ -644,6 +645,11 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnThresholdSCfg, err := jsnCfg.ThresholdSJsonCfg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnMailerCfg, err := jsnCfg.MailerJsonCfg()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1098,6 +1104,15 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error {
|
||||
}
|
||||
}
|
||||
|
||||
if jsnThresholdSCfg != nil {
|
||||
if self.thresholdSCfg == nil {
|
||||
self.thresholdSCfg = new(ThresholdSCfg)
|
||||
}
|
||||
if self.thresholdSCfg.loadFromJsonCfg(jsnThresholdSCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if jsnUserServCfg != nil {
|
||||
if jsnUserServCfg.Enabled != nil {
|
||||
self.UserServerEnabled = *jsnUserServCfg.Enabled
|
||||
@@ -1161,6 +1176,10 @@ func (cfg *CGRConfig) StatSCfg() *StatSCfg {
|
||||
return cfg.statsCfg
|
||||
}
|
||||
|
||||
func (cfg *CGRConfig) ThresholdSCfg() *ThresholdSCfg {
|
||||
return cfg.thresholdSCfg
|
||||
}
|
||||
|
||||
// ToDo: fix locking here
|
||||
func (self *CGRConfig) SMAsteriskCfg() *SMAsteriskCfg {
|
||||
cfgChan := <-self.ConfigReloads[utils.SMAsterisk] // Lock config for read or reloads
|
||||
|
||||
@@ -395,31 +395,38 @@ const CGRATES_CFG_JSON = `
|
||||
|
||||
|
||||
"pubsubs": {
|
||||
"enabled": false, // starts PubSub service: <true|false>.
|
||||
"enabled": false, // starts PubSub service: <true|false>.
|
||||
},
|
||||
|
||||
|
||||
"aliases": {
|
||||
"enabled": false, // starts Aliases service: <true|false>.
|
||||
"enabled": false, // starts Aliases service: <true|false>.
|
||||
},
|
||||
|
||||
|
||||
"users": {
|
||||
"enabled": false, // starts User service: <true|false>.
|
||||
"indexes": [], // user profile field indexes
|
||||
"enabled": false, // starts User service: <true|false>.
|
||||
"indexes": [], // user profile field indexes
|
||||
},
|
||||
|
||||
|
||||
"resources": {
|
||||
"enabled": false, // starts ResourceLimiter service: <true|false>.
|
||||
"stats_conns": [], // address where to reach the stats service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234>
|
||||
"store_interval": "", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|*never|$dur>
|
||||
"enabled": false, // starts ResourceLimiter service: <true|false>.
|
||||
"store_interval": "", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|*never|$dur>
|
||||
"stats_conns": [], // address where to reach the stats service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234>
|
||||
},
|
||||
|
||||
|
||||
"stats": {
|
||||
"enabled": false, // starts Stat service: <true|false>.
|
||||
"store_interval": "0s", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|*never|$dur>
|
||||
"store_interval": "", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|*never|$dur>
|
||||
},
|
||||
|
||||
|
||||
"thresholds": {
|
||||
"enabled": false, // starts ThresholdS service: <true|false>.
|
||||
"store_interval": "", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|*never|$dur>
|
||||
"filtered_fields": [], // match filters based on these fields for dynamic filtering, empty to use all
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ const (
|
||||
ALIASESSERV_JSN = "aliases"
|
||||
USERSERV_JSN = "users"
|
||||
RESOURCES_JSON = "resources"
|
||||
STATS_JSON = "stats"
|
||||
THRESHOLDS_JSON = "thresholds"
|
||||
MAILER_JSN = "mailer"
|
||||
SURETAX_JSON = "suretax"
|
||||
)
|
||||
@@ -372,6 +374,18 @@ func (self CgrJsonCfg) StatSJsonCfg() (*StatServJsonCfg, error) {
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (self CgrJsonCfg) ThresholdSJsonCfg() (*ThresholdSJsonCfg, error) {
|
||||
rawCfg, hasKey := self[THRESHOLDS_JSON]
|
||||
if !hasKey {
|
||||
return nil, nil
|
||||
}
|
||||
cfg := new(ThresholdSJsonCfg)
|
||||
if err := json.Unmarshal(*rawCfg, cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (self CgrJsonCfg) MailerJsonCfg() (*MailerJsonCfg, error) {
|
||||
rawCfg, hasKey := self[MAILER_JSN]
|
||||
if !hasKey {
|
||||
|
||||
@@ -693,7 +693,7 @@ func TestDfResourceLimiterSJsonCfg(t *testing.T) {
|
||||
func TestDfStatServiceJsonCfg(t *testing.T) {
|
||||
eCfg := &StatServJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Store_interval: utils.StringPointer("0s"),
|
||||
Store_interval: utils.StringPointer(""),
|
||||
}
|
||||
if cfg, err := dfCgrJsonCfg.StatSJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
@@ -702,6 +702,19 @@ func TestDfStatServiceJsonCfg(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDfThresholdSJsonCfg(t *testing.T) {
|
||||
eCfg := &ThresholdSJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Store_interval: utils.StringPointer(""),
|
||||
Filtered_fields: utils.StringSlicePointer([]string{}),
|
||||
}
|
||||
if cfg, err := dfCgrJsonCfg.ThresholdSJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eCfg, cfg) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eCfg, cfg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDfMailerJsonCfg(t *testing.T) {
|
||||
eCfg := &MailerJsonCfg{
|
||||
Server: utils.StringPointer("localhost"),
|
||||
|
||||
@@ -587,6 +587,16 @@ func TestCgrCfgJSONDefaultStatsCfg(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCgrCfgJSONDefaultThresholdSCfg(t *testing.T) {
|
||||
eThresholdSCfg := &ThresholdSCfg{
|
||||
Enabled: false,
|
||||
StoreInterval: 0,
|
||||
}
|
||||
if !reflect.DeepEqual(eThresholdSCfg, cgrCfg.thresholdSCfg) {
|
||||
t.Errorf("received: %+v, expecting: %+v", eThresholdSCfg, cgrCfg.statsCfg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCgrCfgJSONDefaultsDiameterAgentCfg(t *testing.T) {
|
||||
testDA := &DiameterAgentCfg{
|
||||
Enabled: false,
|
||||
|
||||
@@ -393,6 +393,13 @@ type StatServJsonCfg struct {
|
||||
Store_interval *string
|
||||
}
|
||||
|
||||
// Threshold service config section
|
||||
type ThresholdSJsonCfg struct {
|
||||
Enabled *bool
|
||||
Store_interval *string
|
||||
Filtered_fields *[]string
|
||||
}
|
||||
|
||||
// Mailer config section
|
||||
type MailerJsonCfg struct {
|
||||
Server *string
|
||||
|
||||
46
config/thresholdscfg.go
Normal file
46
config/thresholdscfg.go
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type ThresholdSCfg struct {
|
||||
Enabled bool
|
||||
StoreInterval time.Duration // Dump regularly from cache into dataDB
|
||||
FilteredFields []string
|
||||
}
|
||||
|
||||
func (t *ThresholdSCfg) loadFromJsonCfg(jsnCfg *ThresholdSJsonCfg) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return nil
|
||||
}
|
||||
if jsnCfg.Enabled != nil {
|
||||
t.Enabled = *jsnCfg.Enabled
|
||||
}
|
||||
if jsnCfg.Store_interval != nil {
|
||||
if t.StoreInterval, err = utils.ParseDurationWithSecs(*jsnCfg.Store_interval); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func (ts Thresholds) Sort() {
|
||||
sort.Slice(ts, func(i, j int) bool { return ts[i].tPrfl.Weight > ts[j].tPrfl.Weight })
|
||||
}
|
||||
|
||||
func NewThresholdService(dm *DataManager, filterFields []string, storeInterval time.Duration,
|
||||
func NewThresholdService(dm *DataManager, filteredFields []string, storeInterval time.Duration,
|
||||
statS rpcclient.RpcClientConnection) (tS *ThresholdService, err error) {
|
||||
return &ThresholdService{dm: dm,
|
||||
filterFields: filterFields,
|
||||
|
||||
@@ -452,6 +452,7 @@ const (
|
||||
EventResourcesPrefix = "ers_"
|
||||
MetaSysLog = "*syslog"
|
||||
MetaStdLog = "*stdout"
|
||||
MetaNever = "*never"
|
||||
)
|
||||
|
||||
func buildCacheInstRevPrefixes() {
|
||||
|
||||
Reference in New Issue
Block a user