Skip to content

Commit

Permalink
Fix pvsa
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilux committed Mar 12, 2015
1 parent a5088ee commit fdcded3
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 72 deletions.
92 changes: 37 additions & 55 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"dbMySqlHost": "192.168.3.20:3306",
"dbMySqlHost": "127.0.0.1:3306",
"dbMySqlUser": "root",
"dbMySqlPassword": "lepanos",
"dbMySqlName": "asteriskcdrdb",
"dbMySqlFetchRowNumber": "81",
"dbMySqlFetchRowNumber": "25",
"mongoHost": "127.0.0.1",
"mongoDbName" : "revor",
"asteriskID": "asterisk1",
Expand All @@ -14,63 +14,45 @@
"testCallActive": false,
"testCallSchedule": 120,
"eventsMongoHost": "127.0.0.1",
"purgeCelEvents": false,
"notifications": [
"f1com"
],
"dialplanContext": [
{ "name": "app-out", "direction": 1},
{ "name": "incomming", "direction": 2},
{ "name": "outgoing", "direction": 1},
{ "name": "DLPN_DialPlan1", "direction": 2},
{ "name": "app-daynight-toggle", "direction": 3},
{ "name": "app-custom-blf-queue", "direction": 3},
{ "name": "iax2-esi-internal", "direction": 3},
{ "name": "test-dnd", "direction": 3},
{ "name": "app-pickup", "direction": 3},
{ "name": "app-custom-2802-vm-on", "direction": 3},
{ "name": "app-custom-2802-vm-off", "direction": 3},
{ "name": "test-incall-for-kebab", "direction": 1},
{ "name": "test-teletech-alarm-call", "direction": 1},
{ "name": "default", "direction": 2},
{ "name": "ringroups-custom-2", "direction": 2},
{ "name": "app-custom-2802-vm", "direction": 2},

{ "name": "app-custom-get-vm", "direction": 2},
{ "name": "app-dial-secratary", "direction": 2},
{ "name": "app-dial-secratary", "direction": 2},
{ "name": "test-teletech-alarm-call", "direction": 1},
{ "name": "incomming-calls-f1-playback", "direction": 2},
{ "name": "app-custom-play-office-holiday", "direction": 2},
{ "name": "from-xoip-f1", "direction": 2},
{ "name": "inner-calls", "direction": 3},
{ "name": "ringroups-custom-1", "direction": 2},
{ "name": "ringroups-custom-2", "direction": 2},
{ "name": "ringroups-custom-3", "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": "DID_span_6", "direction": 2},
{ "name": "CallingRule_0_national", "direction": 1},
{ "name": "queues", "direction": 2},
{ "name": "voicemenu-custom-1", "direction": 2},
{ "name": "incomming-calls-for-recording", "direction": 2},
{ "name": "incomming-calls-f1com", "direction": 1},
{ "name": "from-g200be", "direction": 2},
{ "name": "to-g200be", "direction": 1},
{ "name": "asterisk_guitools", "direction": 3},
{ "name": "simulate-outcall", "direction": 3},
{ "name": "test-teletech-alive-call", "direction": 1},
{ "name": "voicemenu-custom-2", "direction": 2},
{ "name": "voicemenu-custom-1", "direction": 2},
{ "name": "conferences", "direction": 2},
{ "name": "appc-esi-conference", "direction": 3},
{ "name": "app-recorde-prompt", "direction": 3},
{ "name": "appc-esi-conference-room-choise", "direction": 3},
{ "name": "app-set-forward-number", "direction": 3},
{ "name": "app-ext-blf-custom", "direction": 3},
{ "name": "app-custom-9999", "direction": 3}
{ "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}


]
}
2 changes: 1 addition & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Crée un lien symbolic ln -s /opt/revor/vorimport_[version] /opt/vorimport/curre
### Configuraiton
Copier le fichier config.sample.json en config.json : cp config.sample.json config.json
Addapter ce fichier à la configuraiton de système : le dialplan de iPBX et les besoin du client.
Addapter ce fichier à la configuraiton de système : le dialplan de iPBX et les besoins du client.

Context app-alive-test de asterisk dialplan est utilisé pour générer un test cyclique de toute la chaine
Ce context peut être ajouter dans /etc/asterisk/extensions_custom.conf.
Expand Down
26 changes: 18 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Config struct {
AsteriskUser string
AsteriskPassword string
TestCallActive bool
PurgeCelEvents bool
TestCallSchedule int
DialplanContext []Context
Notifications []string
Expand Down Expand Up @@ -153,7 +154,7 @@ func init() {
}

func getInOutStatus(cdr RawCall) (status int, err error) {
config = GetConfig()
//config = GetConfig()
log.Tracef("Enter into getInOutStatus")
for i := range config.DialplanContext {
if config.DialplanContext[i].Name == cdr.Dcontext {
Expand Down Expand Up @@ -296,20 +297,29 @@ func importJob() {
extent = getPeerFromChannel(callDetail.Peer)
log.Tracef("Get extent [%s] for peer [%s].",
extent, callDetail.Peer)
//break
break
}
}
if extent != "" {
cdr.Dst = extent
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
cdr.Dst = cdr.Dst //getPeerFromChannel(cdr.Dstchannel)
if cdr.Dst == "s" {
cdr.Dst = getPeerFromChannel(cdr.Dstchannel)
} else {
cdr.Dst = cdr.Dst
}

}

if cdr.Dnid == "" {
cdr.Dnid = cdr.Dst
}

} else {
cdr.Dst = cdr.Dnid
}
//
//
err = importCdrToMongo(session, cdr)
var importedStatus = 1
if err != nil {
Expand All @@ -318,7 +328,7 @@ 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, 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)
os.Exit(1)
Expand Down
52 changes: 47 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,67 @@
package main

import (
"strings"
"testing"
"time"
//"time"
)

func getPeerFromChannel(channel string) (peer string) {
//try to find the destination from channel
delim := '-'
if strings.Contains(channel, "@") {
delim = '@'
}

w := strings.FieldsFunc(channel, func(r rune) bool {
switch r {

case '/', delim:
return true
}
return false
})

if len(w) >= 3 {
return w[len(w)-2]
} else {
return channel
}

}

func Test_DstChannel(t *testing.T) {
var channel = "SIP/6006-01010101"
peer := getPeerFromChannel(channel)
if peer != "6006" {
t.Error("It is not good peer for channel [%s].", channel)
t.Fail()
}
channel = "DAHDI/g1/0493948400-01010101"
peer = getPeerFromChannel(channel)
if peer != "0493948400" {
t.Error("It is not good peer [%s] for channel [%s].", peer, channel)
t.Fail()
}
t.Log("dstChannelTester test passed.")
channel = "'DAHDI/132-1'"
peer = getPeerFromChannel(channel)
if peer != "132" {
t.Error("It is not good peer [%s] for channel [%s].", peer, channel)
t.Fail()
}

channel = "Local/8129@DLPN_DialPlan1-000000e6;1"
peer = getPeerFromChannel(channel)
if peer != "8129" {
t.Errorf("It is not good peer [%s] for channel [%s].", peer, channel)
t.Fail()
}

t.Log("dstChannelTester test passed.")
}

func Test_EventWatcher_MySql(t *testing.T) {
/*func Test_EventWatcher_MySql(t *testing.T) {
loadConfig(false)
config := GetConfig()
eventWatcher := NewEventWatcher(config)
Expand Down Expand Up @@ -71,9 +113,9 @@ func Test_EventWatcher_MySql(t *testing.T) {
t.Fail()
}
}
}*/

func Test_CallOriginator(t *testing.T) {
/*func Test_CallOriginator(t *testing.T) {
addr := "192.168.3.20"
port := 5038
user := "astmanager"
Expand All @@ -85,4 +127,4 @@ func Test_CallOriginator(t *testing.T) {
time.Sleep(1 * time.Second)
}
}*/
1 change: 1 addition & 0 deletions mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func processDailyAnalytics(session *mgo.Session, cdr RawCall) (err error) {
//
func processDidImport(session *mgo.Session, cdr RawCall) (err error) {
log.Tracef("Import by did : %s\n", cdr.Dnid)

err = processDidDailyAnalytics(session, cdr)
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func bracket(r rune) bool {
*/
func getMysqlCdr(db mysql.Conn) (results []RawCall, err error) {
log.Tracef("Enter into getMysqlCdr")
myQuery := "SELECT UNIX_TIMESTAMP(calldate) as calldate, clid, src, dst, channel, dcontext, disposition,billsec,duration,uniqueid,dstchannel, dnid, recordfile from asteriskcdrdb.cdr WHERE import = 0 and dcontext NOT LIKE 'app-alive-test' LIMIT 0, " + config.DbMySqlFetchRowNumber
myQuery := "SELECT UNIX_TIMESTAMP(calldate) as calldate, clid, src, dst, channel, dcontext, disposition,billsec,duration,uniqueid,dstchannel, dnid, recordfile from asteriskcdrdb.cdr WHERE import = 0 and dcontext NOT LIKE 'app-alive-test' LIMIT " + config.DbMySqlFetchRowNumber
//
log.Debugf("Executing request [%s]\r\n", myQuery)
rows, res, err := db.Query(myQuery)
Expand Down Expand Up @@ -128,7 +128,7 @@ func getMySqlCel(db mysql.Conn, uniqueid string) (cel Cel, err error) {

func getMysqlCdrTestCall(db mysql.Conn) (results []RawCall, err error) {
log.Tracef("Enter into getMysqlCdr")
myQuery := "SELECT UNIX_TIMESTAMP(calldate) as calldate, clid, src, dst, channel, dcontext, disposition,billsec,duration,uniqueid,dstchannel, dnid, recordfile from asteriskcdrdb.cdr WHERE import = 0 and dcontext LIKE 'app-alive-test' LIMIT 0, " + config.DbMySqlFetchRowNumber
myQuery := "SELECT UNIX_TIMESTAMP(calldate) as calldate, clid, src, dst, channel, dcontext, disposition,billsec,duration,uniqueid,dstchannel, dnid, recordfile from asteriskcdrdb.cdr WHERE import = 0 and dcontext LIKE 'app-alive-test' LIMIT " + config.DbMySqlFetchRowNumber
//
log.Debugf("Executing request [%s]\r\n", myQuery)
rows, res, err := db.Query(myQuery)
Expand Down Expand Up @@ -309,6 +309,11 @@ func deleteMySqlCdrRecord(db mysql.Conn, uniqueid string) (err error) {
}

func deleteMySqlCelRecord(db mysql.Conn, uniqueid string) (err error) {

if config.PurgeCelEvents == false {
return nil
}

var query = fmt.Sprintf("DELETE FROM cel WHERE uniqueid = '%s' OR linkedid = '%s'", uniqueid, uniqueid)
_, _, err = db.Query(query)

Expand Down
10 changes: 9 additions & 1 deletion tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import (
)

func getPeerFromChannel(channel string) (peer string) {
//try to find the destination from channel
delim := '-'
if strings.Contains(channel, "@") {
delim = '@'
}

w := strings.FieldsFunc(channel, func(r rune) bool {
switch r {
case '/', '-', ' ':

case '/', delim:
return true
}
return false
Expand All @@ -19,6 +26,7 @@ func getPeerFromChannel(channel string) (peer string) {
} else {
return channel
}

}

func schedule(what func(), delay time.Duration) chan bool {
Expand Down

0 comments on commit fdcded3

Please sign in to comment.