LoginSignup
6
10

More than 5 years have passed since last update.

fluentdでログの特定文言をSlackに通知する

Last updated at Posted at 2018-03-18

概要

先輩にfluentdでログをgrepし、Slackに通知することができると教わった。
学習のため、自分でも試してみる。

fluentdとプラグインを導入

公式サイトを参考に導入を進める。

シェルを実行する

curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh

プラグインを導入

// Slack通知のプラグイン
$ td-agent-gem install fluent-plugin-slack
// grepのプラグイン
$ td-agent-gem install fluent-plugin-grep

設定ファイルに記載

/etc/td-agent/td-agent.conf
<source>
  type tail
  path ログファイル名
  pos_file ログファイル名.pos
  format none
  tag error_log_detail
</source>

<match error_log_detail>
  type grep
  regexp1 message message
  add_tag_prefix slack
</match>

<match slack.*>
  type slack
  webhook_url 通知するチャンネルのWebfookURL
  channel 通知するチャンネル名
  username fluentd
  flush_interval 5s
  color warning
  icon_emoji :ghost:
  message_keys message
  message "引っ掛ける文言"
</match>

fluentdを起動

systemctl start td-agent

これで準備はOK。
あとはログファイルに書き出されると下記のようにSlackに通知される。

スクリーンショット 2018-03-19 0.07.45.png

これで文言を引っ掛けてが発生したらすぐに検知できるようになった。

参考

https://qiita.com/jumbOrNot/items/c7ae01f1456ef61f66a8
https://qiita.com/minamijoyo/items/1bb277383d8d2d2c7c11

6
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
10