Error connecting Logstash to PostgresSQL Database

Hello guys,

I'm trying to connect Logstash to a PostgresSQL database, but every time I run the pipeline, I'm getting the error Unable to configure plugins: (ArgumentError) Cannot determine timezone from nil .
I've tried some things that I found in this community, but none have worked. I think that the problem is because the timestamp is returning in nanosecond, but I'm not sure about this and nor how to solve this problem.

Here folows the pipeline

input{
    jdbc{
        jdbc_driver_library => "C:\RPA\jdbc\postgresql-42.6.0.jar"
        jdbc_driver_class => "org.postgresql.Driver"
        jdbc_connection_string => "jdbc:postgresql://<url>:<port>/<database>"
        jdbc_user => "<usr>"
        jdbc_password => "<password>"
        statement => "<sql>"
        schedule => "*/1 * * * *"
    }
}
filter{
    mutate{
   	add_field => {
            ddtags => "env:prd"
            ddsource => "rpa"
            "timestamp_zoned" => "%{@timestamp}"
        }
    }
    date {
        # Parse UTC string value and convert it to my timezone into a new field
        match => [ "timestamp_zoned", "yyyy-MM-dd HH:mm:ss Z" ]
        timezone => "America/New_York"
        remove_field => [ "timestamp_zoned" ]
        target => "timestamp_zoned_obj"
    }

    ruby {
        # Output the zoned date to a new field
        code => "event['index_day'] = event['timestamp_zoned_obj'].strftime('%Y.%m.%d')"
        remove_field => [ "timestamp_zoned_obj" ]
    }

}
output{
    stdout { }
}

And here follows the stack trace error that I'm receiving

:\Program Files\logstash-8.6.2\bin>.\logstash.bat -f "C:\Program Files\logstash-8.6.2\config\Pipeline\RPA.conf"
"Using bundled JDK: C:\Program Files\logstash-8.6.2\jdk\bin\java.exe"
Sending Logstash logs to C:/Program Files/logstash-8.6.2/logs which is now configured via log4j2.properties
[2023-04-27T17:13:41,778][INFO ][logstash.runner          ] Log4j configuration path used is: C:\Program Files\logstash-8.6.2\config\log4j2.properties
[2023-04-27T17:13:41,778][WARN ][logstash.runner          ] The use of JAVA_HOME has been deprecated. Logstash 8.0 and later ignores JAVA_HOME and uses the bundled JDK. Running Logstash with the bundled JDK is recommended. The bundled JDK has been verified to work with each specific version of Logstash, and generally provides best performance and reliability. If you have compelling reasons for using your own JDK (organizational-specific compliance requirements, for example), you can configure LS_JAVA_HOME to use that version instead.
[2023-04-27T17:13:41,793][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"8.6.2", "jruby.version"=>"jruby 9.3.10.0 (2.6.8) 2023-02-01 107b2e6697 OpenJDK 64-Bit Server VM 17.0.6+10 on 17.0.6+10 +indy +jit [x86_64-mswin32]"}
[2023-04-27T17:13:41,793][INFO ][logstash.runner          ] JVM bootstrap flags: [-Xms1g, -Xmx1g, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djruby.compile.invokedynamic=true, -XX:+HeapDumpOnOutOfMemoryError, -Djava.security.egd=file:/dev/urandom, -Dlog4j2.isThreadContextMapInheritable=true, -Djruby.regexp.interruptible=true, -Djdk.io.File.enableADS=true, --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED, --add-opens=java.base/java.security=ALL-UNNAMED, --add-opens=java.base/java.io=ALL-UNNAMED, --add-opens=java.base/java.nio.channels=ALL-UNNAMED, --add-opens=java.base/sun.nio.ch=ALL-UNNAMED, --add-opens=java.management/sun.management=ALL-UNNAMED]
[2023-04-27T17:13:41,860][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2023-04-27T17:13:43,810][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600, :ssl_enabled=>false}
[2023-04-27T17:13:44,052][INFO ][org.reflections.Reflections] Reflections took 245 ms to scan 1 urls, producing 127 keys and 444 values
[2023-04-27T17:13:48,374][ERROR][logstash.agent           ] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"Java::JavaLang::IllegalStateException", :message=>"Unable to configure plugins: (ArgumentError) Cannot determine timezone from nil\n(secs:1682626424.939,utc~:\"2023-04-27 20:13:44.9389998912811279\",ltz~:nil)\n(etz:nil,tnz:\"BRT\",tziv:\"2.0.6\",tzidv:\"1.2022.7\",rv:\"2.6.8\",rp:\"java\",win:true,rorv:nil,astz:nil,eov:\"1.2.7\",eotnz:\"???\",eotnfz:\"???\",eotlzn:\"???\",\ndebian:nil,centos:nil,osx:nil)\nTry setting `ENV['TZ'] = 'Continent/City'` in your script (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)", :backtrace=>["org.logstash.config.ir.CompiledPipeline.<init>(CompiledPipeline.java:120)", "org.logstash.execution.AbstractPipelineExt.initialize(AbstractPipelineExt.java:181)", "org.logstash.execution.AbstractPipelineExt$INVOKER$i$initialize.call(AbstractPipelineExt$INVOKER$i$initialize.gen)", "org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:846)", "org.jruby.ir.runtime.IRRuntimeHelpers.instanceSuper(IRRuntimeHelpers.java:1229)", "org.jruby.ir.instructions.InstanceSuperInstr.interpret(InstanceSuperInstr.java:131)", "org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:361)", "org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:72)", "org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:128)", "org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:115)", "org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:329)", "org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:87)", "org.jruby.RubyClass.newInstance(RubyClass.java:911)", "org.jruby.RubyClass$INVOKER$i$newInstance.call(RubyClass$INVOKER$i$newInstance.gen)", "org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:329)", "org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:87)", "org.jruby.ir.instructions.CallBase.interpret(CallBase.java:549)", "org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:361)", "org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:72)", "org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:92)", "org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:238)", "org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:225)", "org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:226)", "org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:393)", "org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:206)", "org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:325)", "org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:72)", "org.jruby.ir.interpreter.Interpreter.INTERPRET_BLOCK(Interpreter.java:116)", "org.jruby.runtime.MixedModeIRBlockBody.commonYieldPath(MixedModeIRBlockBody.java:136)", "org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:66)", "org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:58)", "org.jruby.runtime.Block.call(Block.java:143)", "org.jruby.RubyProc.call(RubyProc.java:309)", "org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:107)", "java.base/java.lang.Thread.run(Thread.java:833)"]}
[2023-04-27T17:13:48,413][INFO ][logstash.runner          ] Logstash shut down.
[2023-04-27T17:13:48,418][FATAL][org.logstash.Logstash    ] Logstash stopped processing because of an error: (SystemExit) exit
org.jruby.exceptions.SystemExit: (SystemExit) exit
        at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:790) ~[jruby.jar:?]
        at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:753) ~[jruby.jar:?]
        at C_3a_.Program_20_Files.logstash_minus_8_dot_6_dot_2.lib.bootstrap.environment.<main>(C:\Program Files\logstash-8.6.2\lib\bootstrap\environment.rb:91) ~[?:?]

Hi @vineasouza,

Thanks for providing the stack trace, that really helps. So all the errors are happening in jruby so my hunch is the issue is with the ruby block in your pipeline. Also, the date filter can be tricky because: "The date filter is used for parsing dates from fields, and then using that date or timestamp as the logstash timestamp for the event." It looks like you aren't really wanting to "use that date or timestamp as the logstash timestamp for the event". Rather it looks like you want to parse the date. It's tripped me up before as well, but could be off base on exactly what you are trying to do. Having said that try using this filter instead:

filter{
    mutate{
   	add_field => {
            ddtags => "env:prd"
            ddsource => "rpa"
            "timestamp_zoned" => "%{@timestamp}"
        }
    }
    ruby {
        # Output the zoned date to a new field
        code => "event['index_day'] = Date.strptime(event['timestamp_zoned'],'%Y.%m.%d')"
        remove_field => [ "timestamp_zoned" ]
    }

}

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