1
0
Fork 0
forked from boyska/circolog

Translate the keywords for the QL.

This commit is contained in:
Blallo 2019-01-09 16:39:06 +01:00
parent c1ae059712
commit 05f9e0f1d1
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F

View file

@ -39,10 +39,12 @@ func (e *ExprValue) Set(value string) error {
return nil
}
func (e *ExprValue) Validate(line map[string]interface{}) bool {
// Validate answers the question wether to include a log line or not.
func (e *ExprValue) Validate(lineInput map[string]interface{}) bool {
if e.node == nil {
return true
}
line := translateMap(lineInput)
context := datasource.NewContextSimpleNative(line)
val, ok := vm.Eval(context, e.node)
if !ok || val == nil { // errors when evaluating
@ -54,3 +56,14 @@ func (e *ExprValue) Validate(line map[string]interface{}) bool {
fmt.Fprintln(os.Stderr, "WARNING: The 'where' expression doesn't return a boolean")
return false
}
func translateMap(lineInput map[string]interface{}) map[string]interface{} {
lineOutput := make(map[string]interface{})
lineOutput["prog"] = lineInput["app_name"]
lineOutput["msg"] = lineInput["message"]
lineOutput["facility"] = lineInput["facility"]
lineOutput["host"] = lineInput["hostname"]
lineOutput["time"] = lineInput["timestamp"]
lineOutput["sev"] = lineInput["severity"]
return lineOutput
}