added cdrstats_queue and cdrstats_queue_triggers

console commands fixes #107
This commit is contained in:
Radu Ioan Fericean
2015-07-03 17:26:25 +03:00
parent dbdc95422f
commit 5adc94a45f
7 changed files with 179 additions and 1 deletions

View File

@@ -45,6 +45,14 @@ func (sts *CDRStatsV1) GetQueueIds(empty string, reply *[]string) error {
return sts.CdrStats.GetQueueIds(0, reply)
}
func (sts *CDRStatsV1) GetQueue(id string, sq *engine.StatsQueue) error {
return sts.CdrStats.GetQueue(id, sq)
}
func (sts *CDRStatsV1) GetQueueTriggers(id string, ats *engine.ActionTriggerPriotityList) error {
return sts.CdrStats.GetQueueTriggers(id, ats)
}
func (sts *CDRStatsV1) ReloadQueues(attr utils.AttrCDRStatsReloadQueues, reply *string) error {
if err := sts.CdrStats.ReloadQueues(attr.StatsQueueIds, nil); err != nil {
return err

63
console/cdrstats_queue.go Normal file
View File

@@ -0,0 +1,63 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 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 "github.com/cgrates/cgrates/engine"
func init() {
c := &CmdCdrStatsQueue{
name: "cdrstats_queue",
rpcMethod: "CDRStatsV1.GetQueue",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
type CmdCdrStatsQueue struct {
name string
rpcMethod string
rpcParams *StringWrapper
*CommandExecuter
}
func (self *CmdCdrStatsQueue) Name() string {
return self.name
}
func (self *CmdCdrStatsQueue) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdCdrStatsQueue) RpcParams(ptr bool) interface{} {
if self.rpcParams == nil {
self.rpcParams = &StringWrapper{}
}
if ptr {
return self.rpcParams
}
return *self.rpcParams
}
func (self *CmdCdrStatsQueue) PostprocessRpcParams() error {
return nil
}
func (self *CmdCdrStatsQueue) RpcResult() interface{} {
return &engine.StatsQueue{}
}

View File

@@ -0,0 +1,63 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 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 "github.com/cgrates/cgrates/engine"
func init() {
c := &CmdCdrStatsQueueTriggers{
name: "cdrstats_queue_triggers",
rpcMethod: "CDRStatsV1.GetQueueTriggers",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
type CmdCdrStatsQueueTriggers struct {
name string
rpcMethod string
rpcParams *StringWrapper
*CommandExecuter
}
func (self *CmdCdrStatsQueueTriggers) Name() string {
return self.name
}
func (self *CmdCdrStatsQueueTriggers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdCdrStatsQueueTriggers) RpcParams(ptr bool) interface{} {
if self.rpcParams == nil {
self.rpcParams = &StringWrapper{}
}
if ptr {
return self.rpcParams
}
return *self.rpcParams
}
func (self *CmdCdrStatsQueueTriggers) PostprocessRpcParams() error {
return nil
}
func (self *CmdCdrStatsQueueTriggers) RpcResult() interface{} {
return &engine.ActionTriggerPriotityList{}
}

View File

@@ -4,6 +4,12 @@
// Used in apier_local_tests
// Starts rater, cdrs and mediator connecting over internal channel
"listen": {
"rpc_json": ":2012", // RPC JSON listening address
"rpc_gob": ":2013", // RPC GOB listening address
"http": ":2080", // HTTP listening address
},
"rater": {
"enabled": true, // enable Rater service: <true|false>
},

View File

@@ -118,7 +118,6 @@ func (rit *RITiming) CronString() string {
// Returns wheter the Timing is active at the specified time
func (rit *RITiming) IsActiveAt(t time.Time, endTime bool) bool {
t = t.In(time.UTC) // compare with UTC
// if the received time represents an endtime consider it 24 instead of 0
hour := t.Hour()
if endTime && hour == 0 {

View File

@@ -30,6 +30,8 @@ import (
type StatsInterface interface {
GetValues(string, *map[string]float64) error
GetQueueIds(int, *[]string) error
GetQueue(string, *StatsQueue) error
GetQueueTriggers(string, *ActionTriggerPriotityList) error
AppendCDR(*StoredCdr, *int) error
AddQueue(*CdrStats, *int) error
ReloadQueues([]string, *int) error
@@ -101,6 +103,32 @@ func (s *Stats) GetQueueIds(in int, ids *[]string) error {
return nil
}
func (s *Stats) GetQueue(id string, sq *StatsQueue) error {
s.mux.Lock()
defer s.mux.Unlock()
q, found := s.queues[id]
if !found {
return utils.ErrNotFound
}
*sq = *q
return nil
}
func (s *Stats) GetQueueTriggers(id string, ats *ActionTriggerPriotityList) error {
s.mux.Lock()
defer s.mux.Unlock()
q, found := s.queues[id]
if !found {
return utils.ErrNotFound
}
if q.conf.Triggers != nil {
*ats = q.conf.Triggers
} else {
*ats = ActionTriggerPriotityList{}
}
return nil
}
func (s *Stats) GetValues(sqID string, values *map[string]float64) error {
s.mux.RLock()
defer s.mux.RUnlock()
@@ -282,6 +310,14 @@ func (ps *ProxyStats) GetQueueIds(in int, ids *[]string) error {
return ps.Client.Call("Stats.GetQueueIds", in, ids)
}
func (ps *ProxyStats) GetQueue(id string, sq *StatsQueue) error {
return ps.Client.Call("Stats.GetQueue", id, sq)
}
func (ps *ProxyStats) GetQueueTriggers(id string, ats *ActionTriggerPriotityList) error {
return ps.Client.Call("Stats.GetQueueTriggers", id, ats)
}
func (ps *ProxyStats) AddQueue(cs *CdrStats, out *int) error {
return ps.Client.Call("Stats.AddQueue", cs, out)
}

View File

@@ -135,6 +135,9 @@ func TestGetDataBetweenCostDtChrg1(t *testing.T) {
t.Error(err)
} else if cc.Cost != 0.004 {
//t.Logf("%+v", cc.Timespans[1].RateInterval.Timing)
for _, ts := range cc.Timespans {
t.Logf("TS: %+v", ts)
}
t.Error("Wrong cost returned: ", cc.Cost)
}
}