LoginSignup
124
130

More than 5 years have passed since last update.

ZabbixからSlackに通知を送る

Last updated at Posted at 2014-10-21

方針

  • Slackのincoming hookを利用して、メッセージを送るシェルスクリプトを使う
  • Zabbixに新規にSlackユーザーを作成し、Mediaとして上記スクリプトを登録する
  • slackユーザーを各種通知の通知先に設定されているユーザーグループに追加することで通知を流す

関連リソース

ericoc/zabbix-slack-alertscript
https://github.com/ericoc/zabbix-slack-alertscript

を使います。基本的にはこちらのreadme通りに設定します。

実際の作業

Zabbixサーバにスクリプトを置く

まずはZabbixのAlertScriptPathを確認

grep AlertScriptsPath /etc/zabbix/zabbix_server.conf
### Option: AlertScriptsPath
AlertScriptsPath=/usr/local/share/zabbix/alertscripts

スクリプトをコピーして実行権限をつけておく

cd /usr/local/share/zabbix/alertscripts/
wget https://raw.githubusercontent.com/ericoc/zabbix-slack-alertscript/master/slack.sh
chmod a+x slack.sh

ls -lh /usr/local/share/zabbix/alertscripts/slack.sh
-rwxr-xr-x 1 root root 1.4K Dec 27 13:48 /usr/local/share/zabbix/alertscripts/slack.sh

slack.shの先頭部分の設定を変更

設定項目 設定内容
subdomain hogefuga.slack.comのhogefuga部分を指定
username Slack上に通知するときに使われるユーザー名を指定
channel 通知を送る先のslackチャンネル名を#つきで指定

# Slack sub-domain name (without '.slack.com'), user name, and the channel to send the message to
subdomain='myorgname'
username='Zabbix'
channel='#alerts'

Slack側の設定

https://my.slack.com/services/new/incoming-webhook
からincoming web hookを作成し、"Your Unique Webhook URL"の"token="以下を確認しておきます。

Your Unique Webhook URLが
https://hogefuga.slack.com/services/hooks/incoming-webhook?token=HogehogeFugafuga
であれば、tokenは "HogehogeFugafuga"です。

Zabbix側の設定

"Slack"という名前のmedia typeを作成

web interfaceにsuper-administrator権限のあるユーザーでログインします。
"Administration"タブ -> "Media types"タブ -> "Create media type"ボタンを押して作成。

設定項目 設定内容
media type Script
Script name Slack.sh
Enabled チェックを入れる

Saveする。

"Slack"という名前のユーザーを作成

"Administration"タブ -> "Users"タブ
"User groups"のドロップダウンからUsersを選択 -> "Create User"ボタン

"User"タブ

設定項目 設定内容
Alias Slack

"Media"タブ

"Add"ボタンをおして

設定項目 設定内容
Type Slack
Send to token(例:HogehogeFugafuga)
Use if severityのチェック項目 すべてチェック
Status Enabled

Saveする。

Actionの設定

"Configuration"タブ -> "Actions"タブの内容を確認

Name Conditions Operations Status
Report problems to Zabbix administrators Maintenance status not in maintenance Trigger value = PROBLEM Send message to user groups: Zabbix administrators via all media Enabled

といったエントリがあるならば、Zabbix administratorsグループにSlackユーザーを追加してしまえばOKです。
(via all mediaなのでユーザーSlackのSlackメディアから送られる)

ハマりやすいポイント

to be added

おわりに

Slack.shはとても短いスクリプトなので、自分でカスタムもしやすいと思います。


参考

124
130
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
124
130