I need to extract the timestamp from this line:
[Tue, 07 Jun 2018 15:53:29 +0200] codedeploy-agent started
1)) I've tried the following filter:
mutate {
copy => { "message" => "ts" }
gsub => [ "ts", "\[", "" ]
gsub => [ "ts", "\].*", "" ]
}
but it has no effect: ts
is identical to message
.
2)) If I don't escape the square brackets and use the literal strings...
mutate {
copy => { "message" => "ts" }
gsub => [ "ts", "[", "" ]
gsub => [ "ts", "] codedeploy-agent started", "" ]
}
... the system throws an error [ERROR][logstash.pipeline ] Pipeline aborted due to error {:pipeline_id=>"main", :exception=>#<RegexpError: premature end of char-class: /[/>
3)) If I escape just the square brackets and use the literal string instead of the regex...
mutate {
copy => { "message" => "ts" }
gsub => [ "ts", "\[", "" ]
gsub => [ "ts", "\] codedeploy-agent started", "" ]
}
ts
is identical to message
, again.
4)) This filter:
dissect {
mapping => { "message" => "\[%{ts} %{+ts} %{+ts} %{+ts} %{+ts} %{+ts}\] codedeploy-agent started" }
}
returns a ts
which, strangely, contains ue, 07 Jun 2018 15:53:29 +0200] codedeploy-agent started
.
5)) Without escaping the square brackets:
dissect {
mapping => { "message" => "[%{ts} %{+ts} %{+ts} %{+ts} %{+ts} %{+ts}] codedeploy-agent started" }
}
I get a ts
which is again identical to message
.
There's probably an obvious solution, but what is it?