コード例 #1
0
ファイル: scheduler.go プロジェクト: kevinlovesing/cgrates
func (self *ApierV1) GetScheduledActions(attrs AttrsGetScheduledActions, reply *[]*ScheduledActions) error {
	schedActions := make([]*ScheduledActions, 0)
	if self.Sched == nil {
		return errors.New("SCHEDULER_NOT_ENABLED")
	}
	scheduledActions := self.Sched.GetQueue()
	var min, max int
	if attrs.Paginator.Offset != nil {
		min = *attrs.Paginator.Offset
	}
	if attrs.Paginator.Limit != nil {
		max = *attrs.Paginator.Limit
	}
	if max > len(scheduledActions) {
		max = len(scheduledActions)
	}
	scheduledActions = scheduledActions[min : min+max]
	for _, qActions := range scheduledActions {
		sas := &ScheduledActions{ActionsId: qActions.ActionsId, ActionPlanId: qActions.Id, ActionPlanUuid: qActions.Uuid}
		if attrs.SearchTerm != "" &&
			!(strings.Contains(sas.ActionPlanId, attrs.SearchTerm) ||
				strings.Contains(sas.ActionsId, attrs.SearchTerm)) {
			continue
		}
		sas.NextRunTime = qActions.GetNextStartTime(time.Now())
		if !attrs.TimeStart.IsZero() && sas.NextRunTime.Before(attrs.TimeStart) {
			continue // Filter here only requests in the filtered interval
		}
		if !attrs.TimeEnd.IsZero() && (sas.NextRunTime.After(attrs.TimeEnd) || sas.NextRunTime.Equal(attrs.TimeEnd)) {
			continue
		}
		acntFiltersMatch := false
		for _, acntKey := range qActions.AccountIds {
			tenantMatched := len(attrs.Tenant) == 0
			accountMatched := len(attrs.Account) == 0
			dta, _ := utils.NewTAFromAccountKey(acntKey)
			sas.Accounts = append(sas.Accounts, dta)
			// One member matching
			if !tenantMatched && attrs.Tenant == dta.Tenant {
				tenantMatched = true
			}
			if !accountMatched && attrs.Account == dta.Account {
				accountMatched = true
			}
			if tenantMatched && accountMatched {
				acntFiltersMatch = true
			}
		}
		if !acntFiltersMatch {
			continue
		}
		schedActions = append(schedActions, sas)
	}
	*reply = schedActions
	return nil
}
コード例 #2
0
ファイル: action.go プロジェクト: cgrates/cgrates
// Used by cdrLogAction to dynamically parse values out of account and action
func parseTemplateValue(rsrFlds utils.RSRFields, acnt *Account, action *Action) string {
	var err error
	var dta *utils.TenantAccount
	if acnt != nil {
		dta, err = utils.NewTAFromAccountKey(acnt.ID) // Account information should be valid
	}
	if err != nil || acnt == nil {
		dta = new(utils.TenantAccount) // Init with empty values
	}
	var parsedValue string // Template values
	b := action.Balance.CreateBalance()
	for _, rsrFld := range rsrFlds {
		switch rsrFld.Id {
		case "AccountID":
			parsedValue += rsrFld.ParseValue(acnt.ID)
		case "Directions":
			parsedValue += rsrFld.ParseValue(b.Directions.String())
		case utils.TENANT:
			parsedValue += rsrFld.ParseValue(dta.Tenant)
		case utils.ACCOUNT:
			parsedValue += rsrFld.ParseValue(dta.Account)
		case "ActionID":
			parsedValue += rsrFld.ParseValue(action.Id)
		case "ActionType":
			parsedValue += rsrFld.ParseValue(action.ActionType)
		case "ActionValue":
			parsedValue += rsrFld.ParseValue(strconv.FormatFloat(b.GetValue(), 'f', -1, 64))
		case "BalanceType":
			parsedValue += rsrFld.ParseValue(action.Balance.GetType())
		case "BalanceUUID":
			parsedValue += rsrFld.ParseValue(b.Uuid)
		case "BalanceID":
			parsedValue += rsrFld.ParseValue(b.ID)
		case "BalanceValue":
			parsedValue += rsrFld.ParseValue(strconv.FormatFloat(action.balanceValue, 'f', -1, 64))
		case "DestinationIDs":
			parsedValue += rsrFld.ParseValue(b.DestinationIDs.String())
		case "ExtraParameters":
			parsedValue += rsrFld.ParseValue(action.ExtraParameters)
		case "RatingSubject":
			parsedValue += rsrFld.ParseValue(b.RatingSubject)
		case utils.CATEGORY:
			parsedValue += rsrFld.ParseValue(action.Balance.Categories.String())
		case "SharedGroups":
			parsedValue += rsrFld.ParseValue(action.Balance.SharedGroups.String())
		default:
			parsedValue += rsrFld.ParseValue("") // Mostly for static values
		}
	}
	return parsedValue
}
コード例 #3
0
ファイル: action.go プロジェクト: kevinlovesing/cgrates
// Used by cdrLogAction to dynamically parse values out of account and action
func parseTemplateValue(rsrFlds utils.RSRFields, acnt *Account, action *Action) string {
	dta, err := utils.NewTAFromAccountKey(acnt.Id) // Account information should be valid
	if err != nil {
		dta = new(utils.TenantAccount) // Init with empty values
	}
	var parsedValue string // Template values
	for _, rsrFld := range rsrFlds {
		switch rsrFld.Id {
		case "account_id":
			parsedValue += rsrFld.ParseValue(acnt.Id)
		case "direction":
			parsedValue += rsrFld.ParseValue(action.Balance.Directions.String())
		case "tenant":
			parsedValue += rsrFld.ParseValue(dta.Tenant)
		case "account":
			parsedValue += rsrFld.ParseValue(dta.Account)
		case "action_id":
			parsedValue += rsrFld.ParseValue(action.Id)
		case "action_type":
			parsedValue += rsrFld.ParseValue(action.ActionType)
		case "balance_type":
			parsedValue += rsrFld.ParseValue(action.BalanceType)
		case "balance_uuid":
			parsedValue += rsrFld.ParseValue(action.Balance.Uuid)
		case "balance_id":
			parsedValue += rsrFld.ParseValue(action.Balance.Id)
		case "balance_value":
			parsedValue += rsrFld.ParseValue(strconv.FormatFloat(action.Balance.GetValue(), 'f', -1, 64))
		case "destination_id":
			parsedValue += rsrFld.ParseValue(action.Balance.DestinationIds.String())
		case "extra_params":
			parsedValue += rsrFld.ParseValue(action.ExtraParameters)
		case "rating_subject":
			parsedValue += rsrFld.ParseValue(action.Balance.RatingSubject)
		case "category":
			parsedValue += rsrFld.ParseValue(action.Balance.Categories.String())
		case "shared_group":
			parsedValue += rsrFld.ParseValue(action.Balance.SharedGroups.String())
		default:
			parsedValue += rsrFld.ParseValue("") // Mostly for static values
		}
	}
	return parsedValue
}