Error with ruby filter plugin


#1

I am receiving errors I can't solve, since my config seems correct to me. It is complaining about the use of the ruby filter plugin, but the ruby code is valid.

input {
  beats {
    port => 5443
  }
}

filter {
  ruby {
    code => "event.set('filename', event.get('source').split('/').last" 
  }

  mutate {
    lowercase => [ "filename" ]
  }

  if "checked" not in [tags] {
    grok {
      remove_tag => ["_grokparsefailure"]
      patterns_dir => ["/REDACTED/patterns.d"]
      match => [
          "message", '^"\s*%{OXFolge:folge}\s*%{OXFolge:folge2} \s*%{OXProg:programm}\s*%{OXBezeich:bezeichnung}\s*%{TIME:start_time:date}\s*%{TIME:end_time:date}\s*%{OXDuration:duration}\s*%{OXStatus:status}\s*"$'
      ]
      add_tag => ["logline", "checked"]
    }

    if "_grokparsefailure" not in [tags] {
      elasticsearch {
        hosts => ["http://localhost:9200"]
        index => "ox-%{filename}-%{+YYYY.MM.dd}"
        query => "tags:2headline"
        fields => { "job_timestamp" => "_datestamp" }
      }

      ruby {
        code => "
        d = event.get('_datestamp')
        t = event.get('start_time')
        f = d+'-'+t
        event.set('_timestamp', f)
        "
      }

      date {
        match => [ "_timestamp", "dd.MM.yyyy-HH:mm:ss" ]
        target => "logstamp"
      }
    }

  }

  if "checked" not in [tags] {
    grok {
      remove_tag => ["_grokparsefailure"]
      patterns_dir => ["/REDACTED/patterns.d"]
      match => [
          "message", '^"\s*%{WORD:dunno1}\s*%{NUMBER:dunno2}\s*%{GREEDYDATA:branch}\s*Abschlussinformationen / %{USERNAME:dunno3}\s*%{WORD:dunno4}\s*%{OXDuration:timestamp2}\s*%{WORD:dunno6}\s*%{OXDuration:timestamp3}\s*Seite\s*%{OXPage:page}\s*"$'
      ]
      add_tag => ["headline", "checked"]
    }
  }

  if "checked" not in [tags] {
    grok {
      remove_tag => ["_grokparsefailure"]
      patterns_dir => ["/REDACTED/patterns.d"]
      match => [
          "message", '^"\s*Angefordert durch\s*:\s*%{OXRunUser:run_user}\s*Abschlussjob.*:\s*%{OXAbscJob:job_data}\s*%{DATE_EU:job_timestamp}\s*%{BASE10NUM:nr}\s*"$'
      ]
      add_tag => ["2headline", "checked"]
    }
  }
}

output {
  stdout {}
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "ox-%{filename}-%{+YYYY.MM.dd}"
  }
}

And here is the stacktrace:
Sending Logstash logs to /REDACTED/Desktop/ which is now configured via log4j2.properties
[2018-11-25T05:38:03,137][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2018-11-25T05:38:03,155][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"6.5.0"}
[2018-11-25T05:38:08,968][INFO ][logstash.pipeline ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2018-11-25T05:38:09,322][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>, :added=>[http://localhost:9200/]}}
[2018-11-25T05:38:09,329][INFO ][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://localhost:9200/, :path=>"/"}
[2018-11-25T05:38:09,583][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://localhost:9200/"}
[2018-11-25T05:38:09,633][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
[2018-11-25T05:38:09,637][WARN ][logstash.outputs.elasticsearch] Detected a 6.x and above cluster: the type event field won't be used to determine the document _type {:es_version=>6}
[2018-11-25T05:38:09,661][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["http://localhost:9200"]}
[2018-11-25T05:38:09,679][INFO ][logstash.outputs.elasticsearch] Using mapping template from {:path=>nil}
[2018-11-25T05:38:09,702][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"default"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
[2018-11-25T05:38:09,710][ERROR][logstash.agent ] Failed to execute action {:id=>:main, :action_type=>LogStash::ConvergeResult::FailedAction, :message=>"Could not execute action: PipelineAction::Create, action_result: false", :backtrace=>nil}
[2018-11-25T05:38:09,839][ERROR][org.logstash.Logstash ] java.lang.IllegalStateException: Logstash stopped processing because of an error: (SyntaxError) (ruby filter code):3: syntax error, unexpected kEND

I am really out of ideas


(Paris Mermigkas) #2

You're missing an event.set closing parenthesis after .last .This should work fine.

ruby {
  code => "event.set('filename', event.get('source').split('/').last)" 
}