mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding GetCallCostLog API and console command
This commit is contained in:
@@ -40,6 +40,7 @@ type ApierV1 struct {
|
||||
RatingDb engine.RatingStorage
|
||||
AccountDb engine.AccountingStorage
|
||||
CdrDb engine.CdrStorage
|
||||
LogDb engine.LogStorage
|
||||
Sched *scheduler.Scheduler
|
||||
Config *config.CGRConfig
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ func main() {
|
||||
}
|
||||
|
||||
responder := &engine.Responder{ExitChan: exitChan}
|
||||
apier := &apier.ApierV1{StorDb: loadDb, RatingDb: ratingDb, AccountDb: accountDb, CdrDb: cdrDb, Config: cfg}
|
||||
apier := &apier.ApierV1{StorDb: loadDb, RatingDb: ratingDb, AccountDb: accountDb, CdrDb: cdrDb, LogDb: logDb, Config: cfg}
|
||||
|
||||
if cfg.RaterEnabled && !cfg.BalancerEnabled && cfg.RaterBalancer != utils.INTERNAL {
|
||||
engine.Logger.Info("Registering Rater service")
|
||||
|
||||
76
console/get_callcost.go
Normal file
76
console/get_callcost.go
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cgrates/cgrates/apier"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
commands["get_callcost"] = &CmdGetCallCost{}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdGetCallCost struct {
|
||||
rpcMethod string
|
||||
rpcParams *apier.AttrGetCallCost
|
||||
rpcResult *engine.CallCost
|
||||
}
|
||||
|
||||
// name should be exec's name
|
||||
func (self *CmdGetCallCost) Usage(name string) string {
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_callcost <cgrid> [<runid>]")
|
||||
}
|
||||
|
||||
// set param defaults
|
||||
func (self *CmdGetCallCost) defaults() error {
|
||||
self.rpcMethod = "ApierV1.GetCallCostLog"
|
||||
self.rpcParams = &apier.AttrGetCallCost{RunId: utils.DEFAULT_RUNID}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parses command line args and builds CmdBalance value
|
||||
func (self *CmdGetCallCost) FromArgs(args []string) error {
|
||||
if len(args) < 3 {
|
||||
return fmt.Errorf(self.Usage(""))
|
||||
}
|
||||
// Args look OK, set defaults before going further
|
||||
self.defaults()
|
||||
self.rpcParams.CgrId = args[2]
|
||||
if len(args) == 4 {
|
||||
self.rpcParams.RunId = args[3]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdGetCallCost) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdGetCallCost) RpcParams() interface{} {
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdGetCallCost) RpcResult() interface{} {
|
||||
return &self.rpcResult
|
||||
}
|
||||
@@ -492,12 +492,20 @@ func (self *SQLStorage) LogCallCost(uuid, source, runid string, cc *CallCost) (e
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetCallCostLog(cgrid, source, runid string) (cc *CallCost, err error) {
|
||||
row := self.Db.QueryRow(fmt.Sprintf("SELECT cgrid, accid, direction, tenant, tor, account, subject, destination, cost, timespans, source FROM %s WHERE cgrid='%s' AND source='%s' AND runid='%s'", utils.TBL_COST_DETAILS, cgrid, source, runid))
|
||||
qry := fmt.Sprintf("SELECT cgrid, accid, direction, tenant, tor, account, subject, destination, cost, timespans, source FROM %s WHERE cgrid='%s' AND runid='%s'",
|
||||
utils.TBL_COST_DETAILS, cgrid, runid)
|
||||
if len(source) != 0 {
|
||||
qry += fmt.Sprintf(" AND source='%s'", source)
|
||||
}
|
||||
row := self.Db.QueryRow(qry)
|
||||
var accid, src string
|
||||
var timespansJson string
|
||||
cc = &CallCost{Cost: -1}
|
||||
err = row.Scan(&cgrid, &accid, &cc.Direction, &cc.Tenant, &cc.TOR, &cc.Account, &cc.Subject,
|
||||
&cc.Destination, &cc.Cost, ×pansJson, &src)
|
||||
if len(timespansJson) == 0 { // No costs returned
|
||||
return nil, nil
|
||||
}
|
||||
if err = json.Unmarshal([]byte(timespansJson), &cc.Timespans); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user