Thanks for your great support!
You are right: the Severity variable was dropped by a previous sandbox
filter which omitted to set Severity in the injected message:

    [...]
    inject_message({
        Type = type_output,
        Timestamp = read_message('Timestamp'),
        Fields = data
    })

So to prevent this kind of neglecting in my lua sandboxes, I was wondering
if I could only mutate some fields of an existing message instead of
injecting a completely new message.
Reading the sandbox documentation, it seems the "write_message" api
function is the way to go:
https://hekad.readthedocs.org/en/latest/sandbox/#write-message

But when I try to use it instead of inject_message, I get the following
error:
"filters/encode_event.lua:31: attempt to call global 'write_message' (a nil
value)"

Reading Heka source code, write_message seems to be used only in the tests,
so it may not be available outside testing.
I think it would be useful to have this kind of api function available in
the sandbox, or a function that would copy the current message to a lua
table which can then be modified and reinjected later as a new message with
the inject_message function.

What do you think?

Cheers,
Bruno

On 17 March 2015 at 21:12, Rob Miller <[email protected]> wrote:

> This does look correct, yes, although it's a bit more idiomatic in Lua to
> use `if not severity` instead of `if severity == nil`. That's not going to
> cause your problem, though.
>
> I just tested this by expanding your code slightly:
> https://rmiller.pastebin.mozilla.org/8826150
>
> I used this config: https://rmiller.pastebin.mozilla.org/8826149
>
> That's parsing nginx log files, extracting severity (along w/ lots of
> other data), using the filter to keep a running total of severity values
> (absurd, but an effective sanity check), and writing that ongoing total out
> to stdout. It's working as expected, and I'm not seeing any of the
> "severity can't be nil" errors.
>
> My guess is that you think your messages have a severity set, but they
> don't. How are your messages being generated? Can you try using a LogOutput
> and RstEncoder to catch the same messages and verify that severity is in
> fact set?
>
> Thanks,
>
> -r
>
>
>
> On 03/17/2015 10:35 AM, bruno binet wrote:
>
>> In a lua sandbox filter, I'd like to get the value of the "Severity"
>> message variable, but in the "process_message" function if I do:
>>
>>      local severity = read_message("Severity")
>>      if severity == nil then
>>          return -1, "severity can't be nil"
>>      end
>>
>> when a message is processed by the sandbox, it always returns "severity
>> can't be nil" whereas the message Severity was set to 5.
>>
>> Is "read_message" the right function to use to read the message Severity?
>>
>> Thanks.
>> Bruno
>>
>>
>> _______________________________________________
>> Heka mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/heka
>>
>>
>
_______________________________________________
Heka mailing list
[email protected]
https://mail.mozilla.org/listinfo/heka

Reply via email to