Skip to content

Commit

Permalink
modifiy mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilux committed Mar 15, 2015
1 parent fdcded3 commit d0b3569
Show file tree
Hide file tree
Showing 7 changed files with 586 additions and 465 deletions.
124 changes: 90 additions & 34 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dbMySqlUser": "root",
"dbMySqlPassword": "lepanos",
"dbMySqlName": "asteriskcdrdb",
"dbMySqlFetchRowNumber": "25",
"dbMySqlFetchRowNumber": "100",
"mongoHost": "127.0.0.1",
"mongoDbName" : "revor",
"asteriskID": "asterisk1",
Expand All @@ -19,39 +19,95 @@
"f1com"
],
"dialplanContext": [
{ "name": "app-alive-test", "direction": 3},
{ "name": "app-custom-2587-day", "direction": 2},
{ "name": "app-custom-6705", "direction": 2},
{ "name": "app-custom-6710", "direction": 2},
{ "name": "app-custom-6711", "direction": 2},
{ "name": "app-custom-blf-queue", "direction": 3},
{ "name": "app-custom-getvoicemail", "direction": 3},
{ "name": "app-custom-op-sugar", "direction": 2},
{ "name": "app-ecoute-pvsa-bry", "direction": 2},
{ "name": "app-iax2-bischheim", "direction": 1},
{ "name": "app-iax2-cofintex", "direction": 1},
{ "name": "app-iax2-ludres", "direction": 1},
{ "name": "app-out", "direction": 1},
{ "name": "app-out-hangup-call-party", "direction": 1},
{ "name": "app-pickup", "direction": 3},
{ "name": "asterisk_guitools", "direction": 3},
{ "name": "default", "direction": 3},
{ "name": "DID_span_1", "direction": 2},
{ "name": "DID_span_2", "direction": 2},
{ "name": "DID_span_3", "direction": 1},
{ "name": "DID_span_4", "direction": 1},
{ "name": "DLPN_DialPlan1", "direction": 1},
{ "name": "DLPN_DialPlan2", "direction": 2},
{ "name": "process-in-fax", "direction": 3},
{ "name": "process-in-Modem-RSI", "direction": 3},
{ "name": "process-in-rsi", "direction": 3},
{ "name": "ringroups-custom-1", "direction": 2},
{ "name": "ringroups-custom-2", "direction": 2},
{ "name": "ringroups-custom-3", "direction": 2},
{ "name": "ringroups-custom-4", "direction": 2},
{ "name": "app-custom-from-pstn", "direction": 2},
{ "name": "stdexten", "direction": 3},
{ "name": "voicemenu-custom-1", "direction": 3}
{ "name": "app-out", "direction": 1},
{ "name": "DLPN_DialPlan1", "direction": 1},
{ "name": "app-asts-ecoute", "direction": 2},
{ "name": "DLPN_DialPlan2", "direction": 2},
{ "name": "default", "direction": 2},
{ "name": "ringroups-custom-1", "direction": 2},
{ "name": "ringroups-custom-2", "direction": 2},
{ "name": "ringroups-custom-3", "direction": 2},
{ "name": "app-critel-op", "direction": 1},
{ "name": "app-pickup", "direction": 3},
{ "name": "app-in", "direction": 2},
{ "name": "from-internal", "direction": 1},
{ "name": "from-pstn", "direction": 2},
{ "name": "DID_span_1", "direction": 2},
{ "name": "DID_span_2", "direction": 2},
{ "name": "DID_span_3", "direction": 2},
{ "name": "DID_span_4", "direction": 2},
{ "name": "DID_span_5", "direction": 2},
{ "name": "app-fax-in", "direction": 2},
{ "name": "app-asts-ecoute", "direction": 2},
{ "name": "voicemenu-custom-1", "direction": 2},
{ "name": "voicemenu-custom-2", "direction": 2},
{ "name": "voicemenu-custom-3", "direction": 2},
{ "name": "voicemenu-custom-4", "direction": 2},
{ "name": "voicemenu-custom-5", "direction": 2},
{ "name": "voicemenu-custom-6", "direction": 2},
{ "name": "voicemenu-custom-7", "direction": 2},
{ "name": "voicemenu-custom-8", "direction": 2},
{ "name": "voicemenu-custom-9", "direction": 2},
{ "name": "voicemenu-custom-10", "direction": 2},
{ "name": "voicemenu-custom-11", "direction": 2},
{ "name": "voicemenu-custom-12", "direction": 2},
{ "name": "voicemenu-custom-13", "direction": 2},
{ "name": "voicemenu-custom-14", "direction": 2},
{ "name": "voicemenu-custom-15", "direction": 2},
{ "name": "voicemenu-custom-16", "direction": 2},
{ "name": "voicemenu-custom-17", "direction": 2},
{ "name": "voicemenu-custom-18", "direction": 2},
{ "name": "voicemenu-custom-19", "direction": 2},
{ "name": "voicemenu-custom-20", "direction": 2},
{ "name": "voicemenu-custom-21", "direction": 2},
{ "name": "voicemenu-custom-22", "direction": 2},
{ "name": "voicemenu-custom-23", "direction": 2},
{ "name": "voicemenu-custom-24", "direction": 2},
{ "name": "voicemenu-custom-25", "direction": 2},
{ "name": "voicemenu-custom-26", "direction": 2},
{ "name": "voicemenu-custom-27", "direction": 2},
{ "name": "voicemenu-custom-28", "direction": 2},
{ "name": "voicemenu-custom-29", "direction": 2},
{ "name": "voicemenu-custom-30", "direction": 2},
{ "name": "voicemenu-custom-31", "direction": 2},
{ "name": "voicemenu-custom-32", "direction": 2},
{ "name": "voicemenu-custom-33", "direction": 2},
{ "name": "voicemenu-custom-34", "direction": 2},
{ "name": "voicemenu-custom-35", "direction": 2},
{ "name": "voicemenu-custom-36", "direction": 2},
{ "name": "voicemenu-custom-37", "direction": 2},
{ "name": "voicemenu-custom-38", "direction": 2},
{ "name": "voicemenu-custom-39", "direction": 2},
{ "name": "voicemenu-custom-40", "direction": 2},
{ "name": "voicemenu-custom-41", "direction": 2},
{ "name": "voicemenu-custom-42", "direction": 2},
{ "name": "voicemenu-custom-43", "direction": 2},
{ "name": "voicemenu-custom-44", "direction": 2},
{ "name": "voicemenu-custom-45", "direction": 2},
{ "name": "voicemenu-custom-46", "direction": 2},
{ "name": "voicemenu-custom-47", "direction": 2},
{ "name": "voicemenu-custom-48", "direction": 2},
{ "name": "voicemenu-custom-49", "direction": 2},
{ "name": "voicemenu-custom-50", "direction": 2},
{ "name": "voicemenu-custom-51", "direction": 2},
{ "name": "voicemenu-custom-52", "direction": 2},
{ "name": "voicemenu-custom-53", "direction": 2},
{ "name": "voicemenu-custom-54", "direction": 2},
{ "name": "voicemenu-custom-55", "direction": 2},
{ "name": "voicemenu-custom-56", "direction": 2},
{ "name": "voicemenu-custom-57", "direction": 2},
{ "name": "voicemenu-custom-58", "direction": 2},
{ "name": "voicemenu-custom-59", "direction": 2},
{ "name": "voicemenu-custom-60", "direction": 2},
{ "name": "voicemenu-custom-61", "direction": 2},
{ "name": "voicemenu-custom-62", "direction": 2},
{ "name": "voicemenu-custom-63", "direction": 2},
{ "name": "voicemenu-custom-64", "direction": 3},
{ "name": "voicemenu-custom-65", "direction": 2},
{ "name": "voicemenu-custom-66", "direction": 2},
{ "name": "voicemenu-custom-67", "direction": 2},
{ "name": "voicemenu-custom-68", "direction": 2},
{ "name": "asterisk_guitools", "direction":3}


]
Expand Down
99 changes: 67 additions & 32 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
TestCallSchedule int
DialplanContext []Context
Notifications []string
Dids []string
}

var (
Expand Down Expand Up @@ -154,17 +155,20 @@ func init() {
}

func getInOutStatus(cdr RawCall) (status int, err error) {
//config = GetConfig()
log.Tracef("Enter into getInOutStatus")
return getInOutContextStatus(cdr.Dcontext)
}

func getInOutContextStatus(context string) (status int, err error) {

for i := range config.DialplanContext {
if config.DialplanContext[i].Name == cdr.Dcontext {
if config.DialplanContext[i].Name == context {
status = config.DialplanContext[i].Direction
return status, nil

}
}
log.Infof("Can not find the call direction for the context [%s].", cdr.Dcontext)
return status, errors.New("Can't find the context direction for the context : " + cdr.Dcontext)
log.Infof("Can not find the call direction for the context [%s].", context)
return status, errors.New("Can't find the context direction for the context : " + context)

}

Expand Down Expand Up @@ -242,17 +246,17 @@ func importJob() {
//
var incommingCount = 0
var outgoingCount = 0

for _, cdr := range cdrs {
cdr.AsteriskId = config.AsteriskID
var datetime = cdr.Calldate.Format(time.RFC3339)
log.Tracef("Get raw cdr for the date [%s], the clid [%s] and the context [%s] from asterisk [%s]", datetime, cdr.ClidNumber, cdr.Dcontext, cdr.AsteriskId)
var cel Cel
cel, err = getMySqlCel(db, cdr.Uniqueid)
//var cel Cel
//cel, err = getMySqlCel(db, cdr.Uniqueid)
var inoutstatus, err = getInOutStatus(cdr)
if err != nil {
log.Criticalf("Get error[%s]. Please check your configuration file.", err)
log.Flush()
//panic(err)
os.Exit(1)
}
if inoutstatus == 1 {
Expand All @@ -269,17 +273,16 @@ func importJob() {
cdr.Disposition = 0
}

if cel.EventTime > 0 {
//extract the timezone offset
cdr.AnswerWaitTime = int(cel.EventTime - (cdr.Calldate.Unix() - timeZoneOffset))
}
//if cel.EventTime > 0 {
// //extract the timezone offset
// cdr.AnswerWaitTime = int(cel.EventTime - cdr.Calldate.Unix() - timeZoneOffset)
//}
//
callDetails, err := getMySqlCallDetails(db, cdr.Uniqueid)
if err != nil {
log.Criticalf("Try to get the call details but get the error[%s].", err)
log.Flush()
panic(err)
//os.Exit(1)
os.Exit(1)
}
//
log.Tracef("Get [%d] details records for the call with uniqueud [%s].",
Expand All @@ -288,36 +291,63 @@ func importJob() {
cdr.CallDetails = callDetails
}
//

if cdr.InoutStatus == DIRECTION_CALL_IN {
var extent = ""
var did = ""
var peer = ""
var exten = ""

if len(cdr.CallDetails) == 0 && cdr.Dnid != "" {
//a workaround if I can get cel records
did = cdr.Dnid
log.Tracef("Force did from cdr dnid [%s].", did)
}

for i := range cdr.CallDetails {
var callDetail = cdr.CallDetails[i]
if callDetail.EventType == "BRIDGE_END" {
if i == 0 && callDetail.EventType == "CHAN_START" {
exten = callDetail.Exten
}

if callDetail.EventType == "ANSWER" && exten == callDetail.CidDnid && did == "" {
did = callDetail.CidDnid

} else if callDetail.EventType == "BRIDGE_START" {
//bridge start gives the time before answer
cdr.AnswerWaitTime = int(callDetail.EventTime.Unix() - cdr.Calldate.Unix())

} else if callDetail.EventType == "BRIDGE_END" {
//idea to find the last BRIDGE_END event and get the extention from it
extent = getPeerFromChannel(callDetail.Peer)
log.Tracef("Get extent [%s] for peer [%s].",
extent, callDetail.Peer)
peer = getPeerFromChannel(callDetail.Peer)
break
}
}
if extent == "" {
cdr.Dst = getPeerFromChannel(cdr.Dstchannel)
log.Tracef("Exten is empty for dstchannel [%s] get dst [%s].", cdr.Dstchannel, cdr.Dst)
} else {
//must be checked cause by testing
if cdr.Dst == "s" {
cdr.Dst = getPeerFromChannel(cdr.Dstchannel)
} else {
cdr.Dst = cdr.Dst
}

if peer == "" {
peer = getPeerFromChannel(cdr.Dstchannel)
}

if cdr.Dnid == "" {
cdr.Dnid = cdr.Dst
cdr.Peer = peer

//there is a possibility to have for incomming call a peer for the did number
//this is dependes of the customer configuration
//try to find a did value from database defined by the customer
err := isDid(session, did)

if err == nil {
cdr.Did = did
} else {
cdr.Did = ""
}

}
log.Tracef("Didi verification [%s] and cdtDid [%s].\n", did, cdr.Did)

if cdr.Dst == "s" && peer != "" {
//
cdr.Dst = cdr.Peer
}

} //end of the incomming call process
//
//
err = importCdrToMongo(session, cdr)
Expand All @@ -328,9 +358,12 @@ func importJob() {
//
log.Debugf("Import executed for unique id [%s] with code : [%d], try process the mysql updating.\n",
cdr.Uniqueid, importedStatus)

err = udpateMySqlCdrImportStatus(db, cdr.Uniqueid, 1)

if err != nil {
log.Errorf("Can't update the import status for the call with unique id [%s].", cdr.Uniqueid)
log.Flush()
os.Exit(1)
}

Expand All @@ -341,6 +374,8 @@ func importJob() {

}
//
log.Trace("End of cdr parsing.\n")
//
spec := redis.DefaultSpec()
channel := "channel_cdr"
//
Expand Down
10 changes: 10 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Cdr struct {
waitAnswer int
inoutstatus int
causeStatus int
peer string
did string
}

type Cel struct {
Expand Down Expand Up @@ -49,6 +51,8 @@ type RawCall struct {
Dnid string `bson:"dnid"`
Dstchannel string `bson:"dst_channel"`
CallDetails []CallDetail `bson:"call_details"`
Peer string `bson:"peer"`
Did string `bson:"did"`
}

type CallDetail struct {
Expand Down Expand Up @@ -175,3 +179,9 @@ type MonthlyCall struct {
CallsDaily DatasByDayOfMonth `bson:"calls_per_days"`
DurationsDaily DatasByDayOfMonth `bson:"durations_per_days"`
}

type Did struct {
Did string `bson:"did" json:"did"`
Value string `json:"value" bson:"value"`
Comment string `json:"comment" bson:"comment"`
}
Loading

0 comments on commit d0b3569

Please sign in to comment.