added 'log' output table to lua filter
This commit is contained in:
parent
c1b8a1055e
commit
3a10812036
3 changed files with 28 additions and 1 deletions
10
scraping.go
10
scraping.go
|
@ -811,8 +811,13 @@ func getFilterResultLua(filter *Filter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
L.SetGlobal("inputs", inputs)
|
L.SetGlobal("inputs", inputs)
|
||||||
|
|
||||||
outputs := L.CreateTable(10, 0)
|
outputs := L.CreateTable(10, 0)
|
||||||
L.SetGlobal("outputs", outputs)
|
L.SetGlobal("outputs", outputs)
|
||||||
|
|
||||||
|
logs := L.CreateTable(10, 0)
|
||||||
|
L.SetGlobal("logs", logs)
|
||||||
|
|
||||||
err := L.DoString(filter.Var1)
|
err := L.DoString(filter.Var1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
filter.log(err)
|
filter.log(err)
|
||||||
|
@ -823,4 +828,9 @@ func getFilterResultLua(filter *Filter) {
|
||||||
filter.Results = append(filter.Results, value.String())
|
filter.Results = append(filter.Results, value.String())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
logs.ForEach(
|
||||||
|
func(key lua.LValue, value lua.LValue) {
|
||||||
|
filter.Logs = append(filter.Logs, value.String())
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1217,3 +1217,21 @@ if not(result==true) then error("regexp.match()") end`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFilterLuaLogs(t *testing.T) {
|
||||||
|
script := `table.insert(logs, "test")`
|
||||||
|
|
||||||
|
filter := Filter{
|
||||||
|
Var1: script,
|
||||||
|
}
|
||||||
|
|
||||||
|
getFilterResultLua(&filter)
|
||||||
|
|
||||||
|
if len(filter.Logs) == 0 {
|
||||||
|
t.Error("Nothing in logs, expected 'test'")
|
||||||
|
}
|
||||||
|
|
||||||
|
if filter.Logs[0] != "test" {
|
||||||
|
t.Errorf("Unexpected log message: '%s'", filter.Logs[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -1,5 +1,4 @@
|
||||||
# Todo
|
# Todo
|
||||||
- add logs table to lua filter
|
|
||||||
- make generic 'notifier' interface
|
- make generic 'notifier' interface
|
||||||
- notify filter var2 for specific notifier or 'all'
|
- notify filter var2 for specific notifier or 'all'
|
||||||
- telegram
|
- telegram
|
||||||
|
|
Loading…
Add table
Reference in a new issue