-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo.go
66 lines (54 loc) · 1.39 KB
/
mongo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
log "github.com/cihub/seelog"
"labix.org/v2/mgo"
"os"
)
type TestDummy struct {
FirstName string
}
//
func createMongoCdr(session *mgo.Session, cdr RawCall) (err error) {
collection := session.DB(config.MongoDbName).C("cdrs")
//
err = collection.Insert(cdr)
if err != nil {
log.Criticalf("Can't insert document: %v", err)
os.Exit(1)
} else {
log.Debugf("Row inserted into mongo database for %s from asterisk [%s]", cdr.ClidName, cdr.AsteriskId)
}
return
}
func importCdrToMongo(session *mgo.Session, cdr RawCall) (err error) {
log.Debugf("Start analyze data for mongo database from asterisk : [%s].", cdr.AsteriskId)
createMongoCdr(session, cdr)
for i := range config.ExcludeFromAnalytics {
if config.ExcludeFromAnalytics[i] == cdr.Peer || config.ExcludeFromAnalytics[i] == cdr.Did {
log.Debugf("Call with the uniqueid skipped [%s] from the analytic process.\n ", cdr.Uniqueid)
return nil
}
}
if cdr.InoutStatus == DIRECTION_CALL_IGNORE {
return nil
}
if cdr.Dst != "s" {
//can import for peer(users)
err = processDailyAnalytics(session, cdr)
if err != nil {
return err
}
err = processMonthlyAnalytics(session, cdr)
if err != nil {
return err
}
err = processPeerMonthlySummary(session, cdr)
if err != nil {
return err
}
}
if cdr.InoutStatus == DIRECTION_CALL_IN {
err = processDidImport(session, cdr)
}
return err
}