Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trim field value, or remove part of the value

I am trying to adjust path name so that it no longer has the time stamp attached to the end. I am input many different logs so it would be impractical to write a conditional filter for every possible log. If possible I would just like to trim the last nine characters of the value.

For example "random.log-20140827" would become "random.log".

like image 476
virus.cmd Avatar asked May 14 '15 15:05

virus.cmd


2 Answers

mutate {
    gsub => [
        "path", "-\d{8}$", ""
    ]
}
like image 99
Alain Collins Avatar answered Jan 01 '23 02:01

Alain Collins


So if you know it's always going to be random.log-something --

if [path] =~ /random.log/ {
  mutate {
     replace => ["path", "random.log"]
  }
}

If you want to "fix" anything that has a date in it:

if [path] =~ /-\d\d\d\d\d\d\d\d/ {
   grok {
      match => [ "path", "^(?<pathPrefix>[^-]+)-" ]
   }
   mutate {
      replace => ["path", "%{pathPrefix}"]
      remove_field => "pathPrefix"
   }
}

Of the two, the first is going to be less compute intensive.

I haven't tested either of these, but they should work.

like image 43
Alcanzar Avatar answered Jan 01 '23 01:01

Alcanzar