xml的日志存储配置

bd1hkmkf  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(349)

我是elasticsearch和logstash的新手,我想为logstash创建配置文件,它可以加载xml文件数据,所以我可以使用kibana在elasticsearch中进行搜索。如何创建此配置?
xml文件结构为:

<?xml version="1.0" encoding="ISO-8859-15"?>

<ORDERS>
<ORDER>
<COMPANY_CODE>CHU</COMPANY_CODE>
<ETABLISSEMENET_CODE>CHU</ETABLISSEMENET_CODE>
<FOURNISSEUR>BI</FOURNISSEUR>
<DESTINATAIRE>CHUSUDRUN2</DESTINATAIRE>
<NUM_COMMANDE_MYTOWER>342</NUM_COMMANDE_MYTOWER>
<NUM_COMMANDE_CHU>CMD12345</NUM_COMMANDE_CHU>
<INSTRUCTIONS>COLIS</INSTRUCTIONS>
<ETAT>4</ETAT>
<DATE_DE_COMMANDE>01-01-2018</DATE_DE_COMMANDE>
<DATE_DE_DISPONIBILITE>01-01-2018</DATE_DE_DISPONIBILITE>
<MONTANT_HT>3695.0</MONTANT_HT>
<DATE_DE_CREATION></DATE_DE_CREATION>
<POIDS_BRUT>20.0</POIDS_BRUT>
<NOMBRE_COLIS>3</NOMBRE_COLIS>
a64a0gku

a64a0gku1#

下面是logstash中的xml conf示例:

input {  
file 
{
    path => "/home/Test_xml.xml"
    start_position => "beginning"
     codec => multiline 
    {
        pattern => "^<\?book .*\>"
        negate => true
        what => "previous"
    }
    sincedb_path => "/dev/null"
  }
}

filter 
{
   xml {
    source => "message"
    target => "parsed"
  }
  split {
    field => "[parsed][book]"
    add_field => {
      bookAuthor                => "%{[parsed][book][author]}"
      title                 => "%{[parsed][book][title]}"
      genre                 => "%{[parsed][book][genre]}"
      price                => "%{[parsed][book][price]}"
      publish_date             => "%{[parsed][book][publish_date]}"
      description        => "%{[parsed][book][description]}"
    }
  }
}

output 
{
    elasticsearch {
hosts => "localhost:9200"
index => "xml_test"
}
    stdout 
    {
        codec => rubydebug
    }
}

xml文件的链接
我试着用logstash在elasticsearh long back中插入数据。希望这能奏效。

相关问题