Convert HTTPDATE timestamp to correct format in Graylog - elasticsearch

I have Squid writing logs with a timestamp as dd/MMM/yyyy:HH:mm:ss ZZZZ
"27/Jul/2022:11:55:40 +0100"
I'm sending these logs into Graylog using Filebeat, then parsing the timestamp into individual fields using HTTPDATE in a Grok extractor, so I can get separate Month, Monthday, Year etc fields.
I need to replace the "message received" #timestamp field with the actual "event occurred" timestamp when the event is indexed in Elasticsearch.
How can I convert the Squid timestamp from HTTPDATE into yyyy-MM-dd HH:mm:ss format?
"2022-07-27 11:55:40"
Thanks
EDIT:
Actually I think I have this now. In case it helps anyone else, this was done with a Regex Replacement Extractor:
Extractor Part1
Extractor Part 2
Extractor Part 3

This is an excellent question for the community. Try it there.

Related

How to parse a csv file which has some field containing seprator (comma) as-values

sample message - 111,222,333,444,555,val1in6th,val2in6th,777
The sixth column contains a value consisting of commas (val1in6th,val2in6th is a sample value of 6th column).
When I use a simple csv filter this message is getting converted to 8 fields. I want to be able to tell the filter that val1in6th,val2in6th should be treated as a single value and placed as the value of 6th column (its okay not to have comma between val1in6th and val2in6th when placed as the output as 6th column).
change your plugin, no more the csv one but grok filter - doc here.
Then you use a debugger to create a parser for your lines - like this one: https://grokdebug.herokuapp.com/
For your lines you could use this grok expression:
%{WORD:FIELD1},%{WORD:FIELD2},%{WORD:FIELD3},%{WORD:FIELD4},%{WORD:FIELD5},%{GREEDYDATA:FIELD6}
or :
%{INT:FIELD1},%{INT:FIELD2},%{INT:FIELD3},%{INT:FIELD4},%{INT:FIELD5},%{GREEDYDATA:FIELD6}
It changes the datatypes in elastic of the firsts 5 fields.
To know about parse csv with grok filter in elastic you could use this es official blog guide, it is explained how to use grok with ingestion pipeline, but it is the same with logstash

How to get timestamp from date in elastic search script

As the title suggests, I want to get the timestamp (as a number) from a date type in an elastic search painless script. The following attempts didn't work: doc["date_field"].value, doc["date_field"].date.getMillis().
According to the Painless docs you should be able to access the milliseconds since epoch like this: doc.date_field.millis.
Date fields are exposed as ReadableDateTime, so they support methods
like getYear, getDayOfWeek or e.g. getting milliseconds since epoch
with getMillis. To use these in a script, leave out the get prefix and
continue with lowercasing the rest of the method name.
You should also be able to use the methods from ReadableDateTime. https://www.elastic.co/guide/en/elasticsearch/painless/6.4/painless-api-reference.html#painless-api-reference-org-joda-time-ReadableDateTime

Logstash date format grok pattern

I have a log file which has a date time in 'yyyyMMdd_HHmmss_SSS' format. I am successful in parsing this with _ as delimiter and getting as 3 different text field in ES. But I need this to be converted as ISO_8601 so I can query and visualize the data by date or by hour or by minute.
If you don't specifically need ISO-8601, but care more about the events getting a queryable timestamp, the date filter sounds like a better fit for you.
filter {
date {
match => [ "logdate", "yyyyMMdd_HHmmss_SSS" ]
}
}
This will set the #timestamp field to be a date-searchable field.
However, if you really do need Grok to do the work, you'll probably be best suited through using custom regexes.
(?<logyear>\d{4,})(?<logmonth>\d\d)(?<logday>\d\d)_(and so on)
This leverages single-digit captures to build your string.

Need info in getting the date from filename in logstash

currently i have filename with the below format
[XXXXXXXX][YYYYYYYYYY][2016_07_21][19_21_12][160721T192103][ZZZZ]AB_RTRT.0.log.
is there a way, i can extract the datetimestamp and index it to a specific field in elastic search.
thanks
Subbu

Elasticsearch date field: epoch millis input, string output?

Steps:
1. Define a date field in a mapping.
2. Insert a epoch millisecond (long) value into that field.
Can elastic search returns a string value (yyyy-MM-ddTHH:mm:SS) of that field for a search?
From what I understand of the date-format documentation of ElasticSearch, it will always accept a milliseconds-since-epoch input next to input in the format given by the format, and it will produce a String output using the (first) format given. If you don't provide a format, then the "date_optional_time" format will be used (yyyy-MM-dd’T'HH:mm:ss.SSSZZ).
If the time zone in there is a problem for you, you'd need to give ElasticSearch your intended format.
I don't have the code to hand, but in my testing I believe I managed to do the following:
I used the date formatter on the field and the query fields definition to do this:
curl -XGET 'http://localhost:9200/twitter/tweet/1?fields=title,date_field.date_time'
using the date formats specified here: http://www.elasticsearch.org/guide/reference/mapping/date-format/
If you want a full document returned, this may be onerous. In which case is it possible to use an alias 'view' mapping to get the result to return differently from your primary mapping? Possibly this has become a half-answer.

Resources