forked from boyska/circolog
simple client-side sql filtering
This commit is contained in:
parent
20269bf94e
commit
8bb28d7a7c
1 changed files with 26 additions and 1 deletions
|
@ -12,17 +12,30 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.lattuga.net/boyska/circolog/formatter"
|
"git.lattuga.net/boyska/circolog/formatter"
|
||||||
|
"github.com/araddon/qlbridge/datasource"
|
||||||
|
"github.com/araddon/qlbridge/expr"
|
||||||
|
"github.com/araddon/qlbridge/value"
|
||||||
|
"github.com/araddon/qlbridge/vm"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"gopkg.in/mcuadros/go-syslog.v2/format"
|
"gopkg.in/mcuadros/go-syslog.v2/format"
|
||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: type ExpressionValue
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr := flag.String("addr", "localhost:9080", "http service address")
|
addr := flag.String("addr", "localhost:9080", "http service address")
|
||||||
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server")
|
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server")
|
||||||
backlogLimit := flag.Int("n", -1, "Limit the backlog length, defaults to no limit (-1)")
|
backlogLimit := flag.Int("n", -1, "Limit the backlog length, defaults to no limit (-1)")
|
||||||
|
filter := flag.String("where", "", "sql-like query to filter logs")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
filterExpr, err := expr.ParseExpression(*filter)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "invalid filter:", err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
signal.Notify(interrupt, os.Interrupt)
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
var d *websocket.Dialer
|
var d *websocket.Dialer
|
||||||
|
@ -69,7 +82,19 @@ func main() {
|
||||||
}
|
}
|
||||||
var parsed format.LogParts
|
var parsed format.LogParts
|
||||||
if err := bson.Unmarshal(serialized, &parsed); err != nil {
|
if err := bson.Unmarshal(serialized, &parsed); err != nil {
|
||||||
log.Println("invalid YAML", err)
|
log.Println("invalid BSON", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
context := datasource.NewContextSimpleNative(parsed)
|
||||||
|
val, ok := vm.Eval(context, filterExpr)
|
||||||
|
if !ok || val == nil { // errors when evaluating
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if val.Type() != value.BoolType {
|
||||||
|
fmt.Fprintln(os.Stderr, "WARNING: The expression doesn't return a boolean")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if val.Value().(bool) != true {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := formatter.WriteFormatted(os.Stdout, formatter.FormatSyslog, parsed); err != nil {
|
if err := formatter.WriteFormatted(os.Stdout, formatter.FormatSyslog, parsed); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue