Skip to content

Commit

Permalink
Fix cel clean after import
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilux committed Jan 11, 2015
1 parent 89577ec commit 7613cba
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 128 deletions.
15 changes: 12 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"dbMySqlHost": "localhost:3306",
"dbMySqlHost": "127.0.0.1:3306",
"dbMySqlUser": "root",
"dbMySqlPassword": "lepanos",
"dbMySqlName": "asteriskcdrdb",
"dbMySqlFetchRowNumber": "81",
"mongoHost": "127.0.0.1",
"asteriskID": "asterisk1",
"eventsMongoHost": "127.0.0.1",
"asteriskAddr": "127.0.0.1",
"asteriskAddr": "192.168.3.20",
"asteriskPort" : 5038,
"asteriskUser" : "astmanager",
"asteriskPassword": "lepanos",
"testCallSchedule": 20,
"testCallSchedule": 120,
"notifications": [
"f1com"
],
Expand All @@ -21,16 +21,25 @@
{ "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},
Expand Down
21 changes: 17 additions & 4 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Release Notes vorimport
----------
==================================================================================

Release 1.0.3 date : 19/11/2013
Release 1.0.4 date : 11/01/2015

==================================================================================

Expand All @@ -16,7 +16,20 @@ New:

==================================================================================

Release 1.0.2 date : 20/09/2013
Release 1.0.3 date : 19/11/2014

==================================================================================

Fixing:
Fix collections name

New:



==================================================================================

Release 1.0.2 date : 20/09/2014

==================================================================================

Expand All @@ -40,7 +53,7 @@ New:

==================================================================================

Release 1.0.1 date : 23/09/2013
Release 1.0.1 date : 23/09/2014

==================================================================================

Expand All @@ -55,7 +68,7 @@ New:

==================================================================================

Release 1.0.0 date : 16/09/2013
Release 1.0.0 date : 16/09/2014

==================================================================================
Initial release
Expand Down
2 changes: 1 addition & 1 deletion logger.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<seelog type="adaptive" mininterval="2000000" maxinterval="100000000" critmsgcount="500" minlevel="info">
<seelog type="adaptive" mininterval="2000000" maxinterval="100000000" critmsgcount="500" minlevel="trace">
<exceptions>
<exception filepattern="test*" minlevel="error"/>
</exceptions>
Expand Down
31 changes: 30 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const (
VERSION = "1.0.3"
VERSION = "1.0.4"
)

type Context struct {
Expand Down Expand Up @@ -318,6 +318,12 @@ func importJob() {
log.Errorf("Can't update the import status for the call with unique id [%s].", cdr.Uniqueid)
os.Exit(1)
}

err = deleteMySqlCelRecord(db, cdr.Uniqueid)
if err != nil {
log.Errorf("Can't delete cel records for uniqueid[%s].", cdr.Uniqueid)
}

}
//
spec := redis.DefaultSpec()
Expand Down Expand Up @@ -393,6 +399,26 @@ func generateTestCall() {
}
}

func checkConfigAndDie() {
if len(config.AsteriskAddr) == 0 {
log.Critical("Asterisk address is null or empty. Please check the configuraiton file.\n")
log.Flush()
os.Exit(1)
}

if len(config.AsteriskUser) == 0 || len(config.AsteriskPassword) == 0 {
log.Critical("Asterisk credentials missing. Please check the configuration file.\n")
log.Flush()
os.Exit(1)
}

if config.TestCallSchedule < 30 {
log.Criticalf("Asterisk tesing interval is too short : %d. Minimal value is 30(seconds).Please check the configuration file.\n", config.TestCallSchedule)
log.Flush()
os.Exit(1)
}
}

func main() {
flag.Parse()
//
Expand All @@ -406,6 +432,9 @@ func main() {
loadConfig(true)
//
config = GetConfig()
//to be carrefule and check if the configuraiton is not
checkConfigAndDie()

//
eventWatcher = NewEventWatcher(config)
go eventWatcher.run()
Expand Down
111 changes: 67 additions & 44 deletions mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ 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
//
log.Tracef("Executing request [%s]\r\n", myQuery)
log.Debugf("Executing request [%s]\r\n", myQuery)
rows, res, err := db.Query(myQuery)
//
if err != nil {
log.Debugf("Executing request [%s] and get error [%s] \r\n", myQuery, err)
log.Errorf("Executing request [%s] and get error [%s] \r\n", myQuery, err)
return nil, err
}
//
log.Tracef("Request executed and get [%d] rows\r\n", len(rows))
log.Tracef("getMysqlCdr request executed and get [%d] rows\r\n", len(rows))
//prepare results array
results = make([]RawCall, len(rows))
i := 0
Expand Down Expand Up @@ -104,19 +104,22 @@ func getMysqlCdr(db mysql.Conn) (results []RawCall, err error) {
* Process selection CEL events for given unique id
*/
func getMySqlCel(db mysql.Conn, uniqueid string) (cel Cel, err error) {
myCelQuery := "select UNIX_TIMESTAMP(eventtime) as eventtime from cel where eventtype LIKE 'ANSWER' AND linkedid!=uniqueid AND linkedid=" + uniqueid
myCelQuery := "select UNIX_TIMESTAMP(eventtime) as eventtime from cel where eventtype LIKE 'ANSWER' AND linkedid!=uniqueid AND linkedid='" + uniqueid + "'"
//
rows, res, err := db.Query(myCelQuery)
if err != nil {
return cel, err
}

log.Tracef("getMySqlCel request executed and get [%d] rows\r\n", len(rows))

if len(rows) > 0 {
log.Tracef("Get rows for uniqueid [%s]", uniqueid)
log.Tracef("getMySqlCel get rows for uniqueid [%s]", uniqueid)
row := rows[0]
eventtime := res.Map("eventtime")
cel.EventTime = row.Int64(eventtime)
} else {
log.Tracef("Can't get rows for uniqueid [%s].", uniqueid)
log.Tracef("getMySqlCel faied to get rows for uniqueid [%s].", uniqueid)
cel.EventTime = 0
}

Expand All @@ -127,15 +130,15 @@ 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
//
log.Tracef("Executing request [%s]\r\n", myQuery)
log.Debugf("Executing request [%s]\r\n", myQuery)
rows, res, err := db.Query(myQuery)
//
if err != nil {
log.Debugf("Executing request [%s] and get error [%s] \r\n", myQuery, err)
return nil, err
}
//
log.Tracef("Request executed and get [%d] rows\r\n", len(rows))
log.Tracef("getMysqlCdrTestCall Request executed and get [%d] rows\r\n", len(rows))
//prepare results array
results = make([]RawCall, len(rows))
i := 0
Expand Down Expand Up @@ -206,28 +209,31 @@ func getMysqlCdrTestCall(db mysql.Conn) (results []RawCall, err error) {
func getMySqlCallDetails(db mysql.Conn, uniqueid string) (results []CallDetail, err error) {
var sqlBase = "SELECT eventtype, UNIX_TIMESTAMP(eventtime) as eventtime, cid_num, cid_dnid, exten, context, peer, uniqueid, linkedid FROM cel WHERE "
var sqlOrder = " order by eventtime, id"
//
var sqlStart = sqlBase + "uniqueid = " + uniqueid + " OR linkedid = " + uniqueid + sqlOrder
//
/*myQuery := "SELECT eventtype, UNIX_TIMESTAMP(eventtime) as eventtime, cid_num, cid_dnid, exten, context, peer, uniqueid, linkedid FROM cel WHERE uniqueid =" +
uniqueid + " OR linkedid = " + uniqueid + " order by eventtime, id"*/
log.Tracef(" getMySqlCallDetails Executing request [%s]\r\n", sqlStart)

var sqlStart = sqlBase + " uniqueid = '" + uniqueid + "' OR linkedid = '" + uniqueid + "' " + sqlOrder

log.Debugf("getMySqlCallDetails execute request [%s]\n", sqlStart)

rows, res, err := db.Query(sqlStart)
//
if err != nil {
log.Debugf(" getMySqlCallDetailsExecuting request [%s] and get error [%s] \r\n", sqlStart, err)
log.Debugf("getMySqlCallDetailsExecuting request get error [%s]\n", err)
return nil, err
}

if len(rows) == 0 {
log.Tracef("getMySqlCallDetails 0 records from cel table for uniqueid [%s]\n", uniqueid)
return nil, nil
}
//
var searchIdMap = make(map[string]string)
for _, row := range rows {
uniqueid := res.Map("uniqueid")
linkedid := res.Map("linkedid")
searchIdMap[row.Str(uniqueid)] = row.Str(uniqueid)
searchIdMap[row.Str(linkedid)] = row.Str(linkedid)
keyUniqueid := fmt.Sprintf("'%s'", row.Str(uniqueid))
keyLinkedId := fmt.Sprintf("'%s'", row.Str(linkedid))
searchIdMap[keyUniqueid] = keyUniqueid
searchIdMap[keyLinkedId] = keyLinkedId

}
var keys []string
Expand All @@ -237,48 +243,53 @@ func getMySqlCallDetails(db mysql.Conn, uniqueid string) (results []CallDetail,
var strIds = strings.Join(keys, ",")

var sqlNext = sqlBase + "uniqueid IN (" + strIds + ") OR linkedid IN (" + strIds + ")" + sqlOrder

log.Debugf("getMySqlCallDetailsExecuting sqlNext [%s].\n", sqlNext)

//
rows, res, err = db.Query(sqlNext)
if err != nil {
log.Debugf(" getMySqlCallDetailsExecuting request [%s] and get error [%s] \r\n", sqlNext, err)
return nil, err
rowsNext, resNext, errNext := db.Query(sqlNext)
if errNext != nil {
log.Debugf(" getMySqlCallDetailsExecuting request [%s] and get error [%s] \r\n", sqlNext, errNext)
return nil, errNext
}
if len(rows) == 0 {

if len(rowsNext) == 0 {
return nil, nil
}

//prepare results array
results = make([]CallDetail, len(rows))
log.Debugf("getMySqlCallDetails create results for [%d] rows\r\n", len(rows))
results = make([]CallDetail, len(rowsNext))
log.Tracef("getMySqlCallDetails create results for [%d] rows\r\n", len(rowsNext))
i := 0
for _, row := range rows {
for _, rowNext := range rowsNext {
//
var c CallDetail
//mapping databases fields
eventtype := res.Map("eventtype")
eventtime := res.Map("eventtime")
cid_num := res.Map("cid_num")
cid_dnid := res.Map("cid_dnid")
exten := res.Map("exten")
uniqueid := res.Map("uniqueid")
linkedid := res.Map("linkedid")
context := res.Map("context")
peer := res.Map("peer")
eventtype := resNext.Map("eventtype")
eventtime := resNext.Map("eventtime")
cid_num := resNext.Map("cid_num")
cid_dnid := resNext.Map("cid_dnid")
exten := resNext.Map("exten")
uniqueid := resNext.Map("uniqueid")
linkedid := resNext.Map("linkedid")
context := resNext.Map("context")
peer := resNext.Map("peer")
//
c.EventType = row.Str(eventtype)
c.EventTime = time.Unix(row.Int64(eventtime)+int64(timeZoneOffset), 0)
c.CidNum = row.Str(cid_num)
c.CidDnid = row.Str(cid_dnid)
c.Exten = row.Str(exten)
c.UniqueId = row.Str(uniqueid)
c.LinkedId = row.Str(linkedid)
c.Peer = row.Str(peer)
c.Context = row.Str(context)
c.EventType = rowNext.Str(eventtype)
c.EventTime = time.Unix(rowNext.Int64(eventtime)+int64(timeZoneOffset), 0)
c.CidNum = rowNext.Str(cid_num)
c.CidDnid = rowNext.Str(cid_dnid)
c.Exten = rowNext.Str(exten)
c.UniqueId = rowNext.Str(uniqueid)
c.LinkedId = rowNext.Str(linkedid)
c.Peer = rowNext.Str(peer)
c.Context = rowNext.Str(context)

results[i] = c
i++

}
log.Debugf("getMySqlCallDetails Return [%d] results .\r\n", len(results))
log.Tracef("getMySqlCallDetails Return [%d] results .\r\n", len(results))
return results, nil
}

Expand All @@ -295,3 +306,15 @@ func deleteMySqlCdrRecord(db mysql.Conn, uniqueid string) (err error) {
//
return err
}

func deleteMySqlCelRecord(db mysql.Conn, uniqueid string) (err error) {
var query = fmt.Sprintf("DELETE FROM cel WHERE uniqueid = '%s' OR linkedid = '%s'", uniqueid, uniqueid)
_, _, err = db.Query(query)

log.Debugf("getMySqlCallDetails execute : [%s] .\n", query)

if err != nil {
log.Errorf("deleteMySqlCelRecord Failed delete record into cel table for uniqueid [%s].\n", uniqueid)
}
return err
}
2 changes: 1 addition & 1 deletion prepare_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e

VER_MAJOR="1"
VER_MINOR="0"
VER_PATCH="3"
VER_PATCH="4"

DEPLOY_DIR="vorimport_${VER_MAJOR}.${VER_MINOR}.${VER_PATCH}"
DEPLOY_FILE_NAME="vorimport_${VER_MAJOR}.${VER_MINOR}.${VER_PATCH}.tar.gz"
Expand Down
Loading

0 comments on commit 7613cba

Please sign in to comment.