updated messaging system, removed cache
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-01-16 01:01:14 +01:00
parent 4bada1c166
commit 698510b19a
3 changed files with 18 additions and 8 deletions

View File

@ -10,14 +10,13 @@ import (
"git.paulbsd.com/paulbsd/ipbl/src/models"
_ "github.com/lib/pq"
"xorm.io/xorm"
"xorm.io/xorm/caches"
"xorm.io/xorm/dialects"
"xorm.io/xorm/names"
)
func Initialize(ctx *context.Context, cfg *config.Config) (err error) {
var databaseEngine = "postgres"
cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 1000)
//cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 10)
cfg.Db, err = xorm.NewEngine(databaseEngine,
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.ShowSQL(cfg.Switchs.Debug)
cfg.Db.SetDefaultCacher(cacher)
//cfg.Db.SetDefaultCacher(cacher)
if cfg.Switchs.Drop {
log.Println("Dropping tables")

View File

@ -47,18 +47,19 @@ type Event struct {
ID int `xorm:"pk autoincr"`
Src string `xorm:"text notnull"`
Hostname sql.NullString `xorm:"text default NULL"`
Mode sql.NullString `xorm:"text default NULL"`
IP *IP `xorm:"int ip_id"`
Created time.Time `xorm:"created notnull"`
}
type APIEvent struct {
MsgType string `json:"msgtype"`
Mode string `json:"mode"`
Hostname string `json:"hostname"`
IPData struct {
IP string `json:"ip"`
Src string `json:"src"`
Hostname string `json:"hostname"`
Mode string `json:"mode"`
Date string `json:"date"`
Created string `json:"created"`
} `json:"ipdata"`
}

View File

@ -55,7 +55,7 @@ func Handle(cfg *config.Config, reqsock *goczmq.Sock, pubsock *goczmq.Sock, chan
continue
}
if apievent.MsgType != "init" {
if apievent.MsgType == "add" {
session := cfg.Db.NewSession()
event.APIParse(session, apievent)
session.Close()
@ -66,6 +66,16 @@ func Handle(cfg *config.Config, reqsock *goczmq.Sock, pubsock *goczmq.Sock, chan
}
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))
ipjson := []byte(tmpval)
topub = append(topub, ipjson)