コンテンツにスキップ

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

フィールドの加工(以下を参考)

https://qiita.com/hssh2_bin/items/17c6fb71748bafe5addb#5-%E6%AD%A3%E8%A6%8F%E5%8C%96%E3%83%95%E3%82%A3%E3%83%AB%E3%82%BF%E4%BD%9C%E6%88%90

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"
    }
  }
}