mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
SMGenericV1.ActiveSessions implementation
This commit is contained in:
@@ -89,6 +89,45 @@ func (self *SMGenericV1) ProcessCdr(ev sessionmanager.SMGenericEvent, reply *str
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SMGenericV1) ActiveSessions(attrs utils.AttrSMGGetActiveSessions, reply *[]*sessionmanager.ActiveSession) error {
|
||||
aSessions := make([]*sessionmanager.ActiveSession, 0)
|
||||
for _, sGrp := range self.sm.Sessions() { // Add sessions to return with filter
|
||||
for _, s := range sGrp {
|
||||
as := s.AsActiveSession(self.sm.Timezone())
|
||||
if attrs.ToR != nil && *attrs.ToR != as.TOR {
|
||||
continue
|
||||
}
|
||||
if attrs.RunID != nil && *attrs.RunID != as.RunId {
|
||||
continue
|
||||
}
|
||||
if attrs.RequestType != nil && *attrs.RequestType != as.ReqType {
|
||||
continue
|
||||
}
|
||||
if attrs.Tenant != nil && *attrs.Tenant != as.Tenant {
|
||||
continue
|
||||
}
|
||||
if attrs.Category != nil && *attrs.Category != as.Category {
|
||||
continue
|
||||
}
|
||||
if attrs.Account != nil && *attrs.Account != as.Account {
|
||||
continue
|
||||
}
|
||||
if attrs.Subject != nil && *attrs.Subject != as.Subject {
|
||||
continue
|
||||
}
|
||||
if attrs.Destination != nil && *attrs.Destination != as.Destination {
|
||||
continue
|
||||
}
|
||||
if attrs.Supplier != nil && *attrs.Supplier != as.Supplier {
|
||||
continue
|
||||
}
|
||||
aSessions = append(aSessions, as)
|
||||
}
|
||||
}
|
||||
*reply = aSessions
|
||||
return nil
|
||||
}
|
||||
|
||||
// rpcclient.RpcClientConnection interface
|
||||
func (self *SMGenericV1) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
switch serviceMethod {
|
||||
|
||||
@@ -256,3 +256,40 @@ func (self *SMGSession) saveOperations() error {
|
||||
func (self *SMGSession) TotalUsage() time.Duration {
|
||||
return self.totalUsage
|
||||
}
|
||||
|
||||
func (self *SMGSession) AsActiveSession(timezone string) *ActiveSession {
|
||||
sTime, _ := self.eventStart.GetSetupTime(utils.META_DEFAULT, timezone)
|
||||
aTime, _ := self.eventStart.GetAnswerTime(utils.META_DEFAULT, timezone)
|
||||
usage, _ := self.eventStart.GetUsage(utils.META_DEFAULT)
|
||||
pdd, _ := self.eventStart.GetPdd(utils.META_DEFAULT)
|
||||
aSession := &ActiveSession{
|
||||
CgrId: self.eventStart.GetCgrId(timezone),
|
||||
TOR: utils.VOICE,
|
||||
RunId: self.runId,
|
||||
AccId: self.eventStart.GetUUID(),
|
||||
CdrHost: self.eventStart.GetOriginatorIP(utils.META_DEFAULT),
|
||||
CdrSource: self.eventStart.GetCdrSource(),
|
||||
ReqType: self.eventStart.GetReqType(utils.META_DEFAULT),
|
||||
Direction: self.eventStart.GetDirection(utils.META_DEFAULT),
|
||||
Tenant: self.eventStart.GetTenant(utils.META_DEFAULT),
|
||||
Category: self.eventStart.GetCategory(utils.META_DEFAULT),
|
||||
Account: self.eventStart.GetAccount(utils.META_DEFAULT),
|
||||
Subject: self.eventStart.GetSubject(utils.META_DEFAULT),
|
||||
Destination: self.eventStart.GetDestination(utils.META_DEFAULT),
|
||||
SetupTime: sTime,
|
||||
AnswerTime: aTime,
|
||||
Usage: usage,
|
||||
Pdd: pdd,
|
||||
ExtraFields: self.eventStart.GetExtraFields(),
|
||||
Supplier: self.eventStart.GetSupplier(utils.META_DEFAULT),
|
||||
SMId: "CGR-DA",
|
||||
}
|
||||
if self.cd != nil {
|
||||
aSession.LoopIndex = self.cd.LoopIndex
|
||||
aSession.DurationIndex = self.cd.DurationIndex
|
||||
aSession.MaxRate = self.cd.MaxRate
|
||||
aSession.MaxRateUnit = self.cd.MaxRateUnit
|
||||
aSession.MaxCostSoFar = self.cd.MaxCostSoFar
|
||||
}
|
||||
return aSession
|
||||
}
|
||||
|
||||
@@ -344,6 +344,15 @@ func (self *SMGeneric) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Used by APIer to retrieve sessions
|
||||
func (self *SMGeneric) Sessions() map[string][]*SMGSession {
|
||||
return self.getSessions()
|
||||
}
|
||||
|
||||
func (self *SMGeneric) Timezone() string {
|
||||
return self.timezone
|
||||
}
|
||||
|
||||
// System shutdown
|
||||
func (self *SMGeneric) Shutdown() error {
|
||||
for ssId := range self.getSessions() { // Force sessions shutdown
|
||||
|
||||
@@ -1156,3 +1156,16 @@ type AliasValue struct {
|
||||
Alias string
|
||||
Weight float64
|
||||
}
|
||||
|
||||
// AttrSMGGetActiveSessions will filter returned sessions by SMGenericV1
|
||||
type AttrSMGGetActiveSessions struct {
|
||||
ToR *string
|
||||
RunID *string
|
||||
RequestType *string
|
||||
Tenant *string
|
||||
Category *string
|
||||
Account *string
|
||||
Subject *string
|
||||
Destination *string
|
||||
Supplier *string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user