Ruby filter "LogStash::ConfigurationError"

Hi Guys, got a config setup as below to receive snmp walks result and I a script to clean the data.
However it fails to run because of an error on the ruby filter. I have tried my script on the output on irb and the script runs fin. Below is just a basic part of the script. Any idea what I could be doing wrong?

input {
        walk =>[""]
        hosts => [{XXXX}]
filter {
    ruby {
     code => " do |k,v|
              newkey = k.to_s.gsub!("","")
output {
        stdout { codec => rubydebug}
            hosts => [""]
            index => "snmp_walk"

What is the error?

Error is

Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of #, {, } at line 12, column 38 (byte 316) after filter {\r\n ruby {\r\n code => "\r\n

You are using double quotes in your gsub, I suggest you use single quotes to surround the code. Does the error change if you do that?

Yes you are right the double quotes are a problem. I now get the a different error. But I believe is now is about how I handle the output of the walk. without filter I will normally get below result stored.

      "": "OK",
      "": 0,
      "": 2,
      "": 0,
      "": "",
      "": "",
      "": 1,
      "": "Off Battery",
      "": 0,
      "": 2,
      "": 0,
      "": "Stopped",
      "": 0,

What does the "event" refers to generally? I saw that's what been used in most examples

You should use gsub, not gsub!. For fields like host using gsub! will result in you trying to event.set(nil, ...), which is not what you want.

What an event contains depends on the input. For a file input it is by default one line of a file. For an snmp input which is walking a MIB it is all of the objects that were returned when the input polled the target.

1 Like

Thanks a lot Badger. Couldn't have been explained any better :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.