usa la collection: lastlogin.lastlogin_yymm

This commit is contained in:
Miki 2016-05-09 12:10:27 +02:00
parent 2778e5506b
commit b97098e78b
2 changed files with 7 additions and 9 deletions

4
dbs.go
View file

@ -54,7 +54,7 @@ type Users struct {
Logins []IPs `json:"logins" bson:"logins"` Logins []IPs `json:"logins" bson:"logins"`
} }
func connectMongo() { func connectMongo(data string) {
if opts.MongoSrc == "" { if opts.MongoSrc == "" {
log.Fatalf("Mongodb URI invalid: '%s'\n", opts.MongoSrc) log.Fatalf("Mongodb URI invalid: '%s'\n", opts.MongoSrc)
@ -67,7 +67,7 @@ func connectMongo() {
os.Exit(-3) os.Exit(-3)
} }
dbs.mdbSrc.SetSocketTimeout(0) dbs.mdbSrc.SetSocketTimeout(0)
dbs.ll = dbs.mdbSrc.DB("dovecot").C("lastlogin") dbs.ll = dbs.mdbSrc.DB("lastlogin").C("lastlogin_" + data)
if opts.MongoDst == "" { if opts.MongoDst == "" {
dbs.mdbDst = dbs.mdbSrc dbs.mdbDst = dbs.mdbSrc

View file

@ -13,7 +13,7 @@ import (
) )
const ( const (
_VERSION = "v1.3.7" _VERSION = "v1.4.0"
_tformat = "2006-01-02" _tformat = "2006-01-02"
_24h = (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59) + (time.Millisecond * 999) _24h = (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59) + (time.Millisecond * 999)
_10m = (time.Minute * 10) _10m = (time.Minute * 10)
@ -74,24 +74,22 @@ func main() {
fmt.Printf("Start: %+v\n", opts) fmt.Printf("Start: %+v\n", opts)
log.Printf("Start: %+v\n", opts) log.Printf("Start: %+v\n", opts)
connectMongo()
defer dbs.mdbSrc.Close()
defer dbs.mdbDst.Close()
y, err := time.Parse(_tformat, opts.StartDate) y, err := time.Parse(_tformat, opts.StartDate)
if err != nil { if err != nil {
log.Println("Date Error: ", err) log.Println("Date Error: ", err)
os.Exit(-1) os.Exit(-1)
} }
var ys time.Time var ys time.Time
var ye time.Time var ye time.Time
ys = time.Date(y.Year(), y.Month(), y.Day(), 0, 0, 0, 0, time.UTC) ys = time.Date(y.Year(), y.Month(), y.Day(), 0, 0, 0, 0, time.UTC)
ye = ys.Add(opts.Duration) ye = ys.Add(opts.Duration)
idb = Influxdb(start, ys) idb = Influxdb(start, ys)
connectMongo(ys.Format("0601"))
defer dbs.mdbSrc.Close()
defer dbs.mdbDst.Close()
// DEBUG // DEBUG
if opts.Debug { if opts.Debug {
fmt.Printf("Start: %+v, Stop: %+v\n\r", ys, ye) fmt.Printf("Start: %+v, Stop: %+v\n\r", ys, ye)