mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 17:18:44 +05:00
Merge pull request #1415 from TeoV/master
Add chargers commands in cgr-console
This commit is contained in:
@@ -48,6 +48,8 @@ var (
|
||||
testAccITRPCConn,
|
||||
testAccITAddVoiceBalance,
|
||||
testAccITDebitBalance,
|
||||
testAccITAddBalance,
|
||||
testAccITSetBalance,
|
||||
testAccITStopCgrEngine,
|
||||
}
|
||||
)
|
||||
@@ -149,7 +151,6 @@ func testAccITAddVoiceBalance(t *testing.T) {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
t.Run("TestAddVoiceBalance", func(t *testing.T) { testAccountBalance(t, accAcount, accTenant, utils.VOICE, 2*float64(time.Second)) })
|
||||
|
||||
}
|
||||
|
||||
func testAccITDebitBalance(t *testing.T) {
|
||||
@@ -173,6 +174,48 @@ func testAccITDebitBalance(t *testing.T) {
|
||||
t.Fatalf("Balance with ID %s should %sexist", accBallID, exstr)
|
||||
}
|
||||
t.Run("TestAddVoiceBalance", func(t *testing.T) { testAccountBalance(t, accAcount, accTenant, utils.VOICE, 0) })
|
||||
|
||||
}
|
||||
|
||||
func testAccITAddBalance(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &AttrAddBalance{Tenant: "cgrates.org", Account: "testAccAddBalance",
|
||||
BalanceType: "*monetary", Value: 1.5, Cdrlog: utils.BoolPointer(true)}
|
||||
if err := accRPC.Call("ApierV1.AddBalance", attrs, &reply); err != nil {
|
||||
t.Error("Got error on ApierV1.AddBalance: ", err.Error())
|
||||
} else if reply != "OK" {
|
||||
t.Errorf("Calling ApierV1.AddBalance received: %s", reply)
|
||||
}
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
// verify the cdr from CdrLog
|
||||
var cdrs []*engine.ExternalCDR
|
||||
req := utils.RPCCDRsFilter{Sources: []string{engine.CDRLOG}}
|
||||
if err := accRPC.Call("ApierV2.GetCdrs", req, &cdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(cdrs) != 1 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(cdrs))
|
||||
}
|
||||
}
|
||||
|
||||
func testAccITSetBalance(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &AttrAddBalance{Tenant: "cgrates.org", Account: "testAccSetBalance",
|
||||
BalanceId: utils.StringPointer("testAccSetBalance"),
|
||||
BalanceType: "*monetary", Value: 1.5, Cdrlog: utils.BoolPointer(true)}
|
||||
if err := accRPC.Call("ApierV1.SetBalance", attrs, &reply); err != nil {
|
||||
t.Error("Got error on ApierV1.SetBalance: ", err.Error())
|
||||
} else if reply != "OK" {
|
||||
t.Errorf("Calling ApierV1.SetBalance received: %s", reply)
|
||||
}
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
// verify the cdr from CdrLog
|
||||
var cdrs []*engine.ExternalCDR
|
||||
req := utils.RPCCDRsFilter{Sources: []string{engine.CDRLOG}}
|
||||
if err := accRPC.Call("ApierV2.GetCdrs", req, &cdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(cdrs) != 2 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(cdrs))
|
||||
}
|
||||
}
|
||||
|
||||
func testAccITStopCgrEngine(t *testing.T) {
|
||||
|
||||
@@ -263,7 +263,7 @@ func (dC *DispatcherChargerSv1) GetChargersForEvent(args *dispatchers.CGREvWithA
|
||||
|
||||
// ProcessEvent implements ChargerSv1ProcessEvent
|
||||
func (dC *DispatcherChargerSv1) ProcessEvent(args *dispatchers.CGREvWithApiKey,
|
||||
reply *[]*engine.AttrSProcessEventReply) (err error) {
|
||||
reply *[]*engine.ChrgSProcessEventReply) (err error) {
|
||||
return dC.dC.ChargerSv1ProcessEvent(args, reply)
|
||||
}
|
||||
|
||||
|
||||
66
console/chargers.go
Normal file
66
console/chargers.go
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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 console
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := &CmdGetChargers{
|
||||
name: "chargers",
|
||||
rpcMethod: "ApierV1.GetChargerProfile",
|
||||
rpcParams: &utils.TenantID{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdGetChargers struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *utils.TenantID
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdGetChargers) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdGetChargers) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdGetChargers) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &utils.TenantID{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdGetChargers) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdGetChargers) RpcResult() interface{} {
|
||||
atr := engine.ChargerProfile{}
|
||||
return &atr
|
||||
}
|
||||
66
console/chargers_for_event.go
Normal file
66
console/chargers_for_event.go
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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 console
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/dispatchers"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := &CmdGetChargersForEvent{
|
||||
name: "chargers_for_event",
|
||||
rpcMethod: utils.ChargerSv1GetChargersForEvent,
|
||||
rpcParams: &dispatchers.CGREvWithApiKey{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
type CmdGetChargersForEvent struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *dispatchers.CGREvWithApiKey
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdGetChargersForEvent) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdGetChargersForEvent) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdGetChargersForEvent) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &dispatchers.CGREvWithApiKey{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdGetChargersForEvent) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdGetChargersForEvent) RpcResult() interface{} {
|
||||
atr := engine.ChargerProfiles{}
|
||||
return &atr
|
||||
}
|
||||
71
console/chargers_process_event.go
Normal file
71
console/chargers_process_event.go
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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 console
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/dispatchers"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := &CmdChargersProcessEvent{
|
||||
name: "chargers_process_event",
|
||||
rpcMethod: utils.ChargerSv1ProcessEvent,
|
||||
rpcParams: &dispatchers.CGREvWithApiKey{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
type CmdChargersProcessEvent struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *dispatchers.CGREvWithApiKey
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdChargersProcessEvent) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdChargersProcessEvent) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdChargersProcessEvent) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &dispatchers.CGREvWithApiKey{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdChargersProcessEvent) PostprocessRpcParams() error {
|
||||
if self.rpcParams.Time == nil {
|
||||
self.rpcParams.Time = utils.TimePointer(time.Now())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdChargersProcessEvent) RpcResult() interface{} {
|
||||
atr := []*engine.ChrgSProcessEventReply{}
|
||||
return &atr
|
||||
}
|
||||
62
console/chargers_remove.go
Normal file
62
console/chargers_remove.go
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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 console
|
||||
|
||||
import "github.com/cgrates/cgrates/utils"
|
||||
|
||||
func init() {
|
||||
c := &CmdRemoveChargers{
|
||||
name: "chargers_remove",
|
||||
rpcMethod: "ApierV1.RemoveChargerProfile",
|
||||
rpcParams: &utils.TenantID{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
type CmdRemoveChargers struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *utils.TenantID
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdRemoveChargers) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdRemoveChargers) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdRemoveChargers) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &utils.TenantID{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdRemoveChargers) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdRemoveChargers) RpcResult() interface{} {
|
||||
var s string
|
||||
return &s
|
||||
}
|
||||
62
console/chargers_set.go
Normal file
62
console/chargers_set.go
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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 console
|
||||
|
||||
import "github.com/cgrates/cgrates/engine"
|
||||
|
||||
func init() {
|
||||
c := &CmdSetChargers{
|
||||
name: "chargers_set",
|
||||
rpcMethod: "ApierV1.SetChargerProfile",
|
||||
rpcParams: &engine.ChargerProfile{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
type CmdSetChargers struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *engine.ChargerProfile
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdSetChargers) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdSetChargers) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdSetChargers) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &engine.ChargerProfile{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdSetChargers) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdSetChargers) RpcResult() interface{} {
|
||||
var s string
|
||||
return &s
|
||||
}
|
||||
@@ -71,6 +71,9 @@
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true,
|
||||
"cdrs_conns": [
|
||||
{"address": "127.0.0.1:2012", "transport":"*json"},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -68,6 +68,9 @@
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true,
|
||||
"cdrs_conns": [
|
||||
{"address": "127.0.0.1:2012", "transport":"*json"},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -64,6 +64,9 @@
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true,
|
||||
"cdrs_conns": [
|
||||
{"address": "127.0.0.1:2012", "transport":"*json"},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -49,14 +49,13 @@ func (dS *DispatcherService) ChargerSv1GetChargersForEvent(args *CGREvWithApiKey
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) ChargerSv1ProcessEvent(args *CGREvWithApiKey,
|
||||
reply *[]*engine.AttrSProcessEventReply) (err error) {
|
||||
reply *[]*engine.ChrgSProcessEventReply) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.ChargerSv1ProcessEvent,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaChargers, args.RouteID,
|
||||
utils.ChargerSv1ProcessEvent, args.CGREvent, reply)
|
||||
|
||||
@@ -171,7 +171,7 @@ func cdrLogAction(acc *Account, a *Action, acs Actions, extraData interface{}) (
|
||||
// set stored cdr values
|
||||
var cdrs []*CDR
|
||||
for _, action := range acs {
|
||||
if !utils.IsSliceMember([]string{DEBIT, DEBIT_RESET, TOPUP, TOPUP_RESET}, action.ActionType) ||
|
||||
if !utils.IsSliceMember([]string{DEBIT, DEBIT_RESET, TOPUP, TOPUP_RESET, SET_BALANCE}, action.ActionType) ||
|
||||
action.Balance == nil {
|
||||
continue // Only log specific actions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user