input as file path in logstash config - elasticsearch

When I run a command like this(on a Windows System):
logstash agent -f logstash-simple.conf
When the logstash config file had input as stdin{} it gave the expected output but when the input was a path to the input file (file{path=>})
it didn't give any output.
Here is my config(logstash-simple.conf) file:
input {
file{
type=>"syslog"
path=>["C:/Users/Administrator/Downloads/syslog.txt"]
}
}
output {
stdout {
codec => rubydebug
}
}

If you have an existing file that you are looking to load, you'll need to add
start_postition => beginning
to your file input.

I had the same problem.
You should have an empty line at the end of the file!
that worked for me

Related

Unable to start Logstash server and throwing error

I want to pass log file as an input to a Logstash input. I have added /bin to the environment variable path so that I can access it from anywhere.
Below is my conf file:
logstash.conf
input{
path => "D:\nest\es-logging-example\log\info\info.log"
start_position => beginning
}
output{
elasticsearch{
hosts => ["localhost:9200"]
index => "indexforlogstash"
}
}
After running this using logstash -f "D:\nest\es-logging-example\logstash.conf" its showing below error in terminal.
`
[2022-03-15T16:14:49,851][ERROR][logstash.agent ] Failed to
execute action
{:action=>LogStash::PipelineAction::Create/pipeline_id:main,
:exception=>"LogStash::ConfigurationError", :message=>"Expected one of [
\\t\\r\\n], \"#\", \"{\" at line 2, column 11 (byte 19) after input{\r\n
path ", :backtrace=>["C:/logstash-8.1.0/logstash-
core/lib/logstash/compiler.rb:32:in `compile_imperative'",
"org/logstash/execution/AbstractPipelineExt.java:189:in `initialize'",
"org/logstash/execution/JavaBasePipelineExt.java:72:in `initialize'",
"C:/logstash-8.1.0/logstash-core/lib/logstash/java_pipeline.rb:47:in
`initialize'", "C:/logstash-8.1.0/logstash-
core/lib/logstash/pipeline_action/create.rb:50:in `execute'",
"C:/logstash-8.1.0/logstash-core/lib/logstash/agent.rb:376:in `block in
converge_state'"]}`
What is this error about?
I think your problem is that the \ is an escape character in the quoted string in your config file.
Can you change
path => "D:\nest\es-logging-example\log\info\info.log"
to
path => "D:\\nest\\es-logging-example\\log\\info\\info.log"
So the \ characters in the path are escaped.
There's no configuration found in C:\logstash-8.1.0\logstash.conf
Specify the absolute path where your logstash.cong file is located instead:
logstash -f "D:\\nest\\es-logging-example\\logstash.conf"
You also need to modify your config file as follows
path => "D:\\nest\\es-logging-example\\log\\info\\info.log"
Your configuration is wrong, you need to specify which input plugin you are using, which based on what you shared is the file input plugin.
Also, you need to use forward slashes.
Try the following:
input {
file {
path => "D:/nest/es-logging-example/log/info/info.log"
start_position => beginning
}
}

Trying to set logstash conf file in docker-compose.yml on Mac OS

Here is what I have specified in my yml for the logstash. I've tried multiple variations of quotes, no quotes, etc:
volumes:
- "./logstash:/etc/logstash/conf:ro"
command:
- "logstash -f /etc/logstash/conf/simplels.conf"
And simplels.conf contains this:
input {
stdin{}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
}
stdout{}
}
Overall file structure is this, I'm running docker-compose up from the docker folder and getting Exit 1 on the Logstash container due to my 'command' parameter:
/docker:
docker-compose.yml
/logstash
simplels.conf

logstash configuration to execute a command to elastic search

i am running an ELK stack in 3 docker containers through host machine ubuntu 16.04
the problem is after configuring the logstash.conf file to execute a command like "ifconfig" or "netstat -ano"i get an error. my logstash.conf file is:
input {
exec {
command => "netsat -ano"
codec => "json"
interval => 5
}
}
output{
elasticsearch { hosts => ["elasticsearch:9200"]}
}
i get this error after entering this command ( docker run -h logstash --name logstash --link elasticsearch:elasticsearch -it --rm -v "$PWD":/config-dir logstash -f /config-dir/logstash1.conf)
14:29:30.703 [[main]<exec] ERROR logstash.inputs.exec - Error while running command {:command=>"netsat -ano", :e=>#<IOError: Cannot run program "netsat" (in directory "/"): error=2, No such file or directory>, :backtrace=>["org/jruby/RubyIO.java:4380:in `popen'", "/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-exec-3.1.2/lib/logstash/inputs/exec.rb:76:in `execute'", "/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-exec-3.1.2/lib/logstash/inputs/exec.rb:75:in `execute'", "/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-exec-3.1.2/lib/logstash/inputs/exec.rb:40:in `inner_run'", "/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-exec-3.1.2/lib/logstash/inputs/exec.rb:34:in `run'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:443:in `inputworker'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:436:in `start_input'"]}
can anyone help please thanks in advance !
You will need to provide a full path for those commands, as the one Logstash runs with doesn't contain those directories.
input {
exec {
command => "/bin/netsat -ano"
codec => "json"
interval => 5
}
}

How to read /var/log/wtmp logs in elasticsearch

I am trying to read the access log s from /var/log/wtmp in elasticsearch
I can read the file when logged into the box by using last -F /var/log/wtmp
I have logstash running and sending logs to elasticsearch, here is logstash conf file.
input {
file {
path => "/var/log/wtmp"
start_position => "beginning"
}
}
output {
elasticsearch {
host => localhost
protocol => "http"
port => "9200"
}
}
what is showing in elasticsearch is
G
Once i opened the file using less , i could only see binary data.
Now logstash cant understand this data.
A logstash file like the following should work fine -
input {
pipe {
command => "/usr/bin/last -f /var/log/wtmp"
}
}
output {
elasticsearch {
host => localhost
protocol => "http"
port => "9200"
}
}
Vineeth's answer is right but the following cleaner config works as well:
input { pipe { command => "last" } }
last /var/log/wtmp and last are exactly the same.
utmp, wtmp, btmp are Unix files that keep track of user logins and logouts. They cannot be read directly because they are not regular text files. However, there is the last command which displays the information of /var/log/wtmp in plain text.
$ last --help
Usage:
last [options] [<username>...] [<tty>...]
I can read the file when logged into the box by using last -F /var/log/wtmp
I doubt that. What the -F flag does:
-F, --fulltimes print full login and logout times and dates
So, last -F /var/log/wtmp will interpret /var/log/wtmp as a username and won't print any login information.
What the -f flag does:
-f, --file <file> use a specific file instead of /var/log/wtmp

Logstash not matching the pattern

I was learning logstash. Have a very simple config file..
input {
file {
path => "D:\b.log"
start_position => beginning
}
}
# The filter part of this file is commented out to indicate that it is
# optional.
filter {
grok {
match => { "message" => "%{LOGLEVEL:loglevel}" }
}
}
output {
stdout { codec => rubydebug }
}
The input file is just this:
INFO
I am running logstash on windows and the command is
logstash -f logstash.conf
I expect the output to be shown on the console to ensure that its working. But logstash produces no output, just the logstash config messages..
D:\Installables\logstash-2.0.0\logstash-2.0.0\bin>logstash -f logstash.conf
io/console not supported; tty will not be manipulated
Default settings used: Filter workers: 2
Logstash startup completed
I have deleted the sincedb file and tried. Is there something that i am missing?
I think this answers your question:
How to force Logstash to reparse a file?
It looks like you are missing the quotes around "beginning" and the other post recommends redirecting sincedb to dev/null. I don't know if there is a windows equivalent for that. I did use that as well, and it worked fine.
As an alternative, what I do now is to configure stdin() as input so that I don't have to worry about anything else.

Resources