【问题标题】:Is it posible to split path route in .conf file?是否可以在 .conf 文件中拆分路径路径?
【发布时间】:2021-05-06 12:11:00
【问题描述】:

我正在尝试以更具可扩展性的方式编写此 .conf 文件,我的想法是,为了在 elasticsearch 中拥有多索引,拆分路径并获取最后一个位置以具有 csv 名称并将其设置为类型和弹性搜索中的索引。

import pandas as pd
import numpy as np

input {
  file {
    path => "/home/aitor2/RETO8/BIGDATA/df_suministro_activa.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
  file {
    path => "/home/aitor2/RETO8/BIGDATA/df_activo_consumo.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
path2 = path.split('/')[-1]
filter {
if [path] == "/home/aitor2/RETO8/BIGDATA/df_suministro_activa.csv"{
    mutate { replace => { type => path2 } } 
  csv {
      separator => ","
      skip_header => "true"
      autodetect_column_names => true
  }
     ruby {
    code => "event.to_hash.each { |k, v|
    if k.start_with?('Linea') and v.is_a?(String)
      event.set(k, v.to_f)
    end
}
  "
}
  
}
else if [path] == "/home/aitor2/RETO8/BIGDATA/df_activo_consumo.csv"{
    mutate { replace => { type => "apaches2" } } 
  csv {
      separator => ","
      skip_header => "true"
      autodetect_column_names => true
  }
   ruby {
    code => "event.to_hash.each { |k, v|
    if k.start_with?('Smart') and v.is_a?(String)
      event.set(k, v.to_f)
    end
}
  "
}
  
 }



}

output {
   elasticsearch {
     hosts => "http://localhost:9200"
     index => "%{type}_indexer"
 }
  
stdout {codec => rubydebug}

}

我尝试用path2 = path.split('/')[-1] 来做,但我不确定这是否可行。

【问题讨论】:

    标签: elasticsearch logstash logstash-grok logstash-configuration


    【解决方案1】:

    filter 部分,将type 的值设置为文件名(df_suministro_activa.csvdf_activo_consumo.csv)。我为此使用grokmutate 是另一种可能性(cf doc)

    然后您可以在输出中使用type / 在 if-else / 中更改其值等。

    input {
      file {
        path => "/home/aitor2/RETO8/BIGDATA/df_suministro_activa.csv"
        ...
      }
      file {
        path => "/home/aitor2/RETO8/BIGDATA/df_activo_consumo.csv"
        ...
      }
    }
    
    filter {
      grok { match { "path" => "UNIXPATH/(?<type>[^/]+)" } }
    
      if [type] == "df_suministro_activa.csv" {
        ...
      }
      else if [type] == "df_activo_consumo.csv" {
        mutate { replace => { type => "apaches2" } } 
        ...
      }
    }
    
    output {
       elasticsearch {
         hosts => "http://localhost:9200"
         index => "%{type}_indexer"
      }
    }
    

    我不确定path 字段;您可能想在filter 块中尝试[log][file][path] 而不是path

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 2020-08-04
      • 2015-12-20
      • 2011-05-24
      • 2021-10-11
      • 1970-01-01
      • 2020-06-20
      相关资源
      最近更新 更多