Hello, I'm trying to create a Scripted Field to compute the delay between timestamps: the time when logstashs sees the event - the actual timestamp from the log/event. And so far I'm having a terrible time getting to understand and work with painless, I'm having a lot of trouble doing this simple thing...
Luckily I found some posts here from where I was able to scratch this script:
Date ts = new Date(doc['@timestamp'].value.millis);
Date ti = new Date(doc['event.ingested'].value.millis);
if (doc['event.timezone'].equals("+02:00")) {
return (ti.getTime()+2*60*60*1000 - ts.getTime());
} else {
return (ti.getTime() - ts.getTime());
}
Although all my events are supposed to be normalized to UTC by logstash, they are still processed as UTC+2, so the idea is to just add the +2h (event.timezone) when computing the difference between timestamps. However and here are my 2 issues:
- I'm unable to check whether event.timezone == "+02:00", and therefore it always goes to the else part of the conditional.
- Is there a way to manipulate the event.timezone dynamically? That way it wouldn't be necessary to go through point 1, just check if event.timezone exists and add it, whatever its value.
Thanks in advance, I would appreciate as much help as I can get to make Painless less Painful