Parsing a date field in logstash to elastic search - elasticsearch

I am trying to parse log files from IIS to the ELK stack (Logstash:2.3, Elastic:2.3 and Kibana:4.5, CentOS 7 vm).
I have attempted to parse a date field from the log message as the event timestamp using the date filter below in my logstash configuration:
date {
match => ["date_timestamp", "yyyy-MM-dd HH:mm:ss"]
timezone => "Europe/London"
locale => "en"
target => "#timestamp"
}
The first few characters of the entire log message that was parsed to Elastic Search is:
"message": "2016-03-01 03:30:49 .........
The date field above was parsed to Elastic Search as:
"date_timestamp": "16-03-01 03:30:49",
However, the event timestamp that was parsed to Elastic Search using the date filter above is:
"#timestamp": "0016-03-01T03:32:04.000Z",
I will like the #timestamp to be exactly 2016-03-01T03:30:49 as I can't immediately figure out why there is a difference between the hours and minutes.
I have looked at similar problems and documentations such as this one on SO and this one on logstash documentation and logstash documentation.
Any pointer in the right direction will be appreciated.
Regards
SO

in your date_timestamp you have only 2 characters for year: "16-03-01 03:30:49", so the date pattern in your date filter is incorrect, should be:
date {
match => ["date_timestamp", "yy-MM-dd HH:mm:ss"]
timezone => "Europe/London"
locale => "en"
target => "#timestamp"
}

Related

Date filter in logstash: bad results(shows one day back)

I am loading a CSV file into elastic using logstash
This CSV file contains a column 'deadline' which has dates of the format
"deadline": "15-06-2014"
I am using the date filter plugin in logstash to get this in date format into elastic
date {
match => ["deadline","dd-MM-yyyy"]
target => "deadline_date"
}
But in the output I am receiving the date which has moved one day back
"deadline_date": "2014-06-14T18:30:00.000Z"
I have one more instance with format like this "dd-MM-yyyy HH:mm"
date {
match => ["launched","dd-MM-yyyy HH:mm"]
target => "launched_date"
}
Gives result with time changed
"launched": "09-09-2013 18:19"
"launched_date": "2013-09-09T12:49:00.000Z"
Please help me figure out this issue.
You're missing your timezone:
date {
match => ["deadline","dd-MM-yyyy"]
target => "deadline_date"
timezone => "Etc/GMT"
}

date format convertion in logstash elk stack

I have a date column in my table that I fetch using jdbc input in logstash. The problem is logstash gives a wrong value to elasticsearch stack.
For example if I have a date start_date="2018-03-01" in elasticsearch I would get the value "2018-02-28 23:00:00.000".
What I want is to keep the format of start_date or at least output the value "2018-03-01 00:00:00.000" to elasticsearch.
I tried to use this filter :
date {
timezone => "UTC"
match => ["start_date" , "ISO8601", "yyyy-MM-dd HH:mm:ss"]
}
but it didn't work.
It is because, you are trying to convert it to UTC timezone. You need to change your configuration like this:
date {
match => ["start_date" , "yyyy-MM-dd"]
}
This would be enough to parse your date.
Let me know if that works.

Add extra value to field before sending to elasticsearch

I'm using logstash, filebeat and grok to send data from logs to my elastisearch instance. This is the grok configuration in the pipe
filter {
grok {
match => {
"message" => "%{SYSLOGTIMESTAMP:messageDate} %{GREEDYDATA:messagge}"
}
}
}
This works fine, the issue is that messageDate is in this format Jan 15 11:18:25 and it doesn't have a year entry.
Now, i actually know the year these files were created in and i was wondering if it is possible to add the value to the field during the process, that is, somehow turn Jan 15 11:18:25 into 2016 Jan 15 11:18:25 before sending to elasticsearch (obviously without editing the files, which i could do and even with ease but it'll be a temporary fix to what i have to do and not a definitive solution)
I have tried googling if it was possible but no luck...
Valepu,
The only way to modify the data from a field is using the ruby filter:
filter {
ruby {
code => "#your code here#"
}
}
For more information like...how to get,set field values, here is the link:
https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.html
If you have a separate field for date as a string, you can use logstash date plugin:
https://www.elastic.co/guide/en/logstash/current/plugins-filters-date.html
If you don't have it as a separate field (as in this case) use this site to construct your own grok pattern:
http://grokconstructor.appspot.com/do/match
I made this to preprocess the values:
%{YEAR:yearVal} %{MONTH:monthVal} %{NUMBER:dayVal} %{TIME:timeVal} %{GREEDYDATA:message}
Not the most elegant I guess, but you get the values in different fields. Using this you can create your own date field and parse it with date filter so you will get a comparable value or you can use these fields by themselves. I'm sure there is a better solution, for example you could make your own grok pattern and use that, but I'm gonna leave some exploration for you too. :)
By reading thoroughly the grok documentation i found what google couldn't find for me and which i apparently missed the first time i read that page
https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html#plugins-filters-grok-add_field
Using the add_field and remove_field options i managed to add the year to my date, then i used the date plugin to send it to logstash as a timestamp. My filter configuration now looks like this
filter {
grok {
match => {
"message" => "%{SYSLOGTIMESTAMP:tMessageDate} %{GREEDYDATA:messagge}"
add_field => { "messageDate" => "2016 %{tMessageDate}" }
remove_field => ["tMessageDate"]
}
}
date {
match => [ "messageDate", "YYYY MMM dd HH:mm:ss"]
}
}
And it worked fine

Logstash omitting daylight saving time when parsing date

My log file contains a timestamp without timezone indicator.
In format dd-MMM-yyyy::HH:mm:ss
My server is located in central Europe, so is in timezone UTC+1 but currently uses DST that results in UTC+2.
A date in the log file: 2017-07-25::17:30:00 is parsed as 2017-07-25T16:30:00Z. But it should be 2017-07-25T15:30:00Z. As we are in DST now.
Logstash seems to consider only the timezone but not DST.
How can I fix this?
My logstash config:
date {
match => ["logdate", "dd-MMM-yyyy::HH:mm:ss"]
target => "#timestamp"
remove_field => "logdate"
}
You need to specify the timezone your dates are in:
date {
match => ["logdate", "dd-MMM-yyyy::HH:mm:ss"]
target => "#timestamp"
remove_field => "logdate"
timezone => "Europe/Zurich" <-- add this line
}
You may change "Europe/Zurich" to whatever timezone makes sense to you (other list of time zones that might be of use)

How to set time in log as main #timestamp in elasticsearch

Im using logstash to index some old log files in my elastic DB.
i need kibana/elastic to set the timestamp from within the logfile as the main #timestamp.
Im using grok filter in the following way:
%{TIMESTAMP_ISO8601:#timestamp}
yet elasticsearch sets the time of indexing as the main #timestamp and not the timestamp written in the log line.
Any idea what am i doing wrong here?
Thanks
Use the date filter to set the #timestamp field. Extract the timestamp in whatever format it's in into a separate (temporary) field, e.g. timestamp, and feed it to the date filter. In your case you'll most likely be able to use the special ISO8601 timestamp format token.
filter {
date {
match => ["timestamp", "ISO8601"]
remove_field => ["timestamp"]
}
}

Resources