Ejemplo n.º 1
0
// Separate method to compile RSR fields
func (rf *RequestFilter) CompileValues() (err error) {
	if rf.Type == MetaRSRFields {
		if rf.rsrFields, err = utils.ParseRSRFieldsFromSlice(rf.Values); err != nil {
			return err
		}
	} else if rf.Type == MetaCDRStats {
		rf.cdrStatSThresholds = make([]*RFStatSThreshold, len(rf.Values))
		for i, val := range rf.Values {
			valSplt := strings.Split(val, utils.InInFieldSep)
			if len(valSplt) != 3 {
				return fmt.Errorf("Value %s needs to contain at least 3 items", val)
			}
			st := &RFStatSThreshold{QueueID: valSplt[0], ThresholdType: strings.ToUpper(valSplt[1])}
			if len(st.ThresholdType) < len(MetaMinCapPrefix)+1 {
				return fmt.Errorf("Value %s contains a unsupported ThresholdType format", val)
			} else if !strings.HasPrefix(st.ThresholdType, MetaMinCapPrefix) && !strings.HasPrefix(st.ThresholdType, MetaMaxCapPrefix) {
				return fmt.Errorf("Value %s contains unsupported ThresholdType prefix", val)
			}
			if tv, err := strconv.ParseFloat(valSplt[2], 64); err != nil {
				return err
			} else {
				st.ThresholdValue = tv
			}
			rf.cdrStatSThresholds[i] = st
		}
	}
	return nil
}
Ejemplo n.º 2
0
func NewRequestFilter(rfType, fieldName string, vals []string, cdrStats rpcclient.RpcClientConnection) (*RequestFilter, error) {
	if !utils.IsSliceMember([]string{MetaStringPrefix, MetaTimings, MetaRSRFields, MetaCDRStats, MetaDestinations}, rfType) {
		return nil, fmt.Errorf("Unsupported filter Type: %s", rfType)
	}
	if fieldName == "" && utils.IsSliceMember([]string{MetaStringPrefix, MetaTimings, MetaDestinations}, rfType) {
		return nil, fmt.Errorf("FieldName is mandatory for Type: %s", rfType)
	}
	if len(vals) == 0 && utils.IsSliceMember([]string{MetaStringPrefix, MetaTimings, MetaRSRFields, MetaDestinations, MetaDestinations}, rfType) {
		return nil, fmt.Errorf("Values is mandatory for Type: %s", rfType)
	}
	rf := &RequestFilter{Type: rfType, FieldName: fieldName, Values: vals, cdrStats: cdrStats, cdrStatSThresholds: make([]*RFStatSThreshold, len(vals))}
	if rfType == MetaCDRStats {
		if cdrStats == nil {
			return nil, errors.New("Missing cdrStats information")
		}
		for i, val := range vals {
			valSplt := strings.Split(val, utils.InInFieldSep)
			if len(valSplt) != 3 {
				return nil, fmt.Errorf("Value %s needs to contain at least 3 items", val)
			}
			st := &RFStatSThreshold{QueueID: valSplt[0], ThresholdType: strings.ToUpper(valSplt[1])}
			if len(st.ThresholdType) < len(MetaMinCapPrefix)+1 {
				return nil, fmt.Errorf("Value %s contains a unsupported ThresholdType format", val)
			} else if !strings.HasPrefix(st.ThresholdType, MetaMinCapPrefix) && !strings.HasPrefix(st.ThresholdType, MetaMaxCapPrefix) {
				return nil, fmt.Errorf("Value %s contains unsupported ThresholdType prefix", val)
			}
			if tv, err := strconv.ParseFloat(valSplt[2], 64); err != nil {
				return nil, err
			} else {
				st.ThresholdValue = tv
			}
			rf.cdrStatSThresholds[i] = st
		}
	}
	if rfType == MetaRSRFields {
		var err error
		if rf.rsrFields, err = utils.ParseRSRFieldsFromSlice(vals); err != nil {
			return nil, err
		}
	}
	return rf, nil
}
Ejemplo n.º 3
0
func (self *SmFsConfig) loadFromJsonCfg(jsnCfg *SmFsJsonCfg) error {
	if jsnCfg == nil {
		return nil
	}
	var err error
	if jsnCfg.Enabled != nil {
		self.Enabled = *jsnCfg.Enabled
	}
	if jsnCfg.Rals_conns != nil {
		self.RALsConns = make([]*HaPoolConfig, len(*jsnCfg.Rals_conns))
		for idx, jsnHaCfg := range *jsnCfg.Rals_conns {
			self.RALsConns[idx] = NewDfltHaPoolConfig()
			self.RALsConns[idx].loadFromJsonCfg(jsnHaCfg)
		}
	}
	if jsnCfg.Cdrs_conns != nil {
		self.CDRsConns = make([]*HaPoolConfig, len(*jsnCfg.Cdrs_conns))
		for idx, jsnHaCfg := range *jsnCfg.Cdrs_conns {
			self.CDRsConns[idx] = NewDfltHaPoolConfig()
			self.CDRsConns[idx].loadFromJsonCfg(jsnHaCfg)
		}
	}
	if jsnCfg.Create_cdr != nil {
		self.CreateCdr = *jsnCfg.Create_cdr
	}
	if jsnCfg.Extra_fields != nil {
		if self.ExtraFields, err = utils.ParseRSRFieldsFromSlice(*jsnCfg.Extra_fields); err != nil {
			return err
		}
	}
	if jsnCfg.Debit_interval != nil {
		if self.DebitInterval, err = utils.ParseDurationWithSecs(*jsnCfg.Debit_interval); err != nil {
			return err
		}
	}
	if jsnCfg.Min_call_duration != nil {
		if self.MinCallDuration, err = utils.ParseDurationWithSecs(*jsnCfg.Min_call_duration); err != nil {
			return err
		}
	}
	if jsnCfg.Max_call_duration != nil {
		if self.MaxCallDuration, err = utils.ParseDurationWithSecs(*jsnCfg.Max_call_duration); err != nil {
			return err
		}
	}
	if jsnCfg.Min_dur_low_balance != nil {
		if self.MinDurLowBalance, err = utils.ParseDurationWithSecs(*jsnCfg.Min_dur_low_balance); err != nil {
			return err
		}
	}
	if jsnCfg.Low_balance_ann_file != nil {
		self.LowBalanceAnnFile = *jsnCfg.Low_balance_ann_file
	}
	if jsnCfg.Empty_balance_context != nil {
		self.EmptyBalanceContext = *jsnCfg.Empty_balance_context
	}
	if jsnCfg.Empty_balance_ann_file != nil {
		self.EmptyBalanceAnnFile = *jsnCfg.Empty_balance_ann_file
	}
	if jsnCfg.Subscribe_park != nil {
		self.SubscribePark = *jsnCfg.Subscribe_park
	}
	if jsnCfg.Channel_sync_interval != nil {
		if self.ChannelSyncInterval, err = utils.ParseDurationWithSecs(*jsnCfg.Channel_sync_interval); err != nil {
			return err
		}
	}
	if jsnCfg.Max_wait_connection != nil {
		if self.MaxWaitConnection, err = utils.ParseDurationWithSecs(*jsnCfg.Max_wait_connection); err != nil {
			return err
		}
	}
	if jsnCfg.Event_socket_conns != nil {
		self.EventSocketConns = make([]*FsConnConfig, len(*jsnCfg.Event_socket_conns))
		for idx, jsnConnCfg := range *jsnCfg.Event_socket_conns {
			self.EventSocketConns[idx] = NewDfltFsConnConfig()
			self.EventSocketConns[idx].loadFromJsonCfg(jsnConnCfg)
		}
	}
	return nil
}
Ejemplo n.º 4
0
// Loads from json configuration object, will be used for defaults, config from file and reload, might need lock
func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error {

	// Load sections out of JSON config, stop on error
	jsnGeneralCfg, err := jsnCfg.GeneralJsonCfg()
	if err != nil {
		return err
	}

	jsnListenCfg, err := jsnCfg.ListenJsonCfg()
	if err != nil {
		return err
	}

	jsnTpDbCfg, err := jsnCfg.DbJsonCfg(TPDB_JSN)
	if err != nil {
		return err
	}

	jsnDataDbCfg, err := jsnCfg.DbJsonCfg(DATADB_JSN)
	if err != nil {
		return err
	}

	jsnStorDbCfg, err := jsnCfg.DbJsonCfg(STORDB_JSN)
	if err != nil {
		return err
	}

	jsnBalancerCfg, err := jsnCfg.BalancerJsonCfg()
	if err != nil {
		return err
	}

	jsnRaterCfg, err := jsnCfg.RaterJsonCfg()
	if err != nil {
		return err
	}

	jsnSchedCfg, err := jsnCfg.SchedulerJsonCfg()
	if err != nil {
		return err
	}

	jsnCdrsCfg, err := jsnCfg.CdrsJsonCfg()
	if err != nil {
		return err
	}

	jsnCdrstatsCfg, err := jsnCfg.CdrStatsJsonCfg()
	if err != nil {
		return err
	}

	jsnCdreCfg, err := jsnCfg.CdreJsonCfgs()
	if err != nil {
		return err
	}

	jsnCdrcCfg, err := jsnCfg.CdrcJsonCfg()
	if err != nil {
		return err
	}

	jsnSmFsCfg, err := jsnCfg.SmFsJsonCfg()
	if err != nil {
		return err
	}

	jsnSmKamCfg, err := jsnCfg.SmKamJsonCfg()
	if err != nil {
		return err
	}

	jsnSmOsipsCfg, err := jsnCfg.SmOsipsJsonCfg()
	if err != nil {
		return err
	}

	jsnHistServCfg, err := jsnCfg.HistServJsonCfg()
	if err != nil {
		return err
	}

	jsnPubSubServCfg, err := jsnCfg.PubSubServJsonCfg()
	if err != nil {
		return err
	}

	jsnAliasesServCfg, err := jsnCfg.AliasesServJsonCfg()
	if err != nil {
		return err
	}

	jsnUserServCfg, err := jsnCfg.UserServJsonCfg()
	if err != nil {
		return err
	}

	jsnMailerCfg, err := jsnCfg.MailerJsonCfg()
	if err != nil {
		return err
	}

	// All good, start populating config variables
	if jsnTpDbCfg != nil {
		if jsnTpDbCfg.Db_type != nil {
			self.TpDbType = *jsnTpDbCfg.Db_type
		}
		if jsnTpDbCfg.Db_host != nil {
			self.TpDbHost = *jsnTpDbCfg.Db_host
		}
		if jsnTpDbCfg.Db_port != nil {
			self.TpDbPort = strconv.Itoa(*jsnTpDbCfg.Db_port)
		}
		if jsnTpDbCfg.Db_name != nil {
			self.TpDbName = *jsnTpDbCfg.Db_name
		}
		if jsnTpDbCfg.Db_user != nil {
			self.TpDbUser = *jsnTpDbCfg.Db_user
		}
		if jsnTpDbCfg.Db_passwd != nil {
			self.TpDbPass = *jsnTpDbCfg.Db_passwd
		}
	}

	if jsnDataDbCfg != nil {
		if jsnDataDbCfg.Db_type != nil {
			self.DataDbType = *jsnDataDbCfg.Db_type
		}
		if jsnDataDbCfg.Db_host != nil {
			self.DataDbHost = *jsnDataDbCfg.Db_host
		}
		if jsnDataDbCfg.Db_port != nil {
			self.DataDbPort = strconv.Itoa(*jsnDataDbCfg.Db_port)
		}
		if jsnDataDbCfg.Db_name != nil {
			self.DataDbName = *jsnDataDbCfg.Db_name
		}
		if jsnDataDbCfg.Db_user != nil {
			self.DataDbUser = *jsnDataDbCfg.Db_user
		}
		if jsnDataDbCfg.Db_passwd != nil {
			self.DataDbPass = *jsnDataDbCfg.Db_passwd
		}
		if jsnDataDbCfg.Load_history_size != nil {
			self.LoadHistorySize = *jsnDataDbCfg.Load_history_size
		}
	}

	if jsnStorDbCfg != nil {
		if jsnStorDbCfg.Db_type != nil {
			self.StorDBType = *jsnStorDbCfg.Db_type
		}
		if jsnStorDbCfg.Db_host != nil {
			self.StorDBHost = *jsnStorDbCfg.Db_host
		}
		if jsnStorDbCfg.Db_port != nil {
			self.StorDBPort = strconv.Itoa(*jsnStorDbCfg.Db_port)
		}
		if jsnStorDbCfg.Db_name != nil {
			self.StorDBName = *jsnStorDbCfg.Db_name
		}
		if jsnStorDbCfg.Db_user != nil {
			self.StorDBUser = *jsnStorDbCfg.Db_user
		}
		if jsnStorDbCfg.Db_passwd != nil {
			self.StorDBPass = *jsnStorDbCfg.Db_passwd
		}
		if jsnStorDbCfg.Max_open_conns != nil {
			self.StorDBMaxOpenConns = *jsnStorDbCfg.Max_open_conns
		}
		if jsnStorDbCfg.Max_idle_conns != nil {
			self.StorDBMaxIdleConns = *jsnStorDbCfg.Max_idle_conns
		}
	}

	if jsnGeneralCfg != nil {
		if jsnGeneralCfg.Dbdata_encoding != nil {
			self.DBDataEncoding = *jsnGeneralCfg.Dbdata_encoding
		}
		if jsnGeneralCfg.Default_reqtype != nil {
			self.DefaultReqType = *jsnGeneralCfg.Default_reqtype
		}
		if jsnGeneralCfg.Default_category != nil {
			self.DefaultCategory = *jsnGeneralCfg.Default_category
		}
		if jsnGeneralCfg.Default_tenant != nil {
			self.DefaultTenant = *jsnGeneralCfg.Default_tenant
		}
		if jsnGeneralCfg.Default_subject != nil {
			self.DefaultSubject = *jsnGeneralCfg.Default_subject
		}
		if jsnGeneralCfg.Connect_attempts != nil {
			self.ConnectAttempts = *jsnGeneralCfg.Connect_attempts
		}
		if jsnGeneralCfg.Response_cache_ttl != nil {
			if self.ResponseCacheTTL, err = utils.ParseDurationWithSecs(*jsnGeneralCfg.Response_cache_ttl); err != nil {
				return err
			}
		}
		if jsnGeneralCfg.Reconnects != nil {
			self.Reconnects = *jsnGeneralCfg.Reconnects
		}
		if jsnGeneralCfg.Rounding_decimals != nil {
			self.RoundingDecimals = *jsnGeneralCfg.Rounding_decimals
		}
		if jsnGeneralCfg.Http_skip_tls_verify != nil {
			self.HttpSkipTlsVerify = *jsnGeneralCfg.Http_skip_tls_verify
		}
		if jsnGeneralCfg.Tpexport_dir != nil {
			self.TpExportPath = *jsnGeneralCfg.Tpexport_dir
		}
		if jsnGeneralCfg.Default_timezone != nil {
			self.DefaultTimezone = *jsnGeneralCfg.Default_timezone
		}
		if jsnGeneralCfg.Internal_ttl != nil {
			if self.InternalTtl, err = utils.ParseDurationWithSecs(*jsnGeneralCfg.Internal_ttl); err != nil {
				return err
			}
		}
	}

	if jsnListenCfg != nil {
		if jsnListenCfg.Rpc_json != nil {
			self.RPCJSONListen = *jsnListenCfg.Rpc_json
		}
		if jsnListenCfg.Rpc_gob != nil {
			self.RPCGOBListen = *jsnListenCfg.Rpc_gob
		}
		if jsnListenCfg.Http != nil {
			self.HTTPListen = *jsnListenCfg.Http
		}
	}

	if jsnRaterCfg != nil {
		if jsnRaterCfg.Enabled != nil {
			self.RaterEnabled = *jsnRaterCfg.Enabled
		}
		if jsnRaterCfg.Balancer != nil {
			self.RaterBalancer = *jsnRaterCfg.Balancer
		}
		if jsnRaterCfg.Cdrstats != nil {
			self.RaterCdrStats = *jsnRaterCfg.Cdrstats
		}
		if jsnRaterCfg.Historys != nil {
			self.RaterHistoryServer = *jsnRaterCfg.Historys
		}
		if jsnRaterCfg.Pubsubs != nil {
			self.RaterPubSubServer = *jsnRaterCfg.Pubsubs
		}
		if jsnRaterCfg.Aliases != nil {
			self.RaterAliasesServer = *jsnRaterCfg.Aliases
		}
		if jsnRaterCfg.Users != nil {
			self.RaterUserServer = *jsnRaterCfg.Users
		}
	}

	if jsnBalancerCfg != nil && jsnBalancerCfg.Enabled != nil {
		self.BalancerEnabled = *jsnBalancerCfg.Enabled
	}

	if jsnSchedCfg != nil && jsnSchedCfg.Enabled != nil {
		self.SchedulerEnabled = *jsnSchedCfg.Enabled
	}

	if jsnCdrsCfg != nil {
		if jsnCdrsCfg.Enabled != nil {
			self.CDRSEnabled = *jsnCdrsCfg.Enabled
		}
		if jsnCdrsCfg.Extra_fields != nil {
			if self.CDRSExtraFields, err = utils.ParseRSRFieldsFromSlice(*jsnCdrsCfg.Extra_fields); err != nil {
				return err
			}
		}
		if jsnCdrsCfg.Store_cdrs != nil {
			self.CDRSStoreCdrs = *jsnCdrsCfg.Store_cdrs
		}
		if jsnCdrsCfg.Rater != nil {
			self.CDRSRater = *jsnCdrsCfg.Rater
		}
		if jsnCdrsCfg.Pubsubs != nil {
			self.CDRSPubSub = *jsnCdrsCfg.Pubsubs
		}
		if jsnCdrsCfg.Users != nil {
			self.CDRSUsers = *jsnCdrsCfg.Users
		}
		if jsnCdrsCfg.Aliases != nil {
			self.CDRSAliases = *jsnCdrsCfg.Aliases
		}
		if jsnCdrsCfg.Cdrstats != nil {
			self.CDRSStats = *jsnCdrsCfg.Cdrstats
		}
		if jsnCdrsCfg.Cdr_replication != nil {
			self.CDRSCdrReplication = make([]*CdrReplicationCfg, len(*jsnCdrsCfg.Cdr_replication))
			for idx, rplJsonCfg := range *jsnCdrsCfg.Cdr_replication {
				self.CDRSCdrReplication[idx] = new(CdrReplicationCfg)
				if rplJsonCfg.Transport != nil {
					self.CDRSCdrReplication[idx].Transport = *rplJsonCfg.Transport
				}
				if rplJsonCfg.Server != nil {
					self.CDRSCdrReplication[idx].Server = *rplJsonCfg.Server
				}
				if rplJsonCfg.Synchronous != nil {
					self.CDRSCdrReplication[idx].Synchronous = *rplJsonCfg.Synchronous
				}
				if rplJsonCfg.Cdr_filter != nil {
					if self.CDRSCdrReplication[idx].CdrFilter, err = utils.ParseRSRFields(*rplJsonCfg.Cdr_filter, utils.INFIELD_SEP); err != nil {
						return err
					}
				}
			}
		}
	}

	if jsnCdrstatsCfg != nil {
		if jsnCdrstatsCfg.Enabled != nil {
			self.CDRStatsEnabled = *jsnCdrstatsCfg.Enabled
			if jsnCdrstatsCfg.Save_Interval != nil {
				if self.CDRStatsSaveInterval, err = utils.ParseDurationWithSecs(*jsnCdrstatsCfg.Save_Interval); err != nil {
					return err
				}
			}
		}
	}

	if jsnCdreCfg != nil {
		if self.CdreProfiles == nil {
			self.CdreProfiles = make(map[string]*CdreConfig)
		}
		for profileName, jsnCdre1Cfg := range jsnCdreCfg {
			if _, hasProfile := self.CdreProfiles[profileName]; !hasProfile { // New profile, create before loading from json
				self.CdreProfiles[profileName] = new(CdreConfig)
				if profileName != utils.META_DEFAULT {
					self.CdreProfiles[profileName] = self.dfltCdreProfile.Clone() // Clone default so we do not inherit pointers
				}
			}
			if err = self.CdreProfiles[profileName].loadFromJsonCfg(jsnCdre1Cfg); err != nil { // Update the existing profile with content from json config
				return err
			}
		}
	}

	if jsnCdrcCfg != nil {
		if self.CdrcProfiles == nil {
			self.CdrcProfiles = make(map[string]map[string]*CdrcConfig)
		}
		for profileName, jsnCrc1Cfg := range jsnCdrcCfg {
			if _, hasDir := self.CdrcProfiles[*jsnCrc1Cfg.Cdr_in_dir]; !hasDir {
				self.CdrcProfiles[*jsnCrc1Cfg.Cdr_in_dir] = make(map[string]*CdrcConfig)
			}
			if _, hasProfile := self.CdrcProfiles[profileName]; !hasProfile {
				if profileName == utils.META_DEFAULT {
					self.CdrcProfiles[*jsnCrc1Cfg.Cdr_in_dir][profileName] = new(CdrcConfig)
				} else {
					self.CdrcProfiles[*jsnCrc1Cfg.Cdr_in_dir][profileName] = self.dfltCdrcProfile.Clone() // Clone default so we do not inherit pointers
				}
			}
			if err = self.CdrcProfiles[*jsnCrc1Cfg.Cdr_in_dir][profileName].loadFromJsonCfg(jsnCrc1Cfg); err != nil {
				return err
			}
		}
	}

	if jsnSmFsCfg != nil {
		if err := self.SmFsConfig.loadFromJsonCfg(jsnSmFsCfg); err != nil {
			return err
		}
	}

	if jsnSmKamCfg != nil {
		if err := self.SmKamConfig.loadFromJsonCfg(jsnSmKamCfg); err != nil {
			return err
		}
	}

	if jsnSmOsipsCfg != nil {
		if err := self.SmOsipsConfig.loadFromJsonCfg(jsnSmOsipsCfg); err != nil {
			return err
		}
	}

	if jsnHistServCfg != nil {
		if jsnHistServCfg.Enabled != nil {
			self.HistoryServerEnabled = *jsnHistServCfg.Enabled
		}
		if jsnHistServCfg.History_dir != nil {
			self.HistoryDir = *jsnHistServCfg.History_dir
		}
		if jsnHistServCfg.Save_interval != nil {
			if self.HistorySaveInterval, err = utils.ParseDurationWithSecs(*jsnHistServCfg.Save_interval); err != nil {
				return err
			}
		}
	}

	if jsnPubSubServCfg != nil {
		if jsnPubSubServCfg.Enabled != nil {
			self.PubSubServerEnabled = *jsnPubSubServCfg.Enabled
		}
	}

	if jsnAliasesServCfg != nil {
		if jsnAliasesServCfg.Enabled != nil {
			self.AliasesServerEnabled = *jsnAliasesServCfg.Enabled
		}
	}

	if jsnUserServCfg != nil {
		if jsnUserServCfg.Enabled != nil {
			self.UserServerEnabled = *jsnUserServCfg.Enabled
		}
		if jsnUserServCfg.Indexes != nil {
			self.UserServerIndexes = *jsnUserServCfg.Indexes
		}
	}

	if jsnMailerCfg != nil {
		if jsnMailerCfg.Server != nil {
			self.MailerServer = *jsnMailerCfg.Server
		}
		if jsnMailerCfg.Auth_user != nil {
			self.MailerAuthUser = *jsnMailerCfg.Auth_user
		}
		if jsnMailerCfg.Auth_passwd != nil {
			self.MailerAuthPass = *jsnMailerCfg.Auth_passwd
		}
		if jsnMailerCfg.From_address != nil {
			self.MailerFromAddr = *jsnMailerCfg.From_address
		}
	}
	return nil
}
Ejemplo n.º 5
0
// Loads from json configuration object, will be used for defaults, config from file and reload, might need lock
func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error {

	// Load sections out of JSON config, stop on error
	jsnGeneralCfg, err := jsnCfg.GeneralJsonCfg()
	if err != nil {
		return err
	}

	// Load sections out of JSON config, stop on error
	jsnCacheCfg, err := jsnCfg.CacheJsonCfg()
	if err != nil {
		return err
	}

	jsnListenCfg, err := jsnCfg.ListenJsonCfg()
	if err != nil {
		return err
	}

	jsnTpDbCfg, err := jsnCfg.DbJsonCfg(TPDB_JSN)
	if err != nil {
		return err
	}

	jsnDataDbCfg, err := jsnCfg.DbJsonCfg(DATADB_JSN)
	if err != nil {
		return err
	}

	jsnStorDbCfg, err := jsnCfg.DbJsonCfg(STORDB_JSN)
	if err != nil {
		return err
	}

	jsnBalancerCfg, err := jsnCfg.BalancerJsonCfg()
	if err != nil {
		return err
	}

	jsnRALsCfg, err := jsnCfg.RalsJsonCfg()
	if err != nil {
		return err
	}

	jsnSchedCfg, err := jsnCfg.SchedulerJsonCfg()
	if err != nil {
		return err
	}

	jsnCdrsCfg, err := jsnCfg.CdrsJsonCfg()
	if err != nil {
		return err
	}

	jsnCdrstatsCfg, err := jsnCfg.CdrStatsJsonCfg()
	if err != nil {
		return err
	}

	jsnCdreCfg, err := jsnCfg.CdreJsonCfgs()
	if err != nil {
		return err
	}

	jsnCdrcCfg, err := jsnCfg.CdrcJsonCfg()
	if err != nil {
		return err
	}

	jsnSmGenericCfg, err := jsnCfg.SmGenericJsonCfg()
	if err != nil {
		return err
	}

	jsnSmFsCfg, err := jsnCfg.SmFsJsonCfg()
	if err != nil {
		return err
	}

	jsnSmKamCfg, err := jsnCfg.SmKamJsonCfg()
	if err != nil {
		return err
	}

	jsnSmOsipsCfg, err := jsnCfg.SmOsipsJsonCfg()
	if err != nil {
		return err
	}

	jsnSMAstCfg, err := jsnCfg.SmAsteriskJsonCfg()
	if err != nil {
		return err
	}

	jsnDACfg, err := jsnCfg.DiameterAgentJsonCfg()
	if err != nil {
		return err
	}

	jsnHistServCfg, err := jsnCfg.HistServJsonCfg()
	if err != nil {
		return err
	}

	jsnPubSubServCfg, err := jsnCfg.PubSubServJsonCfg()
	if err != nil {
		return err
	}

	jsnAliasesServCfg, err := jsnCfg.AliasesServJsonCfg()
	if err != nil {
		return err
	}

	jsnUserServCfg, err := jsnCfg.UserServJsonCfg()
	if err != nil {
		return err
	}

	jsnRLSCfg, err := jsnCfg.ResourceLimiterJsonCfg()
	if err != nil {
		return err
	}

	jsnMailerCfg, err := jsnCfg.MailerJsonCfg()
	if err != nil {
		return err
	}

	jsnSureTaxCfg, err := jsnCfg.SureTaxJsonCfg()
	if err != nil {
		return err
	}

	// All good, start populating config variables
	if jsnTpDbCfg != nil {
		if jsnTpDbCfg.Db_type != nil {
			self.TpDbType = *jsnTpDbCfg.Db_type
		}
		if jsnTpDbCfg.Db_host != nil {
			self.TpDbHost = *jsnTpDbCfg.Db_host
		}
		if jsnTpDbCfg.Db_port != nil {
			self.TpDbPort = strconv.Itoa(*jsnTpDbCfg.Db_port)
		}
		if jsnTpDbCfg.Db_name != nil {
			self.TpDbName = *jsnTpDbCfg.Db_name
		}
		if jsnTpDbCfg.Db_user != nil {
			self.TpDbUser = *jsnTpDbCfg.Db_user
		}
		if jsnTpDbCfg.Db_password != nil {
			self.TpDbPass = *jsnTpDbCfg.Db_password
		}
	}

	if jsnDataDbCfg != nil {
		if jsnDataDbCfg.Db_type != nil {
			self.DataDbType = *jsnDataDbCfg.Db_type
		}
		if jsnDataDbCfg.Db_host != nil {
			self.DataDbHost = *jsnDataDbCfg.Db_host
		}
		if jsnDataDbCfg.Db_port != nil {
			self.DataDbPort = strconv.Itoa(*jsnDataDbCfg.Db_port)
		}
		if jsnDataDbCfg.Db_name != nil {
			self.DataDbName = *jsnDataDbCfg.Db_name
		}
		if jsnDataDbCfg.Db_user != nil {
			self.DataDbUser = *jsnDataDbCfg.Db_user
		}
		if jsnDataDbCfg.Db_password != nil {
			self.DataDbPass = *jsnDataDbCfg.Db_password
		}
		if jsnDataDbCfg.Load_history_size != nil {
			self.LoadHistorySize = *jsnDataDbCfg.Load_history_size
		}
	}

	if jsnStorDbCfg != nil {
		if jsnStorDbCfg.Db_type != nil {
			self.StorDBType = *jsnStorDbCfg.Db_type
		}
		if jsnStorDbCfg.Db_host != nil {
			self.StorDBHost = *jsnStorDbCfg.Db_host
		}
		if jsnStorDbCfg.Db_port != nil {
			self.StorDBPort = strconv.Itoa(*jsnStorDbCfg.Db_port)
		}
		if jsnStorDbCfg.Db_name != nil {
			self.StorDBName = *jsnStorDbCfg.Db_name
		}
		if jsnStorDbCfg.Db_user != nil {
			self.StorDBUser = *jsnStorDbCfg.Db_user
		}
		if jsnStorDbCfg.Db_password != nil {
			self.StorDBPass = *jsnStorDbCfg.Db_password
		}
		if jsnStorDbCfg.Max_open_conns != nil {
			self.StorDBMaxOpenConns = *jsnStorDbCfg.Max_open_conns
		}
		if jsnStorDbCfg.Max_idle_conns != nil {
			self.StorDBMaxIdleConns = *jsnStorDbCfg.Max_idle_conns
		}
		if jsnStorDbCfg.Cdrs_indexes != nil {
			self.StorDBCDRSIndexes = *jsnStorDbCfg.Cdrs_indexes
		}
	}

	if jsnGeneralCfg != nil {
		if jsnGeneralCfg.Dbdata_encoding != nil {
			self.DBDataEncoding = *jsnGeneralCfg.Dbdata_encoding
		}
		if jsnGeneralCfg.Default_request_type != nil {
			self.DefaultReqType = *jsnGeneralCfg.Default_request_type
		}
		if jsnGeneralCfg.Default_category != nil {
			self.DefaultCategory = *jsnGeneralCfg.Default_category
		}
		if jsnGeneralCfg.Default_tenant != nil {
			self.DefaultTenant = *jsnGeneralCfg.Default_tenant
		}
		if jsnGeneralCfg.Connect_attempts != nil {
			self.ConnectAttempts = *jsnGeneralCfg.Connect_attempts
		}
		if jsnGeneralCfg.Response_cache_ttl != nil {
			if self.ResponseCacheTTL, err = utils.ParseDurationWithSecs(*jsnGeneralCfg.Response_cache_ttl); err != nil {
				return err
			}
		}
		if jsnGeneralCfg.Reconnects != nil {
			self.Reconnects = *jsnGeneralCfg.Reconnects
		}
		if jsnGeneralCfg.Connect_timeout != nil {
			if self.ConnectTimeout, err = utils.ParseDurationWithSecs(*jsnGeneralCfg.Connect_timeout); err != nil {
				return err
			}
		}
		if jsnGeneralCfg.Reply_timeout != nil {
			if self.ReplyTimeout, err = utils.ParseDurationWithSecs(*jsnGeneralCfg.Reply_timeout); err != nil {
				return err
			}
		}
		if jsnGeneralCfg.Rounding_decimals != nil {
			self.RoundingDecimals = *jsnGeneralCfg.Rounding_decimals
		}
		if jsnGeneralCfg.Http_skip_tls_verify != nil {
			self.HttpSkipTlsVerify = *jsnGeneralCfg.Http_skip_tls_verify
		}
		if jsnGeneralCfg.Tpexport_dir != nil {
			self.TpExportPath = *jsnGeneralCfg.Tpexport_dir
		}
		if jsnGeneralCfg.Httpposter_attempts != nil {
			self.HttpPosterAttempts = *jsnGeneralCfg.Httpposter_attempts
		}
		if jsnGeneralCfg.Http_failed_dir != nil {
			self.HttpFailedDir = *jsnGeneralCfg.Http_failed_dir
		}
		if jsnGeneralCfg.Default_timezone != nil {
			self.DefaultTimezone = *jsnGeneralCfg.Default_timezone
		}
		if jsnGeneralCfg.Internal_ttl != nil {
			if self.InternalTtl, err = utils.ParseDurationWithSecs(*jsnGeneralCfg.Internal_ttl); err != nil {
				return err
			}
		}
		if jsnGeneralCfg.Locking_timeout != nil {
			if self.LockingTimeout, err = utils.ParseDurationWithSecs(*jsnGeneralCfg.Locking_timeout); err != nil {
				return err
			}
		}
	}

	if jsnCacheCfg != nil {
		if err := self.CacheConfig.loadFromJsonCfg(jsnCacheCfg); err != nil {
			return err
		}
	}

	if jsnListenCfg != nil {
		if jsnListenCfg.Rpc_json != nil {
			self.RPCJSONListen = *jsnListenCfg.Rpc_json
		}
		if jsnListenCfg.Rpc_gob != nil {
			self.RPCGOBListen = *jsnListenCfg.Rpc_gob
		}
		if jsnListenCfg.Http != nil {
			self.HTTPListen = *jsnListenCfg.Http
		}
	}

	if jsnRALsCfg != nil {
		if jsnRALsCfg.Enabled != nil {
			self.RALsEnabled = *jsnRALsCfg.Enabled
		}
		if jsnRALsCfg.Balancer != nil {
			self.RALsBalancer = *jsnRALsCfg.Balancer
		}
		if jsnRALsCfg.Cdrstats_conns != nil {
			self.RALsCDRStatSConns = make([]*HaPoolConfig, len(*jsnRALsCfg.Cdrstats_conns))
			for idx, jsnHaCfg := range *jsnRALsCfg.Cdrstats_conns {
				self.RALsCDRStatSConns[idx] = NewDfltHaPoolConfig()
				self.RALsCDRStatSConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnRALsCfg.Historys_conns != nil {
			self.RALsHistorySConns = make([]*HaPoolConfig, len(*jsnRALsCfg.Historys_conns))
			for idx, jsnHaCfg := range *jsnRALsCfg.Historys_conns {
				self.RALsHistorySConns[idx] = NewDfltHaPoolConfig()
				self.RALsHistorySConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnRALsCfg.Pubsubs_conns != nil {
			self.RALsPubSubSConns = make([]*HaPoolConfig, len(*jsnRALsCfg.Pubsubs_conns))
			for idx, jsnHaCfg := range *jsnRALsCfg.Pubsubs_conns {
				self.RALsPubSubSConns[idx] = NewDfltHaPoolConfig()
				self.RALsPubSubSConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnRALsCfg.Aliases_conns != nil {
			self.RALsAliasSConns = make([]*HaPoolConfig, len(*jsnRALsCfg.Aliases_conns))
			for idx, jsnHaCfg := range *jsnRALsCfg.Aliases_conns {
				self.RALsAliasSConns[idx] = NewDfltHaPoolConfig()
				self.RALsAliasSConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnRALsCfg.Users_conns != nil {
			self.RALsUserSConns = make([]*HaPoolConfig, len(*jsnRALsCfg.Users_conns))
			for idx, jsnHaCfg := range *jsnRALsCfg.Users_conns {
				self.RALsUserSConns[idx] = NewDfltHaPoolConfig()
				self.RALsUserSConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnRALsCfg.Rp_subject_prefix_matching != nil {
			self.RpSubjectPrefixMatching = *jsnRALsCfg.Rp_subject_prefix_matching
		}
		if jsnRALsCfg.Lcr_subject_prefix_matching != nil {
			self.LcrSubjectPrefixMatching = *jsnRALsCfg.Lcr_subject_prefix_matching
		}
	}

	if jsnBalancerCfg != nil && jsnBalancerCfg.Enabled != nil {
		self.BalancerEnabled = *jsnBalancerCfg.Enabled
	}

	if jsnSchedCfg != nil && jsnSchedCfg.Enabled != nil {
		self.SchedulerEnabled = *jsnSchedCfg.Enabled
	}

	if jsnCdrsCfg != nil {
		if jsnCdrsCfg.Enabled != nil {
			self.CDRSEnabled = *jsnCdrsCfg.Enabled
		}
		if jsnCdrsCfg.Extra_fields != nil {
			if self.CDRSExtraFields, err = utils.ParseRSRFieldsFromSlice(*jsnCdrsCfg.Extra_fields); err != nil {
				return err
			}
		}
		if jsnCdrsCfg.Store_cdrs != nil {
			self.CDRSStoreCdrs = *jsnCdrsCfg.Store_cdrs
		}
		if jsnCdrsCfg.Cdr_account_summary != nil {
			self.CDRScdrAccountSummary = *jsnCdrsCfg.Cdr_account_summary
		}
		if jsnCdrsCfg.Rals_conns != nil {
			self.CDRSRaterConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Rals_conns))
			for idx, jsnHaCfg := range *jsnCdrsCfg.Rals_conns {
				self.CDRSRaterConns[idx] = NewDfltHaPoolConfig()
				self.CDRSRaterConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnCdrsCfg.Pubsubs_conns != nil {
			self.CDRSPubSubSConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Pubsubs_conns))
			for idx, jsnHaCfg := range *jsnCdrsCfg.Pubsubs_conns {
				self.CDRSPubSubSConns[idx] = NewDfltHaPoolConfig()
				self.CDRSPubSubSConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnCdrsCfg.Users_conns != nil {
			self.CDRSUserSConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Users_conns))
			for idx, jsnHaCfg := range *jsnCdrsCfg.Users_conns {
				self.CDRSUserSConns[idx] = NewDfltHaPoolConfig()
				self.CDRSUserSConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnCdrsCfg.Aliases_conns != nil {
			self.CDRSAliaseSConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Aliases_conns))
			for idx, jsnHaCfg := range *jsnCdrsCfg.Aliases_conns {
				self.CDRSAliaseSConns[idx] = NewDfltHaPoolConfig()
				self.CDRSAliaseSConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnCdrsCfg.Cdrstats_conns != nil {
			self.CDRSStatSConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Cdrstats_conns))
			for idx, jsnHaCfg := range *jsnCdrsCfg.Cdrstats_conns {
				self.CDRSStatSConns[idx] = NewDfltHaPoolConfig()
				self.CDRSStatSConns[idx].loadFromJsonCfg(jsnHaCfg)
			}
		}
		if jsnCdrsCfg.Cdr_replication != nil {
			self.CDRSCdrReplication = make([]*CdrReplicationCfg, len(*jsnCdrsCfg.Cdr_replication))
			for idx, rplJsonCfg := range *jsnCdrsCfg.Cdr_replication {
				self.CDRSCdrReplication[idx] = new(CdrReplicationCfg)
				if rplJsonCfg.Transport != nil {
					self.CDRSCdrReplication[idx].Transport = *rplJsonCfg.Transport
				}
				if rplJsonCfg.Address != nil {
					self.CDRSCdrReplication[idx].Address = *rplJsonCfg.Address
				}
				if rplJsonCfg.Synchronous != nil {
					self.CDRSCdrReplication[idx].Synchronous = *rplJsonCfg.Synchronous
				}
				self.CDRSCdrReplication[idx].Attempts = 1
				if rplJsonCfg.Attempts != nil {
					self.CDRSCdrReplication[idx].Attempts = *rplJsonCfg.Attempts
				}
				if rplJsonCfg.Cdr_filter != nil {
					if self.CDRSCdrReplication[idx].CdrFilter, err = utils.ParseRSRFields(*rplJsonCfg.Cdr_filter, utils.INFIELD_SEP); err != nil {
						return err
					}
				}
			}
		}
	}

	if jsnCdrstatsCfg != nil {
		if jsnCdrstatsCfg.Enabled != nil {
			self.CDRStatsEnabled = *jsnCdrstatsCfg.Enabled
			if jsnCdrstatsCfg.Save_Interval != nil {
				if self.CDRStatsSaveInterval, err = utils.ParseDurationWithSecs(*jsnCdrstatsCfg.Save_Interval); err != nil {
					return err
				}
			}
		}
	}

	if jsnCdreCfg != nil {
		if self.CdreProfiles == nil {
			self.CdreProfiles = make(map[string]*CdreConfig)
		}
		for profileName, jsnCdre1Cfg := range jsnCdreCfg {
			if _, hasProfile := self.CdreProfiles[profileName]; !hasProfile { // New profile, create before loading from json
				self.CdreProfiles[profileName] = new(CdreConfig)
				if profileName != utils.META_DEFAULT {
					self.CdreProfiles[profileName] = self.dfltCdreProfile.Clone() // Clone default so we do not inherit pointers
				}
			}
			if err = self.CdreProfiles[profileName].loadFromJsonCfg(jsnCdre1Cfg); err != nil { // Update the existing profile with content from json config
				return err
			}
		}
	}
	if jsnCdrcCfg != nil {
		if self.CdrcProfiles == nil {
			self.CdrcProfiles = make(map[string][]*CdrcConfig)
		}
		for _, jsnCrc1Cfg := range jsnCdrcCfg {
			if jsnCrc1Cfg.Id == nil || *jsnCrc1Cfg.Id == "" {
				return errors.New("CDRC profile without an id")
			}
			if *jsnCrc1Cfg.Id == utils.META_DEFAULT {
				if self.dfltCdrcProfile == nil {
					self.dfltCdrcProfile = new(CdrcConfig)
				}
			}
			indxFound := -1 // Will be different than -1 if an instance with same id will be found
			pathFound := "" // Will be populated with the path where slice of cfgs was found
			var cdrcInstCfg *CdrcConfig
			for path := range self.CdrcProfiles {
				for i := range self.CdrcProfiles[path] {
					if self.CdrcProfiles[path][i].ID == *jsnCrc1Cfg.Id {
						indxFound = i
						pathFound = path
						cdrcInstCfg = self.CdrcProfiles[path][i]
						break
					}
				}
			}
			if cdrcInstCfg == nil {
				cdrcInstCfg = self.dfltCdrcProfile.Clone()
			}
			if err := cdrcInstCfg.loadFromJsonCfg(jsnCrc1Cfg); err != nil {
				return err
			}
			if cdrcInstCfg.CdrInDir == "" {
				return errors.New("CDRC profile without cdr_in_dir")
			}
			if _, hasDir := self.CdrcProfiles[cdrcInstCfg.CdrInDir]; !hasDir {
				self.CdrcProfiles[cdrcInstCfg.CdrInDir] = make([]*CdrcConfig, 0)
			}
			if indxFound != -1 { // Replace previous config so we have inheritance
				self.CdrcProfiles[pathFound][indxFound] = cdrcInstCfg
			} else {
				self.CdrcProfiles[cdrcInstCfg.CdrInDir] = append(self.CdrcProfiles[cdrcInstCfg.CdrInDir], cdrcInstCfg)
			}
		}
	}
	if jsnSmGenericCfg != nil {
		if err := self.SmGenericConfig.loadFromJsonCfg(jsnSmGenericCfg); err != nil {
			return err
		}
	}
	if jsnSmFsCfg != nil {
		if err := self.SmFsConfig.loadFromJsonCfg(jsnSmFsCfg); err != nil {
			return err
		}
	}

	if jsnSmKamCfg != nil {
		if err := self.SmKamConfig.loadFromJsonCfg(jsnSmKamCfg); err != nil {
			return err
		}
	}

	if jsnSmOsipsCfg != nil {
		if err := self.SmOsipsConfig.loadFromJsonCfg(jsnSmOsipsCfg); err != nil {
			return err
		}
	}

	if jsnSMAstCfg != nil {
		if err := self.smAsteriskCfg.loadFromJsonCfg(jsnSMAstCfg); err != nil {
			return err
		}
	}

	if jsnDACfg != nil {
		if err := self.diameterAgentCfg.loadFromJsonCfg(jsnDACfg); err != nil {
			return err
		}
	}

	if jsnHistServCfg != nil {
		if jsnHistServCfg.Enabled != nil {
			self.HistoryServerEnabled = *jsnHistServCfg.Enabled
		}
		if jsnHistServCfg.History_dir != nil {
			self.HistoryDir = *jsnHistServCfg.History_dir
		}
		if jsnHistServCfg.Save_interval != nil {
			if self.HistorySaveInterval, err = utils.ParseDurationWithSecs(*jsnHistServCfg.Save_interval); err != nil {
				return err
			}
		}
	}

	if jsnPubSubServCfg != nil {
		if jsnPubSubServCfg.Enabled != nil {
			self.PubSubServerEnabled = *jsnPubSubServCfg.Enabled
		}
	}

	if jsnAliasesServCfg != nil {
		if jsnAliasesServCfg.Enabled != nil {
			self.AliasesServerEnabled = *jsnAliasesServCfg.Enabled
		}
	}

	if jsnRLSCfg != nil {
		if self.resourceLimiterCfg == nil {
			self.resourceLimiterCfg = new(ResourceLimiterConfig)
		}
		if self.resourceLimiterCfg.loadFromJsonCfg(jsnRLSCfg); err != nil {
			return err
		}
	}

	if jsnUserServCfg != nil {
		if jsnUserServCfg.Enabled != nil {
			self.UserServerEnabled = *jsnUserServCfg.Enabled
		}
		if jsnUserServCfg.Indexes != nil {
			self.UserServerIndexes = *jsnUserServCfg.Indexes
		}
	}

	if jsnMailerCfg != nil {
		if jsnMailerCfg.Server != nil {
			self.MailerServer = *jsnMailerCfg.Server
		}
		if jsnMailerCfg.Auth_user != nil {
			self.MailerAuthUser = *jsnMailerCfg.Auth_user
		}
		if jsnMailerCfg.Auth_password != nil {
			self.MailerAuthPass = *jsnMailerCfg.Auth_password
		}
		if jsnMailerCfg.From_address != nil {
			self.MailerFromAddr = *jsnMailerCfg.From_address
		}
	}

	if jsnSureTaxCfg != nil { // New config for SureTax
		if self.sureTaxCfg, err = NewSureTaxCfgWithDefaults(); err != nil {
			return err
		}
		if err := self.sureTaxCfg.loadFromJsonCfg(jsnSureTaxCfg); err != nil {
			return err
		}
	}

	return nil
}