How can I set current time in field


(Егор Крид) #1

Hi,
Could you please share with me info how I can to set current system time in field "@timestamp".
In my case, I successfully copy field with @timestamp in filed "real_timestamp".
And then I would like to set @timestamp with system time of the server we logstash running.


(Lewis Barclay) #2

You could try the following:

    ruby { 
         code => "event.set('systemtime', Time.now());"
    }

(Егор Крид) #3

Hi guys,
Thanx @Eniqmatic
I've done this job with the following config:

 mutate {
    add_field => { "realtimestamp" => "%{@timestamp}" }
        }

      ruby {
        code => "event.set('logstash_processed_at', Time.now());"
        }

    mutate {
    convert => { "logstash_processed_at" => "string" }
        }

    date {
    match => [ "logstash_processed_at", "ISO8601" ]
    target => "@timestamp"
    add_tag => "timestamp_changed"
    }

(Lewis Barclay) #4

Correct well done!

Please mark as solved! :slight_smile: