Как устранить ошибку разбора CSV-файла в Logstash - PullRequest
1 голос
/ 27 мая 2020

Я использую Filebeat для отправки CSV-файла в Logsta sh, а затем в Kibana, однако я получаю сообщение об ошибке синтаксического анализа, когда файл CSV выбирается Logsta sh.

Это - это содержимое файла CSV:

time    version id  score   type

May 6, 2020 @ 11:29:59.863  1 2 PPy_6XEBuZH417wO9uVe  _doc

Logsta sh .conf:

input {
  beats {
    port => 5044
  }
}
filter {
  csv {
      separator => ","
      columns =>["time","version","id","index","score","type"]
      }
}
output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
  }
}

Filebeat.yml:

filebeat.inputs:

# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.

- type: log

  # Change to true to enable this input configuration.
  enabled: true

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /etc/test/*.csv
    #- c:\programdata\elasticsearch\logs\*

и ошибка в Logsta sh:

[2020-05-27T12:28:14,585][WARN ][logstash.filters.csv     ][main] Error parsing csv {:field=>"message", :source=>"time,version,id,score,type,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", :exception=>#<TypeError: wrong argument type String (expected LogStash::Timestamp)>}
[2020-05-27T12:28:14,586][WARN ][logstash.filters.csv     ][main] Error parsing csv {:field=>"message", :source=>"\"May 6, 2020 @ 11:29:59.863\",1,2,PPy_6XEBuZH417wO9uVe,_doc,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", :exception=>#<TypeError: wrong argument type String (expected LogStash::Timestamp)>}

Я получаю некоторые данные в Kibana, но не то, что хочу видеть.

enter image description here

1 Ответ

2 голосов
/ 27 мая 2020

Мне удалось заставить его работать локально. ошибки, которые я заметил до сих пор, были:

  1. Использование зарезервированных полей ES, например @timestamp, @version и др.
  2. Временная метка была не в формате ISO8601. У него был знак @ посередине.
  3. Ваш фильтр установил разделитель на ,, но ваш реальный разделитель CSV - "\t".
  4. Согласно ошибке вы можете это увидеть пытается также работать с вашей строкой заголовков, я предлагаю вам удалить его из CSV или использовать параметр skip_header.

Ниже находится logsta sh .conf файл, который я использовал:

input {
    file {
        path => "C:/work/elastic/logstash-6.5.0/config/test.csv"
        start_position => "beginning"
    } 
}
filter { 
    csv { 
        separator => ","
        columns =>["time","version","id","score","type"]
    } 
} 
output { 
    elasticsearch { 
        hosts => ["localhost:9200"]
        index => "csv-test" 
    } 
}

CSV файл, который я использовал:

May 6 2020 11:29:59.863,1,PPy_6XEBuZH417wO9uVe,_doc
May 6 2020 11:29:59.863,1,PPy_6XEBuZH417wO9uVe,_doc
May 6 2020 11:29:59.863,1,PPy_6XEBuZH417wO9uVe,_doc
May 6 2020 11:29:59.863,1,PPy_6XEBuZH417wO9uVe,_doc

Из моего Kibana:

enter image description here

...