I like to parse and set the correct timestamp to logmessages with the pipeline feature. I have all ready fields with hour,minutes,seconds, day of month and so on…
My first pipeline stage is detecting the logs (for example application server type a). The second stage is parsing the logmessage with the proper grok pattern.
Now I have the issue, that the logmessage timestamp and the graylog (elasticsearch) timestamp differ a view seconds. My idea is to use the parsed fields from stage two and set the correct timestamp in stage three.
My idea is a rule like this:
rule "Appserver Parsing - Timestamp"
when
true
then
let new_timestamp = parse_date(
value: to_string($message.year) + "-" + to_string($message.month) + "-" + to_string($message.day) + " " + to_string($message.hour) + ":" + to_string($message.minute) + ":" + to_string($message.seconds),
pattern: "yyyy-MM-dd hh:mm:ss",
timezone: to_string("Europe/Berlin")
);
set_field("AAA_pipline_timestamp", new_timestamp);
// If the timestamp is correct, rename the field
end
Does this is the correct way? Is an other way a better solution?
I have many different log formats and think this will be a simple way to get the values in fileds and then set the correct timestamp.
Do you use this already and is it working? (The set_field("timestamp", new_timestamp); part)
I have the problem that I can’t store the DateTime object into graylogs timestamp field. If I do this graylog seems to start dropping the messages without any error.
Are you sure, that the “test” message field contains a date which exactly matches the pattern you’ve used in the parse_date() function (without any leading or trailing characters)?
Are you also sure that the order of processors is correct (first extractors, then message processing pipelines)?
This clearly shows that you’re trying to parse an empty string (“”) as timestamp, which obviously doesn’t match the date pattern in your parse_date() function.
Maybe you should ensure that the “test” field really contains a parseable string.
What do you think about this pipeline ? You just have to set the TZ for the now function.
No extractor needed.
rule “timestamp_now+2"
when
true
then
let new_date = parse_date(substring(to_string(now(”+0100")),0,23), “yyyy-MM-dd’T’HH:mm:ss.SSS”);
set_field(“timestamp”, new_date);
end