diff --git a/main.go b/main.go index 50a399e..fd2fe94 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ package main import ( "flag" "fmt" - "gopkg.in/mgo.v2" "io/ioutil" "log" "net/http" @@ -12,6 +11,8 @@ import ( "path" "path/filepath" "time" + + "gopkg.in/mgo.v2" ) type Options struct { @@ -23,6 +24,7 @@ type Options struct { TimeStart time.Time DateStop time.Duration Version bool + Debug bool } const ( @@ -38,7 +40,7 @@ var ( opts = Options{ MongoUri: "mongodb://127.0.0.1:27018", LogFile: "log/imp.log", - DateStart: time.Now().Add(-time.Hour).Format(_tformat), + DateStart: time.Now().UTC().Add(-time.Hour).Format(_tformat), DateStop: time.Hour, } mimp = MongoImp{} @@ -55,7 +57,7 @@ func connectMongo() { } func usage() { - fmt.Println("Usage: imp_mongo -d -r -m -l -v\n") + fmt.Println("Usage: imp_mongo -d -r -m -l -v -D\n") os.Exit(0) } @@ -71,6 +73,7 @@ func init() { flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename") flag.StringVar(&opts.DateStart, "d", opts.DateStart, "From Date ") flag.DurationVar(&opts.DateStop, "r", opts.DateStop, "Duration h") + flag.BoolVar(&opts.Debug, "D", false, "Debug") flag.BoolVar(&opts.Version, "v", false, "Version") } @@ -141,8 +144,6 @@ func main() { } } - // fmt.Printf("%+v\n", mimp) - fmt.Printf("Stop: %v\n", time.Since(start)) log.Printf("Stop: %v\n", time.Since(start)) } diff --git a/parser.go b/parser.go index 72a101b..e01c04e 100644 --- a/parser.go +++ b/parser.go @@ -2,7 +2,7 @@ package main import ( - // "fmt" + "fmt" "log" "strconv" "strings" @@ -113,9 +113,11 @@ func parse(body string, stime time.Time) { index.Date = stime } else if strings.HasPrefix(lines[ind], "counters") { k := strings.Split(lines[ind], ";") - // fmt.Printf("%s = %s\n", k[0], k[1]) key := strings.Split(k[0], "/") - // fmt.Printf("Keys: %s - %s - %s\n", key[0], key[1], key[2]) + if opts.Debug { + // fmt.Printf("%s = %s\n", k[0], k[1]) + // fmt.Printf("Keys: %s - %s - %s\n", key[0], key[1], key[2]) + } if key[0] == "counters" { switch key[1] { case "banner": @@ -201,5 +203,8 @@ func parse(body string, stime time.Time) { if err != nil { log.Println("Insert Errro: ", err) } - // fmt.Printf("%+v\n", info) + + if opts.Debug { + fmt.Printf("%+v\n", mimp) + } }