gestisce cluster di mongodb
aggiunte le funzioni di hash con SHA1 e MD5 (default)
This commit is contained in:
parent
6896b447c5
commit
7a52478c63
6 changed files with 29 additions and 9 deletions
|
@ -3,6 +3,6 @@ FROM scratch
|
||||||
|
|
||||||
MAINTAINER Michele Fadda "<mikif70@gmail.com>"
|
MAINTAINER Michele Fadda "<mikif70@gmail.com>"
|
||||||
|
|
||||||
COPY lastlogin_mongodb-v4.2.0 /bin/lastlogin_mongodb
|
COPY lastlogin_mongodb-v4.3.0 /bin/lastlogin_mongodb
|
||||||
|
|
||||||
ENTRYPOINT [ "/bin/lastlogin_mongodb" ]
|
ENTRYPOINT [ "/bin/lastlogin_mongodb" ]
|
||||||
|
|
3
Docker/build.sh
Executable file
3
Docker/build.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker build -t mikif70/llmongo:4.3.0 .
|
|
@ -6,9 +6,8 @@ docker run \
|
||||||
--name llmongo_tiscali \
|
--name llmongo_tiscali \
|
||||||
--log-opt max-size=2m \
|
--log-opt max-size=2m \
|
||||||
--log-opt max-file=5 \
|
--log-opt max-file=5 \
|
||||||
mikif70/llmongo:4.2.0 \
|
mikif70/llmongo:4.2.1 \
|
||||||
-l /data/llmongo.log \
|
-l /data/llmongo.log \
|
||||||
-p /data/llmongo.pid \
|
|
||||||
-r redis-ll.mail.tiscali.sys:6379 \
|
-r redis-ll.mail.tiscali.sys:6379 \
|
||||||
-m 10.39.80.189:27017 \
|
-m 10.39.80.189:27017 \
|
||||||
-d lastlogin \
|
-d lastlogin \
|
||||||
|
|
22
consumer.go
22
consumer.go
|
@ -2,6 +2,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/sha1"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -19,7 +21,7 @@ type consumed struct {
|
||||||
logins []string
|
logins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func hash(val []byte) string {
|
func hash256(val []byte) string {
|
||||||
|
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write(val)
|
h.Write(val)
|
||||||
|
@ -27,6 +29,22 @@ func hash(val []byte) string {
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hash160(val []byte) string {
|
||||||
|
|
||||||
|
h := sha1.New()
|
||||||
|
h.Write(val)
|
||||||
|
|
||||||
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func hash128(val []byte) string {
|
||||||
|
|
||||||
|
h := md5.New()
|
||||||
|
h.Write(val)
|
||||||
|
|
||||||
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
|
}
|
||||||
|
|
||||||
// protocol:timestamp:ip:country
|
// protocol:timestamp:ip:country
|
||||||
|
|
||||||
func consumer() {
|
func consumer() {
|
||||||
|
@ -68,7 +86,7 @@ func consumer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// genera l' _ID con user + timestamp + ip
|
// genera l' _ID con user + timestamp + ip
|
||||||
mlID := hash([]byte(fmt.Sprintf("%s%s%s", prod.user, time.Unix(date, 0).Format("20060102T15"), sval[2]))) // Format("20060102T150405")
|
mlID := hash160([]byte(fmt.Sprintf("%s%s%s", prod.user, time.Unix(date, 0).Format("20060102T15"), sval[2]))) // Format("20060102T150405")
|
||||||
ml := MongoLogin{
|
ml := MongoLogin{
|
||||||
ID: mlID,
|
ID: mlID,
|
||||||
User: prod.user,
|
User: prod.user,
|
||||||
|
|
2
dbs.go
2
dbs.go
|
@ -90,7 +90,7 @@ func (db *Dbs) poolRedis() {
|
||||||
|
|
||||||
func (db *Dbs) connectMongo() {
|
func (db *Dbs) connectMongo() {
|
||||||
|
|
||||||
mongoList := strings.Split(db.MongoURI, ",")
|
mongoList := strings.Split(db.MongoURI, "|")
|
||||||
|
|
||||||
for m := range mongoList {
|
for m := range mongoList {
|
||||||
nm, err := mgo.Dial(fmt.Sprintf("mongodb://%s", mongoList[m]))
|
nm, err := mgo.Dial(fmt.Sprintf("mongodb://%s", mongoList[m]))
|
||||||
|
|
6
main.go
6
main.go
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_Version = "v4.2.0"
|
_Version = "v4.3.0"
|
||||||
_Producer = 0
|
_Producer = 0
|
||||||
_Consumer = 1
|
_Consumer = 1
|
||||||
_Remover = 2
|
_Remover = 2
|
||||||
|
@ -75,8 +75,8 @@ func main() {
|
||||||
// defer pid.Remove()
|
// defer pid.Remove()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
fmt.Printf("Start: %+v\n", opts)
|
fmt.Printf("Start:\t%+v\n\t%+v\n", opts, dbs)
|
||||||
log.Printf("Start: %+v\n", opts)
|
log.Printf("Start:\t%+v\n\t%+v\n", opts, dbs)
|
||||||
|
|
||||||
opts.Month = start.Format("0601")
|
opts.Month = start.Format("0601")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue