2017-05-31 101 views
2

MySQLとElasticsearch間のデータをLogstashで同期しようとしています。Logstash複数入力複数出力

複数のjdbc入力と複数の出力を異なるelasticsearchインデックスに設定しました...そして、すべてがelseブロックに行くので間違っています。ここで

は私の設定です:

input { 
    jdbc { 
     jdbc_connection_string => "jdbc:mysql:127.0.0.1:3306/whatever" 
     jdbc_user => "xxx" 
     jdbc_password => "yyy" 
     jdbc_driver_library => "mysql-connector-java-5.1.41.jar" 
     jdbc_driver_class => "com.mysql.jdbc.Driver" 
     schedule => "* * * * *" 
     statement => "SELECT * from table1 WHERE updated_at > :sql_last_value order by updated_at" 
     use_column_value => true 
     tracking_column => updated_at 
     type => "table1" 
     last_run_metadata_path => "/opt/logstash-5.4.0/sql-last-values/table1" 
    } 
     jdbc { 
     jdbc_connection_string => "jdbc:mysql:127.0.0.1:3306/whatever" 
     jdbc_user => "xxx" 
     jdbc_password => "yyy" 
     jdbc_driver_library => "mysql-connector-java-5.1.41.jar" 
     jdbc_driver_class => "com.mysql.jdbc.Driver" 
     schedule => "* * * * *" 
     statement => "SELECT * from table2 WHERE updated_at > :sql_last_value order by updated_at" 
     use_column_value => true 
     tracking_column => updated_at 
     type => "table2" 
     last_run_metadata_path => "/opt/logstash-5.4.0/sql-last-values/table2" 
    } 
} 
output { 
    if [type] == "table1" { 
      elasticsearch { 
       hosts => ["localhost:9200"] 
       index => "table1" 
       document_type => "table1" 
       document_id => "%{id}" 
     } 
     file { 
       codec => json_lines 
       path => "/opt/logstash-5.4.0/logs/table1.log" 
     } 

    } else if [type] == "table2" { 
      elasticsearch { 
       hosts => ["localhost:9200"] 
       index => "table2" 
       document_type => "table2" 
       document_id => "%{id}" 
     } 
    } else { 
     file { 
       codec => json_lines 
       path => "/opt/logstash-5.4.0/logs/unknown.log" 
      } 

    } 
} 

私が間違って何をしているのですか?すべてがelseブロックに/opt/logstash-5.4.0/logs/unknown.logに行きます。

私のアプローチは間違っていますか?複数のファイルを用意する必要がありますか?

ありがとうございました

答えて

6

解決策を発見しました!代わりに、タイプの使用タグ場合

...

input { 
jdbc { 
... 
tags => "table1" 
... 
} 
jdbc { 
... 
tags => "table2" 
... 
} 
} 
output { 
    if "table1" in [tags] { 

} 

https://discuss.elastic.co/t/solved-multiple-logstash-config-file/51692/10

+0

私は同様の問題を持って、それを固定タグを使用していました。 「タイプ」はログフィールドで使用でき、入力値を無効にします。 winlogbeatでは "type"はログの偶数型になります。 –