How to refer path from filter to other?


(Saket Kumar) #1

input {
file {
path => ["/opt/Log/*.csv" ]
start_position => "beginning"
}
}

i have requirement to use if [path] == "contains string" then set type => string.

Also can i refer path in other filters such as in Filter plugin and how.

thanks in advance.


(Magnus Bäck) #2

The path of the input file is saved in the path field so you can e.g. do this:

filter {
  if "substring" in [path] {
    mutate {
      replace => {
        "type" => "string"
      }
    }
  }
}

(Saket Kumar) #3

Can i refer this [path] in ruby {}.

I have requirement to extract the file name from path and add_field for them in elastic search...

the Ruby code what i have written:

def ReadFileName(filepath)
filename = File.basename("#{filepath}", ".*")
value = filename.split("")
x = value[0]
y = value[1]+"
" + value[2] +"_"+ value[3]
z = value[4]

print "#{x} \n"
print "#{y} \n"
print "#{z} \n"

return x,y,z
end

ReadFileName("d:\1431509083921_150513_E6_GHY_bing_CSV_ContentBreakdown.csv")

Hence instead ReadFileName("d:\1431509083921_150513_E6_GHY_bing_CSV_ContentBreakdown.csv") can i refer ReadFileName("[path]")


(Magnus Bäck) #4

You don't have to use a ruby filter for this, but if you choose to do so you can access it with event['path'].


(Saket Kumar) #5

what you suggest except ruby. i am sorry for being so demanding here...but i appreciate your help.


(Magnus Bäck) #6

It's an ideal job for a grok filter.


(system) #7