I need some help in testing this. Below is the logstash config file[logstash-6.5.4/config/logstash-sample-4.conf]. I would like to feed the logstash with elasticsearch logs, which runs on port 9200.
input {
tcp {
type => "logs"
codec => "json"
port => 9200
}
file {
path => "/var/log/system.log"
type => "syslog"
}
}
output {
if [type]=="syslog" {
elasticsearch {
hosts => [ "localhost:9200" ]
index => "syslog-debug-%{+YYYY.MM.dd}"
}
}
else if [type]=="logs" {
elasticsearch {
hosts => [ "localhost:9200" ]
index => "elasticlogs-debug-%{+YYYY.MM.dd}"
stdout {
codec => rubydebug
}
}
}
else {
elasticsearch {
hosts => [ "localhost:9200" ]
index => "logs-debug-%{+YYYY.MM.dd}"
}
}
}
Ran logstash with logstash -f <logstash_file>
But it is failing.
[2019-04-02T13:23:07,899][ERROR][logstash.agent ] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of #, => at line 25, column 15 (byte 493) after output {\n if [type]==\"syslog\" {\n elasticsearch {\n hosts => [ \"localhost:9200\" ]\n index => \"syslog-debug-%{+YYYY.MM.dd}\"\n }\n } \n else if [type]==\"logs\" {\n elasticsearch {\n hosts => [ \"localhost:9200\" ]\n index => \"elasticlogs-debug-%{+YYYY.MM.dd}\"\n stdout ", :backtrace=>["/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/compiler.rb:41:in `compile_imperative'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/compiler.rb:49:in `compile_graph'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/compiler.rb:11:in `block in compile_sources'", "org/jruby/RubyArray.java:2486:in `map'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/compiler.rb:10:in `compile_sources'", "org/logstash/execution/AbstractPipelineExt.java:149:in `initialize'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/pipeline.rb:22:in `initialize'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/pipeline.rb:90:in `initialize'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/pipeline_action/create.rb:42:in `block in execute'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/agent.rb:92:in `block in exclusive'", "org/jruby/ext/thread/Mutex.java:148:in `synchronize'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/agent.rb:92:in `exclusive'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/pipeline_action/create.rb:38:in `execute'", "/Users/mouliveera/Desktop/tools/logstash-6.5.4/logstash-core/lib/logstash/agent.rb:317:in `block in converge_state'"]}
I tried with apache port 80 as well. I see the similar behaviour. Can someone help me in fixing it.
Thanks
First, with the above config you would have both Logstash and Elasticsearch listening on port 9200 on localhost. That will not work. I would let Elasticsearch use its default port 9200 and set Logastash to use some other non standard port. E.g. I use ports 551X for Logstash inputs.
Second, Elsticsearch doesn't push logs that Logstash could just receive on a port. I use Filebeat to tail the Elasticsearch log files and ship Elasticsearch logs to Logstash.
Then, for the Logstash error message which says
Expected one of #, => at line 25
You have to close the elasticsearch output config before you define the stdout output.
I would not recommend using well known or common ports as ports for Logstash inputs.
Again, Logstash is not pulling any logs from e.g. Apache. Unless you setup some sort of log shipper the webserver logs are written to a file on the filesystem where the webserver process runs. Containers is a slightly different story but even there you would probably have to tail a log file on disk at some stage of the log export.
For a Logstash TCP input that excepts JSON to work the way you want, you have to have something that actually sends those messages as JSON to the desired port on the machine where Logstash runs.
You can test this with netcat. The below is a bash example for a UDP input.
You can't directly do that. As you describe it above, the port for the service is a listening port. It is not sending anything to Logstash.
The same way as you have Logstash reading a local log file in your config above, you can have Filebeat reading a log file on another systems and send it to Logstash.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.