diff --git a/config.json b/config.json index 831d287..f15952f 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "dbMySqlHost": "localhost:3306", + "dbMySqlHost": "127.0.0.1:3306", "dbMySqlUser": "root", "dbMySqlPassword": "lepanos", "dbMySqlName": "asteriskcdrdb", @@ -7,11 +7,11 @@ "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" ], @@ -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}, diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index abcb20d..afaf29d 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -3,7 +3,7 @@ Release Notes vorimport ---------- ================================================================================== -Release 1.0.3 date : 19/11/2013 +Release 1.0.4 date : 11/01/2015 ================================================================================== @@ -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 ================================================================================== @@ -40,7 +53,7 @@ New: ================================================================================== -Release 1.0.1 date : 23/09/2013 +Release 1.0.1 date : 23/09/2014 ================================================================================== @@ -55,7 +68,7 @@ New: ================================================================================== -Release 1.0.0 date : 16/09/2013 +Release 1.0.0 date : 16/09/2014 ================================================================================== Initial release diff --git a/logger.xml b/logger.xml index cf15971..caeedb2 100644 --- a/logger.xml +++ b/logger.xml @@ -1,4 +1,4 @@ - + diff --git a/main.go b/main.go index 7dfa840..ab875ed 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( ) const ( - VERSION = "1.0.3" + VERSION = "1.0.4" ) type Context struct { @@ -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() @@ -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() // @@ -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() diff --git a/mysql.go b/mysql.go index a01cbf8..f4eedad 100644 --- a/mysql.go +++ b/mysql.go @@ -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 @@ -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 } @@ -127,7 +130,7 @@ 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 { @@ -135,7 +138,7 @@ func getMysqlCdrTestCall(db mysql.Conn) (results []RawCall, err error) { 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 @@ -206,19 +209,20 @@ 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 } // @@ -226,8 +230,10 @@ func getMySqlCallDetails(db mysql.Conn, uniqueid string) (results []CallDetail, 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 @@ -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 } @@ -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 +} diff --git a/prepare_deploy.sh b/prepare_deploy.sh index 159ab65..a7b6a4c 100755 --- a/prepare_deploy.sh +++ b/prepare_deploy.sh @@ -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" diff --git a/samples/config.sample.json b/samples/config.sample.json index ed7d54f..046e7a6 100644 --- a/samples/config.sample.json +++ b/samples/config.sample.json @@ -1,15 +1,26 @@ { - "dbMySqlHost": "127.0.0.1:3306", + "dbMySqlHost": "127.0.0.1:3306", "dbMySqlUser": "asterisk", - "dbMySqlPassword": "asterisk", + "dbMySqlPassword": "crakcme", "dbMySqlName": "asteriskcdrdb", "dbMySqlFetchRowNumber": "81", "mongoHost": "127.0.0.1", - "asteriskID": "asterisk1", + "asteriskID": "asthost", "eventsMongoHost": "127.0.0.1", + "asteriskAddr": "127.0.0.1", + "asteriskPort" : 5038, + "asteriskUser" : "astmanager", + "asteriskPassword": "crackme", + "testCallSchedule": 20, + "notifications": [ + "f1com" + ], "dialplanContext": [ - { "name": "app-out", "direction": 1}, - { "name": "DLPN_DialPlan1", "direction": 2}, - { "name": "app-daynight-toggle", "direction": 3}, + { "name": "app-out", "direction": 1}, + { "name": "DLPN_DialPlan1", "direction": 2}, + { "name": "ringroups-custom-1", "direction": 2}, + { "name": "DID_span_1", "direction": 2}, + { "name": "app-daynight-toggle", "direction": 3} ] + } diff --git a/tests/clear_revor.sh b/tests/clear_revor.sh deleted file mode 100755 index e7d83a6..0000000 --- a/tests/clear_revor.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash -######################################################################################### -# -# -# -# -# -# Description : Clear import datas of revor mongodatabases -# Author : vassilux -# Last modified : 2014-09-18 14:00:00 -########################################################################################## - -function dprint() -{ - tput setb 1 - level="$1" - dtype="$2" - value="$3" - echo -e "\e[00;31m $dtype:$level $value \e[00m" >&2 -} - - -function main() -{ - dprint 0 INFO "Do you want to delete all revor import data?[y/N]" - read resp - if [ "$resp" = "" -o "$resp" = "n" ]; then - dprint 0 INFO "See you next time. Bye" - exit 0 - fi - - mongo revor --eval "db.cdrs.drop()" - mongo revor --eval "db.dailypeer_incomming.drop()" - - mongo revor --eval "db.dailypeer_outgoing.drop()" - mongo revor --eval "db.dailydid_incomming.drop()" - mongo revor --eval "db.monthlypeer__incomming.drop()" - mongo revor --eval "db.monthlypeer_incomming.drop()" - mongo revor --eval "db.monthlypeer_outgoing.drop()" - mongo revor --eval "db.monthlydid_incomming.drop()" - mongo revor --eval "db.monthlydid_summary.drop()" - mongo revor --eval "db.monthlydid_summary.drop()" - - mongo revor --eval "db.monthlypeeroutgoing_summary.drop()" - mongo revor --eval "db.monthlypeerincomming_summary.drop()" - - - -} - -main - - - - - - - - - - - - - - - - diff --git a/tests/import_data_tests.py b/tests/import_data_tests.py index e4493f5..c23bc9f 100644 --- a/tests/import_data_tests.py +++ b/tests/import_data_tests.py @@ -89,7 +89,7 @@ seconds_in_a_day = 60 * 60 * 24 -MONTH_AGO = 5 +MONTH_AGO = 0 # char_set_uniqueid = string.digits