I am trying to get just the date part from @report_timestamp field of a parsed json message in logstash configuration so that I can name the output log file name based on date, say request_2017_08_01.log
my message looks like this:
"{"udf": 1, "report_timestamp": "2017-11-29T17:58:28.967388", "service_engine": "test", "vcpu_id": 1, "log_id": 911550, "client_ip": "93.20.1.24", "response_code": 200}"
my logstash conf looks like this:
filter {
json {
source => "message"
target => "parsedjson"
}
mutate {
add_field => {"event_generated_on" => "%{[parsedjson][report_timestamp]}"}
}
Expecting date part of the report_timestamp field value assigned to "event_generated_on".
You can use a grok filter to extract the date, but if your end goal is to name your output file e.g. request_2017_08_01.log just use the %{+YYYY_MM_dd} notation to get the timestamp from @timestamp formatted in yyyy_mm_dd format.
Not sure if @timestamp will have values same as that of report_timestamp (What if I put a past date ) which is a part of json message field. please suggest.
Well, I don't know your data so I can't tell if report_timestamp should be copied to @timestamp but it probably should be if report_timestamp is the "main" timestamp of the event.
If not you should, as I said, use a grok filter to extract the date part from report_timestamp.
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.