Logstashの設定をするときのメモ
デバッグ用
以下が基本のパターン
patterns_dir を書かずに message 以降にそのままパターンを書いても良さそう
input {
  stdin {}
}
filter {
  grok {
    patterns_dir => ["/etc/logstash/pattern.d"]
    match => { "message" => "なにか" }
  }
}
output {
  stdout {}
}
grokつくるとき
公式のpatternsリスト
https://www.elastic.co/guide/en/beats/filebeat/7.4/exported-fields-ecs.html#_log_2
https://github.com/elastic/ecs
オレオレ正規表現をつかいたいとき
https://medium.com/statuscode/using-custom-regex-patterns-in-logstash-fa3c5b40daab
テスト方法
http://grokconstructor.appspot.com/do/match
https://grokdebug.herokuapp.com/
フィールドの加工
https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html
フィールドの加工(以下を参考)
filter {
  if "OK" in [message] {
    grok {
      patterns_dir => [ "/etc/logstash/patterns.d/mypattern" ]
      match => { "message" => "%{MYLOG}"}
    }
    date {
      match => [ "start","UNIX" ]
      target => "@timestamp"
    }
    date {
      match => [ "start","UNIX" ]
      target => "start_time"
    }
    geoip {
      source => "ipaddr"
      target => "ipaddr_geoip"
      tag_on_failure => "eoip_lookup_failure"
    }
  }
}