Hi evryone
i tried o use ruby filter to calculate 3 new fields:
The first is the total number of observation in may table.
the second id the number of observations where(Contrainte>=-78),Contrainte is a field in my csv file.
The third is the percentage of compliant observations.
Unfortuntally it doesn't work.
This is my logstash config file:
input{
file{
path => "C:/Users/Asus/Dropbox/PFE_part2/moov_dogbo_2g.csv"
start_position => "beginning"
sincedb_path => "NUL"
codec => plain { charset => "CP1252" }
}
}
filter{
csv {
separator => ","
columns => [ "Message",
"Time",
"Distance",
"Longitude",
"Latitude",
"ServRxLevIdle"
]
convert => {
"Longitude" => "float"
"Latitude" => "float"
"ServRxLevIdle" => "float"
}
}
mutate { rename => ["ServRxLevIdle", Contrainte] }
mutate { add_field => { "Location" => ["%{[Latitude]}","%{[Longitude]}"] } }
mutate { convert=> ["Location", "float"] }
date { match => [ "time", "dd MMM yy HH:mm:ss" ] }
ruby { code => 'event.set("[total_observation_number]", event.get("Message").count())'} #total number of observation
if(["Contrainte"] >= -78){
ruby { code =>'event.set("[observation_compliant]", event.get("Message").count())'} #number of compliant observation
}
ruby{ code => 'event.set("[percentage]", [event.get("[observation_compliant]") / event.get("[total_observation_number]") ] * 100 )'}
}
output{
elasticsearch {
action => "index"
hosts => ["http://localhost:9200/"]
index => "friends"
}
stdout { codec => rubydebug }
}
And here is part of the error
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
warning: thread "[main]>worker2" terminated with exception (report_on_exception is true):
java.lang.IllegalStateException: java.lang.NullPointerException
at org.logstash.execution.WorkerLoop.run(org/logstash/execution/WorkerLoop.java:85)
at java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)
at org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:441)
at org.jruby.javasupport.JavaMethod.invokeDirect(org/jruby/javasupport/JavaMethod.java:305)
at C_3a_.elastic_stack.logstash_minus_7_dot_6_dot_2.logstash_minus_core.lib.logstash.java_pipeline.start_workers(C:/elastic_stack/logstash-7.6.2/logstash-core/lib/logstash/java_pipeline.rb:262)
at org.jruby.RubyProc.call(org/jruby/RubyProc.java:274)
at java.lang.Thread.run(java/lang/Thread.java:748)
Caused by: java.lang.NullPointerException
at org.logstash.config.ir.compiler.EventCondition$Compiler$UnexpectedTypeException.<init>(EventCondition.java:659)
at org.logstash.config.ir.compiler.EventCondition$Compiler.compare(EventCondition.java:433)
at org.logstash.config.ir.compiler.EventCondition$Compiler.lambda$compareFieldToConstant$11(EventCondition.java:424)
at org.logstash.config.ir.compiler.Utils.filterEvents(Utils.java:27)
at org.logstash.generated.CompiledDataset6.compute(Unknown Source)
at org.logstash.generated.CompiledDataset7.compute(Unknown Source)
at org.logstash.generated.CompiledDataset8.compute(Unknown Source)
at org.logstash.generated.CompiledDataset9.compute(Unknown Source)
at org.logstash.generated.CompiledDataset10.compute(Unknown Source)
at org.logstash.execution.WorkerLoop.run(WorkerLoop.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(JavaMethod.java:441)
at org.jruby.javasupport.JavaMethod.invokeDirect(JavaMethod.java:305)
at org.jruby.java.invokers.InstanceMethodInvoker.call(InstanceMethodInvoker.java:32)
at C_3a_.elastic_stack.logstash_minus_7_dot_6_dot_2.logstash_minus_core.lib.logstash.java_pipeline.RUBY$block$start_workers$5(C:/elastic_stack/logstash-7.6.2/logstash-core/lib/logstash/java_pipeline.rb:262)
at org.jruby.runtime.CompiledIRBlockBody.callDirect(CompiledIRBlockBody.java:136)
at org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:77)
at org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:71)
at org.jruby.runtime.Block.call(Block.java:125)
at org.jruby.RubyProc.call(RubyProc.java:274)
at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:105)
at java.lang.Thread.run(Thread.java:748)
[2020-06-15T17:31:48,834][FATAL][logstash.runner ] An unexpected error occurred! {:error=>java.lang.IllegalStateException: java.lang.NullPointerException, :backtrace=>["org.logstash.execution.WorkerLoop.run(org/logstash/execution/WorkerLoop.java:85)", "java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)", "org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:441)", "org.jruby.javasupport.JavaMethod.invokeDirect(org/jruby/javasupport/JavaMethod.java:305)", "C_3a_.elastic_stack.logstash_minus_7_dot_6_dot_2.logstash_minus_core.lib.logstash.java_pipeline.start_workers(C:/elastic_stack/logstash-7.6.2/logstash-core/lib/logstash/java_pipeline.rb:262)", "org.jruby.RubyProc.call(org/jruby/RubyProc.java:274)", "java.lang.Thread.run(java/lang/Thread.java:748)"]}
[2020-06-15T17:31:48,858][ERROR][org.logstash.Logstash ] java.lang.IllegalStateException: Logstash stopped processing because of an error: (SystemExit) exit
Can you help me?