updated messaging system, removed cache
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4bada1c166
commit
698510b19a
@ -10,14 +10,13 @@ import (
|
|||||||
"git.paulbsd.com/paulbsd/ipbl/src/models"
|
"git.paulbsd.com/paulbsd/ipbl/src/models"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
"xorm.io/xorm/caches"
|
|
||||||
"xorm.io/xorm/dialects"
|
"xorm.io/xorm/dialects"
|
||||||
"xorm.io/xorm/names"
|
"xorm.io/xorm/names"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Initialize(ctx *context.Context, cfg *config.Config) (err error) {
|
func Initialize(ctx *context.Context, cfg *config.Config) (err error) {
|
||||||
var databaseEngine = "postgres"
|
var databaseEngine = "postgres"
|
||||||
cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 1000)
|
//cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 10)
|
||||||
|
|
||||||
cfg.Db, err = xorm.NewEngine(databaseEngine,
|
cfg.Db, err = xorm.NewEngine(databaseEngine,
|
||||||
fmt.Sprintf("%s://%s:%s@%s/%s",
|
fmt.Sprintf("%s://%s:%s@%s/%s",
|
||||||
@ -33,7 +32,7 @@ func Initialize(ctx *context.Context, cfg *config.Config) (err error) {
|
|||||||
cfg.Db.SetQuotePolicy(dialects.QuotePolicyReserved)
|
cfg.Db.SetQuotePolicy(dialects.QuotePolicyReserved)
|
||||||
cfg.Db.ShowSQL(cfg.Switchs.Debug)
|
cfg.Db.ShowSQL(cfg.Switchs.Debug)
|
||||||
|
|
||||||
cfg.Db.SetDefaultCacher(cacher)
|
//cfg.Db.SetDefaultCacher(cacher)
|
||||||
|
|
||||||
if cfg.Switchs.Drop {
|
if cfg.Switchs.Drop {
|
||||||
log.Println("Dropping tables")
|
log.Println("Dropping tables")
|
||||||
|
@ -47,18 +47,19 @@ type Event struct {
|
|||||||
ID int `xorm:"pk autoincr"`
|
ID int `xorm:"pk autoincr"`
|
||||||
Src string `xorm:"text notnull"`
|
Src string `xorm:"text notnull"`
|
||||||
Hostname sql.NullString `xorm:"text default NULL"`
|
Hostname sql.NullString `xorm:"text default NULL"`
|
||||||
Mode sql.NullString `xorm:"text default NULL"`
|
|
||||||
IP *IP `xorm:"int ip_id"`
|
IP *IP `xorm:"int ip_id"`
|
||||||
Created time.Time `xorm:"created notnull"`
|
Created time.Time `xorm:"created notnull"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type APIEvent struct {
|
type APIEvent struct {
|
||||||
MsgType string `json:"msgtype"`
|
MsgType string `json:"msgtype"`
|
||||||
IPData struct {
|
Mode string `json:"mode"`
|
||||||
|
Hostname string `json:"hostname"`
|
||||||
|
IPData struct {
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
Src string `json:"src"`
|
Src string `json:"src"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
Mode string `json:"mode"`
|
Date string `json:"date"`
|
||||||
Created string `json:"created"`
|
Created string `json:"created"`
|
||||||
} `json:"ipdata"`
|
} `json:"ipdata"`
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ func Handle(cfg *config.Config, reqsock *goczmq.Sock, pubsock *goczmq.Sock, chan
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if apievent.MsgType != "init" {
|
if apievent.MsgType == "add" {
|
||||||
session := cfg.Db.NewSession()
|
session := cfg.Db.NewSession()
|
||||||
event.APIParse(session, apievent)
|
event.APIParse(session, apievent)
|
||||||
session.Close()
|
session.Close()
|
||||||
@ -66,6 +66,16 @@ func Handle(cfg *config.Config, reqsock *goczmq.Sock, pubsock *goczmq.Sock, chan
|
|||||||
}
|
}
|
||||||
log.Printf("zmq: Inserted event")
|
log.Printf("zmq: Inserted event")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if apievent.MsgType == "file" {
|
||||||
|
apievent.MsgType = "zmq"
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err = json.Marshal(apievent)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
tmpval := fmt.Sprintf("%s %s", channel, string(val))
|
tmpval := fmt.Sprintf("%s %s", channel, string(val))
|
||||||
ipjson := []byte(tmpval)
|
ipjson := []byte(tmpval)
|
||||||
topub = append(topub, ipjson)
|
topub = append(topub, ipjson)
|
||||||
|
Loading…
Reference in New Issue
Block a user