diff --git a/Docker/Dockerfile b/Docker/Dockerfile new file mode 100644 index 0000000..edd0de7 --- /dev/null +++ b/Docker/Dockerfile @@ -0,0 +1,7 @@ +FROM scratch + +MAINTAINER Michele Fadda "" + +COPY imp_mongodb-v1.1.0 /bin/imp_mongodb + +ENTRYPOINT [ "/bin/imp_mongodb" ] \ No newline at end of file diff --git a/Docker/imp_mongodb-v1.1.0 b/Docker/imp_mongodb-v1.1.0 new file mode 100755 index 0000000..436fc95 Binary files /dev/null and b/Docker/imp_mongodb-v1.1.0 differ diff --git a/Docker/run.sh b/Docker/run.sh new file mode 100644 index 0000000..91026c9 --- /dev/null +++ b/Docker/run.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +docker run \ + --rm \ + -v /opt/impmongo/log:/data \ + --name impmongo \ + --log-opt max-size=2m \ + --log-opt max-file=5 \ + mikif70/impmongo:1.1.0 \ + -l /data/llmongo.log \ + -p /data/llmongo.pid \ + -m mongodb://10.39.80.189:27017 \ + -i http://10.39.109.107:8086 \ + $@ \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..dca2789 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo . diff --git a/influxdb.go b/influxdb.go index ff4daf3..c823dbe 100644 --- a/influxdb.go +++ b/influxdb.go @@ -55,13 +55,23 @@ func writeStats(mimp *MongoImp) { "rate_smtp": mimp.Rate.Smtpp, "rate_total": mimp.Rate.Totalp, } - pt, err := influxdb.NewPoint("cloudmark", tags, fields, mimp.Date) - if err != nil { - fmt.Printf("Error: %+v\n", err) - return - } + if opts.Out { + pt, err := influxdb.NewPoint("cloudmark_out", tags, fields, mimp.Date) + if err != nil { + fmt.Printf("Error: %+v\n", err) + return + } - bp.AddPoint(pt) + bp.AddPoint(pt) + } else { + pt, err := influxdb.NewPoint("cloudmark", tags, fields, mimp.Date) + if err != nil { + fmt.Printf("Error: %+v\n", err) + return + } + + bp.AddPoint(pt) + } // Write the batch c.Write(bp) diff --git a/main.go b/main.go index a77b772..259be66 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ type Options struct { DateStart string TimeStart time.Time DateStop time.Duration + Out bool Version bool Debug bool } @@ -38,6 +39,7 @@ const ( var ( _imp = [...]string{"cmgw-1", "cmgw-2", "cmgw-3", "cmgw-4"} + _out = [...]string{"michael", "santino"} opts = Options{ MongoUri: "mongodb://127.0.0.1:27018", LogFile: "log/imp.log", @@ -54,7 +56,12 @@ func connectMongo() { log.Println("Mongodb connect Error: ", err.Error()) os.Exit(-3) } - opts.ll = opts.mdb.DB("antispam").C("counters") + if opts.Out { + opts.ll = opts.mdb.DB("antispam").C("output") + } else { + opts.ll = opts.mdb.DB("antispam").C("counters") + } + } func usage() { @@ -75,6 +82,7 @@ func init() { flag.StringVar(&opts.DateStart, "d", opts.DateStart, "From Date ") flag.DurationVar(&opts.DateStop, "r", opts.DateStop, "Duration h") flag.StringVar(&opts.Influxdb, "i", "", "Influxdb") + flag.BoolVar(&opts.Out, "O", false, "Out") flag.BoolVar(&opts.Debug, "D", false, "Debug") flag.BoolVar(&opts.Version, "v", false, "Version") } @@ -135,21 +143,41 @@ func main() { for h := 0; h < int(opts.DateStop.Hours()); h++ { stime := opts.TimeStart.Add(time.Hour * time.Duration(h)) // fmt.Println("Time: ", stime) - for ind := range _imp { - uri := "http://" + _imp[ind] + _domain + ":" + _port + _dashboard + stime.Format("2006010215") + "00" - // fmt.Println(uri) - resp, err := http.Get(uri) - if err != nil { - log.Fatal(err) - } - body, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - log.Fatal(err) - } - parse(string(body), stime) + if opts.Out { + for ind := range _out { + uri := "http://" + _out[ind] + _domain + ":" + _port + _dashboard + stime.Format("2006010215") + "00" + // fmt.Println(uri) + resp, err := http.Get(uri) + if err != nil { + log.Fatal(err) + } + body, err := ioutil.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + log.Fatal(err) + } + + parse(string(body), stime) + } + } else { + for ind := range _imp { + uri := "http://" + _imp[ind] + _domain + ":" + _port + _dashboard + stime.Format("2006010215") + "00" + // fmt.Println(uri) + resp, err := http.Get(uri) + if err != nil { + log.Fatal(err) + } + body, err := ioutil.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + log.Fatal(err) + } + + parse(string(body), stime) + } } + } fmt.Printf("Stop: %v\n", time.Since(start))