Documentation ¶
Overview ¶
Rating system designed to be used in VoIP Carriers World Copyright (C) 2013 ITsysCOM
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/>
Index ¶
- Constants
- Variables
- func BalanceKey(tenant, account, direction string) string
- func ConvertMapValStrIf(inMap map[string]string) map[string]interface{}
- func CopyHour(src, dest time.Time) time.Time
- func FSCgrId(uuid string) string
- func FallbackSubjKeys(direction, tenant, tor, fallbackSubjects string) []string
- func FirstNonEmpty(vals ...string) string
- func GenUUID() string
- func IsSliceMember(ss []string, s string) bool
- func MapKeys(m map[string]string) []string
- func MirrorMap(mapIn map[string]string) (map[string]string, error)
- func MissingMapKeys(inMap map[string]string, requiredKeys []string) []string
- func MissingStructFields(s interface{}, mandatories []string) []string
- func NewTPid() string
- func NonemptyStructFields(s interface{}) map[string]interface{}
- func ParseDate(date string) (expDate time.Time, err error)
- func ParseDurationWithSecs(durStr string) (time.Duration, error)
- func ParseTimeDetectLayout(tmStr string) (time.Time, error)
- func Round(x float64, prec int, method string) float64
- func RoundTo(whole, amount time.Duration) time.Duration
- func SHA1(text string) string
- func SliceMemberHasPrefix(ss []string, prfx string) bool
- func SplitPrefix(prefix string) []string
- func StrucToMap(s interface{}) map[string]interface{}
- func UpdateStructWithStrMap(s interface{}, m map[string]string) []string
- type ApiReloadCache
- type ApierTPTiming
- type AttrCacheStats
- type AttrCachedItemAge
- type AttrExpFileCdrs
- type AttrTPRatingProfileIds
- type CacheStats
- type CachedItemAge
- type CgrCdr
- func (cgrCdr CgrCdr) AsRatedCdr(...) (*RatedCDR, error)
- func (cgrCdr CgrCdr) GetAccId() string
- func (cgrCdr CgrCdr) GetAccount() string
- func (cgrCdr CgrCdr) GetAnswerTime() (t time.Time, err error)
- func (cgrCdr CgrCdr) GetCdrHost() string
- func (cgrCdr CgrCdr) GetCdrSource() string
- func (cgrCdr CgrCdr) GetCgrId() string
- func (cgrCdr CgrCdr) GetDestination() string
- func (cgrCdr CgrCdr) GetDirection() string
- func (cgrCdr CgrCdr) GetDuration() time.Duration
- func (cgrCdr CgrCdr) GetExtraFields() map[string]string
- func (cgrCdr CgrCdr) GetOrigId() string
- func (cgrCdr CgrCdr) GetReqType() string
- func (cgrCdr CgrCdr) GetSubject() string
- func (cgrCdr CgrCdr) GetTOR() string
- func (cgrCdr CgrCdr) GetTenant() string
- type DestinationRate
- type ExportedFileCdrs
- type LoggerInterface
- type MonthDays
- type Months
- type RateSlot
- type RatedCDR
- func (ratedCdr *RatedCDR) AsRatedCdr(...) (*RatedCDR, error)
- func (ratedCdr *RatedCDR) GetAccId() string
- func (ratedCdr *RatedCDR) GetAccount() string
- func (ratedCdr *RatedCDR) GetAnswerTime() (time.Time, error)
- func (ratedCdr *RatedCDR) GetCdrHost() string
- func (ratedCdr *RatedCDR) GetCdrSource() string
- func (ratedCdr *RatedCDR) GetCgrId() string
- func (ratedCdr *RatedCDR) GetDestination() string
- func (ratedCdr *RatedCDR) GetDirection() string
- func (ratedCdr *RatedCDR) GetDuration() time.Duration
- func (ratedCdr *RatedCDR) GetExtraFields() map[string]string
- func (ratedCdr *RatedCDR) GetReqType() string
- func (ratedCdr *RatedCDR) GetSubject() string
- func (ratedCdr *RatedCDR) GetTOR() string
- func (ratedCdr *RatedCDR) GetTenant() string
- type RawCDR
- type StdLogger
- func (sl *StdLogger) Alert(m string) (err error)
- func (sl *StdLogger) Close() (err error)
- func (sl *StdLogger) Crit(m string) (err error)
- func (sl *StdLogger) Debug(m string) (err error)
- func (sl *StdLogger) Emerg(m string) (err error)
- func (sl *StdLogger) Err(m string) (err error)
- func (sl *StdLogger) Info(m string) (err error)
- func (sl *StdLogger) Notice(m string) (err error)
- func (sl *StdLogger) Warning(m string) (err error)
- type TPAccountActions
- type TPAction
- type TPActionTiming
- type TPActionTimings
- type TPActionTrigger
- type TPActionTriggers
- type TPActions
- type TPDestination
- type TPDestinationRate
- type TPRate
- type TPRatingActivation
- type TPRatingPlan
- type TPRatingPlanBinding
- type TPRatingProfile
- type TPTiming
- type WeekDays
- type Years
Constants ¶
const ( VERSION = "0.9.1c3" POSTGRES = "postgres" MYSQL = "mysql" MONGO = "mongo" REDIS = "redis" LOCALHOST = "127.0.0.1" FSCDR_FILE_CSV = "freeswitch_file_csv" FSCDR_HTTP_JSON = "freeswitch_http_json" NOT_IMPLEMENTED = "not implemented" PREPAID = "prepaid" POSTPAID = "postpaid" PSEUDOPREPAID = "pseudoprepaid" RATED = "rated" ERR_NOT_IMPLEMENTED = "NOT_IMPLEMENTED" ERR_SERVER_ERROR = "SERVER_ERROR" ERR_NOT_FOUND = "NOT_FOUND" ERR_MANDATORY_IE_MISSING = "MANDATORY_IE_MISSING" ERR_EXISTS = "EXISTS" ERR_BROKEN_REFERENCE = "BROKEN_REFERENCE" TBL_TP_TIMINGS = "tp_timings" TBL_TP_DESTINATIONS = "tp_destinations" TBL_TP_RATES = "tp_rates" TBL_TP_DESTINATION_RATES = "tp_destination_rates" TBL_TP_RATING_PLANS = "tp_rating_plans" TBL_TP_RATE_PROFILES = "tp_rating_profiles" TBL_TP_ACTIONS = "tp_actions" TBL_TP_ACTION_TIMINGS = "tp_action_timings" TBL_TP_ACTION_TRIGGERS = "tp_action_triggers" TBL_TP_ACCOUNT_ACTIONS = "tp_account_actions" TBL_CDRS_PRIMARY = "cdrs_primary" TBL_CDRS_EXTRA = "cdrs_extra" TBL_COST_DETAILS = "cost_details" TBL_RATED_CDRS = "rated_cdrs" TIMINGS_CSV = "Timings.csv" DESTINATIONS_CSV = "Destinations.csv" RATES_CSV = "Rates.csv" DESTINATION_RATES_CSV = "DestinationRates.csv" RATING_PLANS_CSV = "RatingPlans.csv" RATING_PROFILES_CSV = "RatingProfiles.csv" ACTIONS_CSV = "Actions.csv" ACTION_TIMINGS_CSV = "ActionTimings.csv" ACTION_TRIGGERS_CSV = "ActionTriggers.csv" ACCOUNT_ACTIONS_CSV = "AccountActions.csv" TIMINGS_NRCOLS = 6 DESTINATIONS_NRCOLS = 2 RATES_NRCOLS = 8 DESTINATION_RATES_NRCOLS = 3 DESTRATE_TIMINGS_NRCOLS = 4 RATE_PROFILES_NRCOLS = 7 ACTIONS_NRCOLS = 11 ACTION_TIMINGS_NRCOLS = 4 ACTION_TRIGGERS_NRCOLS = 8 ACCOUNT_ACTIONS_NRCOLS = 5 ROUNDING_UP = "*up" ROUNDING_MIDDLE = "*middle" ROUNDING_DOWN = "*down" ANY = "*any" COMMENT_CHAR = '#' CSV_SEP = ',' FALLBACK_SEP = ';' JSON = "json" MSGPACK = "msgpack" CSV_LOAD = "CSVLOAD" ACCID = "accid" CDRHOST = "cdrhost" CDRSOURCE = "cdrsource" REQTYPE = "reqtype" DIRECTION = "direction" TENANT = "tenant" TOR = "tor" ACCOUNT = "account" SUBJECT = "subject" DESTINATION = "destination" ANSWER_TIME = "answer_time" DURATION = "duration" DEFAULT_RUNID = "default" STATIC_VALUE_PREFIX = "^" CDRE_CSV = "csv" CDRE_DRYRUN = "dry_run" )
Variables ¶
var (
CdreCdrFormats = []string{CDRE_CSV, CDRE_DRYRUN}
)
var PrimaryCdrFields []string = []string{ACCID, CDRHOST, CDRSOURCE, REQTYPE, DIRECTION, TENANT, TOR, ACCOUNT, SUBJECT, DESTINATION, ANSWER_TIME, DURATION}
Functions ¶
func BalanceKey ¶
func ConvertMapValStrIf ¶
Converts map[string]string into map[string]interface{}
func FallbackSubjKeys ¶
Helper to return the subject fallback keys we need in dataDb
func FirstNonEmpty ¶
Returns first non empty string out of vals. Useful to extract defaults
func MissingMapKeys ¶
Returns mising keys in a map
func MissingStructFields ¶
Detects missing field values based on mandatory field names, s should be a pointer to a struct
func NonemptyStructFields ¶
func NonemptyStructFields(s interface{}) map[string]interface{}
Detects nonempty struct fields, s should be a pointer to a struct Useful to not overwrite db fields with non defined params in api
func ParseDurationWithSecs ¶
Parses duration, considers s as time unit if not provided
func Round ¶
Round return rounded version of x with prec precision.
Special cases are:
Round(±0) = ±0 Round(±Inf) = ±Inf Round(NaN) = NaN
func SliceMemberHasPrefix ¶
Iterates over slice members and returns true of one starts with prefix
func SplitPrefix ¶
func UpdateStructWithStrMap ¶
Update struct with map fields, returns not matching map keys, s is a struct to be updated
Types ¶
type ApiReloadCache ¶
type ApiReloadCache struct { DestinationIds []string RatingPlanIds []string RatingProfileIds []string ActionIds []string }
Data used to do remote cache reloads via api
type ApierTPTiming ¶
type ApierTPTiming struct { TPid string // Tariff plan id TimingId string // Timing id Years string // semicolon separated list of years this timing is valid on, *any supported Months string // semicolon separated list of months this timing is valid on, *any supported MonthDays string // semicolon separated list of month's days this timing is valid on, *any supported WeekDays string // semicolon separated list of week day names this timing is valid on *any supported Time string // String representing the time this timing starts on }
type AttrCacheStats ¶
type AttrCacheStats struct { }
type AttrCachedItemAge ¶
type AttrExpFileCdrs ¶
type AttrExpFileCdrs struct { CdrFormat string // Cdr output file format <utils.CdreCdrFormats> TimeStart string // If provided, will represent the starting of the CDRs interval (>=) TimeEnd string // If provided, will represent the end of the CDRs interval (<) RemoveFromDb bool // If true the CDRs will be also deleted after export }
type AttrTPRatingProfileIds ¶
type CacheStats ¶
type CachedItemAge ¶
type CgrCdr ¶
func (CgrCdr) AsRatedCdr ¶
func (cgrCdr CgrCdr) AsRatedCdr(runId, reqTypeFld, directionFld, tenantFld, torFld, accountFld, subjectFld, destFld, answerTimeFld, durationFld string, extraFlds []string, fieldsMandatory bool) (*RatedCDR, error)
Used in mediation, fieldsMandatory marks whether missing field out of request represents error or can be ignored If the fields in parameters start with ^ their value is considered instead of dynamically retrieving it from CDR
func (CgrCdr) GetAccount ¶
func (CgrCdr) GetCdrHost ¶
func (CgrCdr) GetCdrSource ¶
func (CgrCdr) GetDestination ¶
Charging destination number
func (CgrCdr) GetDirection ¶
func (CgrCdr) GetDuration ¶
Extracts duration as considered by the telecom switch
func (CgrCdr) GetExtraFields ¶
func (CgrCdr) GetReqType ¶
func (CgrCdr) GetSubject ¶
type DestinationRate ¶
type ExportedFileCdrs ¶
type LoggerInterface ¶
type MonthDays ¶
type MonthDays []int
Defines month days series
type Months ¶
Defines months series
type RateSlot ¶
type RateSlot struct { ConnectFee float64 // ConnectFee applied once the call is answered Rate float64 // Rate applied RateUnit string // Number of billing units this rate applies to RateIncrement string // This rate will apply in increments of duration GroupIntervalStart string // Group position RoundingMethod string // Use this method to round the cost RoundingDecimals int // Round the cost number of decimals // contains filtered or unexported fields }
func NewRateSlot ¶
func NewRateSlot(connectFee, rate float64, rateUnit, rateIncrement, grpInterval, rndMethod string, rndDecimals int) (*RateSlot, error)
Needed so we make sure we always use SetDurations() on a newly created value
func (*RateSlot) GroupIntervalStartDuration ¶
func (*RateSlot) RateIncrementDuration ¶
func (*RateSlot) RateUnitDuration ¶
func (*RateSlot) SetDurations ¶
Used to set the durations we need out of strings
type RatedCDR ¶
type RatedCDR struct { CgrId string AccId string CdrHost string CdrSource string ReqType string Direction string Tenant string TOR string Account string Subject string Destination string AnswerTime time.Time Duration time.Duration ExtraFields map[string]string MediationRunId string Cost float64 }
Rated CDR as extracted from StorDb. Kinda standard of internal CDR, complies to CDR interface also
func NewRatedCDRFromRawCDR ¶
func (*RatedCDR) AsRatedCdr ¶
func (*RatedCDR) GetAccount ¶
func (*RatedCDR) GetCdrHost ¶
func (*RatedCDR) GetCdrSource ¶
func (*RatedCDR) GetDestination ¶
func (*RatedCDR) GetDirection ¶
func (*RatedCDR) GetDuration ¶
func (*RatedCDR) GetExtraFields ¶
func (*RatedCDR) GetReqType ¶
func (*RatedCDR) GetSubject ¶
type RawCDR ¶
type RawCDR interface { GetCgrId() string GetAccId() string GetCdrHost() string GetCdrSource() string GetDirection() string GetSubject() string GetAccount() string GetDestination() string GetTOR() string GetTenant() string GetReqType() string GetAnswerTime() (time.Time, error) GetDuration() time.Duration GetExtraFields() map[string]string //Stores extra CDR Fields AsRatedCdr(string, string, string, string, string, string, string, string, string, string, []string, bool) (*RatedCDR, error) // Based on fields queried will return a particular instance of RatedCDR }
RawCDR is the type containing all the original CDR fields, needs it as it is for later usage
type TPAccountActions ¶
type TPAccountActions struct { TPid string // Tariff plan id LoadId string // LoadId, used to group actions on a load Tenant string // Tenant's Id Account string // Account name Direction string // Traffic direction ActionTimingsId string // Id of ActionTimings profile to use ActionTriggersId string // Id of ActionTriggers profile to use }
func NewTPAccountActionsFromKeyId ¶
func NewTPAccountActionsFromKeyId(tpid, loadId, keyId string) (*TPAccountActions, error)
Used to rebuild a TPAccountActions (empty ActionTimingsId and ActionTriggersId) out of it's key in nosqldb
func (*TPAccountActions) KeyId ¶
func (self *TPAccountActions) KeyId() string
Returns the id used in some nosql dbs (eg: redis)
type TPAction ¶
type TPAction struct { Identifier string // Identifier mapped in the code BalanceType string // Type of balance the action will operate on Direction string // Balance direction Units float64 // Number of units to add/deduct ExpiryTime string // Time when the units will expire DestinationId string // Destination profile id RatingSubject string // Reference a rate subject defined in RatingProfiles BalanceWeight float64 // Balance weight ExtraParameters string Weight float64 // Action's weight }
type TPActionTiming ¶
type TPActionTimings ¶
type TPActionTimings struct { TPid string // Tariff plan id ActionTimingsId string // ActionTimings id ActionTimings []*TPActionTiming // Set of ActionTiming bindings this profile will group }
type TPActionTrigger ¶
type TPActionTrigger struct { BalanceType string // Type of balance this trigger monitors Direction string // Traffic direction ThresholdType string // This threshold type ThresholdValue float64 // Threshold DestinationId string // Id of the destination profile ActionsId string // Actions which will execute on threshold reached Weight float64 // weight }
type TPActionTriggers ¶
type TPActionTriggers struct { TPid string // Tariff plan id ActionTriggersId string // Profile id ActionTriggers []*TPActionTrigger // Set of triggers grouped in this profile }
type TPDestination ¶
type TPDestinationRate ¶
type TPDestinationRate struct { TPid string // Tariff plan id DestinationRateId string // DestinationRate profile id DestinationRates []*DestinationRate // Set of destinationid-rateid bindings }
type TPRatingActivation ¶
type TPRatingPlan ¶
type TPRatingPlan struct { TPid string // Tariff plan id RatingPlanId string // RatingPlan profile id RatingPlanBindings []*TPRatingPlanBinding // Set of destinationid-rateid bindings }
type TPRatingPlanBinding ¶
type TPRatingPlanBinding struct { DestinationRatesId string // The DestinationRate identity TimingId string // The timing identity Weight float64 // Binding priority taken into consideration when more DestinationRates are active on a time slot // contains filtered or unexported fields }
func (*TPRatingPlanBinding) SetTiming ¶
func (self *TPRatingPlanBinding) SetTiming(tm *TPTiming)
func (*TPRatingPlanBinding) Timing ¶
func (self *TPRatingPlanBinding) Timing() *TPTiming
type TPRatingProfile ¶
type TPRatingProfile struct { TPid string // Tariff plan id LoadId string // Gives ability to load specific RatingProfile based on load identifier, hence being able to keep history also in stordb Tenant string // Tenant's Id TOR string // TypeOfRecord Direction string // Traffic direction, OUT is the only one supported for now Subject string // Rating subject, usually the same as account RatingPlanActivations []*TPRatingActivation // Activate rate profiles at specific time }
func NewTPRatingProfileFromKeyId ¶
func NewTPRatingProfileFromKeyId(tpid, loadId, keyId string) (*TPRatingProfile, error)
Used to rebuild a TPRatingProfile (empty RatingPlanActivations) out of it's key in nosqldb
func (*TPRatingProfile) KeyId ¶
func (self *TPRatingProfile) KeyId() string
Used as key in nosql db (eg: redis)
type WeekDays ¶
Defines week days series