chg: [sshd] HTML compiler logic

nifi
Jean-Louis Huynen 2020-01-28 15:20:09 +01:00
parent 75a917b6b8
commit ebb2911277
No known key found for this signature in database
GPG Key ID: 64799157F4BD6B93
1 changed files with 38 additions and 7 deletions

45
main.go
View File

@ -8,6 +8,7 @@ import (
"os/signal"
"strconv"
"strings"
"sync"
"time"
"bufio"
@ -33,16 +34,23 @@ type (
httpHost string
httpPort string
}
comutex struct {
mu sync.Mutex
compiling bool
}
)
// Setting up flags
var (
confdir = flag.String("c", "conf.sample", "configuration directory")
all = flag.Bool("a", true, "run all parsers when set. Set by default")
specific = flag.String("o", "", "run only a specific parser [sshd]")
redisD4 redis.Conn
redisParsers *redis.Pool
parsers = [1]string{"sshd"}
confdir = flag.String("c", "conf.sample", "configuration directory")
all = flag.Bool("a", true, "run all parsers when set. Set by default")
specific = flag.String("o", "", "run only a specific parser [sshd]")
redisD4 redis.Conn
redisParsers *redis.Pool
parsers = [1]string{"sshd"}
compilationTrigger = 10
wg sync.WaitGroup
compiling comutex
)
func main() {
@ -135,6 +143,9 @@ func main() {
// Create a connection Pool
redisParsers = newPool(rp.redisHost+":"+rp.redisPort, rp.redisDBCount)
// Line counter to trigger HTML compilation
nblines := 0
var torun = []logparser.Parser{}
// Init parser depending on the parser flags:
if *all {
@ -185,12 +196,32 @@ func main() {
log.Fatal(err)
}
}
nblines++
if nblines > compilationTrigger {
nblines = 0
// Non-blocking
if !compiling.compiling {
go compile()
}
}
}
wg.Wait()
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 {
return &redis.Pool{
MaxActive: maxconn,