chg: [sshd] HTML compiler logic
parent
75a917b6b8
commit
ebb2911277
45
main.go
45
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"bufio"
|
"bufio"
|
||||||
|
@ -33,16 +34,23 @@ type (
|
||||||
httpHost string
|
httpHost string
|
||||||
httpPort string
|
httpPort string
|
||||||
}
|
}
|
||||||
|
comutex struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
compiling bool
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Setting up flags
|
// Setting up flags
|
||||||
var (
|
var (
|
||||||
confdir = flag.String("c", "conf.sample", "configuration directory")
|
confdir = flag.String("c", "conf.sample", "configuration directory")
|
||||||
all = flag.Bool("a", true, "run all parsers when set. Set by default")
|
all = flag.Bool("a", true, "run all parsers when set. Set by default")
|
||||||
specific = flag.String("o", "", "run only a specific parser [sshd]")
|
specific = flag.String("o", "", "run only a specific parser [sshd]")
|
||||||
redisD4 redis.Conn
|
redisD4 redis.Conn
|
||||||
redisParsers *redis.Pool
|
redisParsers *redis.Pool
|
||||||
parsers = [1]string{"sshd"}
|
parsers = [1]string{"sshd"}
|
||||||
|
compilationTrigger = 10
|
||||||
|
wg sync.WaitGroup
|
||||||
|
compiling comutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -135,6 +143,9 @@ func main() {
|
||||||
// Create a connection Pool
|
// Create a connection Pool
|
||||||
redisParsers = newPool(rp.redisHost+":"+rp.redisPort, rp.redisDBCount)
|
redisParsers = newPool(rp.redisHost+":"+rp.redisPort, rp.redisDBCount)
|
||||||
|
|
||||||
|
// Line counter to trigger HTML compilation
|
||||||
|
nblines := 0
|
||||||
|
|
||||||
var torun = []logparser.Parser{}
|
var torun = []logparser.Parser{}
|
||||||
// Init parser depending on the parser flags:
|
// Init parser depending on the parser flags:
|
||||||
if *all {
|
if *all {
|
||||||
|
@ -185,12 +196,32 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
nblines++
|
||||||
|
if nblines > compilationTrigger {
|
||||||
|
nblines = 0
|
||||||
|
// Non-blocking
|
||||||
|
if !compiling.compiling {
|
||||||
|
go compile()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
log.Println("Exit")
|
log.Println("Exit")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func compile() {
|
||||||
|
compiling.mu.Lock()
|
||||||
|
compiling.compiling = true
|
||||||
|
wg.Add(1)
|
||||||
|
log.Println("I should probably be writing")
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
log.Println("Writing")
|
||||||
|
compiling.compiling = false
|
||||||
|
compiling.mu.Unlock()
|
||||||
|
wg.Done()
|
||||||
|
}
|
||||||
|
|
||||||
func newPool(addr string, maxconn int) *redis.Pool {
|
func newPool(addr string, maxconn int) *redis.Pool {
|
||||||
return &redis.Pool{
|
return &redis.Pool{
|
||||||
MaxActive: maxconn,
|
MaxActive: maxconn,
|
||||||
|
|
Loading…
Reference in New Issue