エンジニア全員がいち早く障害対応に取り掛かるようにSlack + Hubotで各メンバーに固定のメッセージを流す電話をかけられるようにしてます。
“起きろう!起きろう!早く起きろう!サーバーが落ちてるぞ!”
Slackでコマンド一つで掛けられるのでざわざわ電話を取り出す必要もなく、誰でも気軽く掛けられるようになってます。その延長線でもありますが、つい先日Amazon Dash Buttonが日本でもリリースされたので、それを使ってサーバー障害時非常ベルみたいなことをやってみました。
用意するもの。
- Slack
- Amazon Dash Button
- メンバーの電話番号
- Hubot
- Twilioアカウント
Slack
Amazon Dash Buttonで使われるwebhook urlを予め生成しておきます。 https://{team}.slack.com/apps でIncoming WebHooksを選択し、Postするチャンネルを選択して、Webhook URLをメモします。後でButton設定で使います。
Amazon Dash Button
Amazon Dash Button本来の使い方はこれではないので少し設定が必要です。まず、Amazon AppをiPhoneかAndroidにインストールします。Buttonを6秒押してAppから認識するようにします。公式ドキュメントは以下のようになります。
手順のように商品まで選択して設定すると、本来の注文ボタンになるので、商品選択画面で右上のxボタンで設定を終了させます。
この状態のままMac側でAmazon Dash Buttonのフィジカルアドレスを取得します。
https://github.com/maddox/dasher
$ git clone https://github.com/maddox/dasher.git $ cd dasher $ sudo ./script/find_button
下のようなMACアドレスが表示されますが、今回のButtonはYAMAHA CORPORATIONでした。macとandroid, iphoneが同じwifiではないときに表示されなかったりすることがあるので、同じwifi環境にしましょう。
$ ./script/find_button Password: Watching for arp & udp requests on your local network, please try to press your dash now Dash buttons should appear as manufactured by 'Amazon Technologies Inc.' Possible dash hardware address detected: 00:**:**:**:**:** Manufacturer: YAMAHA CORPORATION Protocol: arp
フィジカルアドレスをコピーして以下のようにconfig/config.jsonのaddressに反映します。 urlにはSlackのwebhook urlを書いて、bodyのtextにはbotコマンドを書きます。今回はbot用に bot sos
と書きます。
{"buttons":[ { "name" : "Amazon Dash Button", "address": "00:**:**:**:**:**", "url": "https://hooks.slack.com/services/***/***", "method": "POST", "json": true, "body": {"text":"bot sos"} } ]}
dasher起動してAmazon Dash Buttonの押下を監視します。
$ sudo npm start > dasher@1.1.1 start /Users/dongri/Desktop/dasher > node app.js [2016-12-12T03:20:04.614Z] Amazon Dash Button added.
これで、MacとAmazon Dash Buttonの準備は完了です。
Twillo
電話掛けるようにするので、TwilioのAPIを使います。予めユーザー登録して、日本国内に電話掛けれれるように電話番号を取得しておきます。APIで使われる ACCOUNT SIDとAUTH TOKENもメモしときます。
Hubot
Hubot+Slackの設置に関してはここでは割愛します。hubot script書ける前提で話します。 /scripts/sos.coffee というファイルを作成します。
async = require 'async' # メンバーの電話番号設定 users = { "dongri": "+81**********" "dave": "+81**********" "sheba": "+81**********" } client = require('twilio')("******", "*******") # ACCOUNT SID, AUTH TOKEN設定 twilioPhoneNumber = "+18*********" #Twilioで取得した電話番号を設定 call = (to, callback) -> client.makeCall { to: to from: twilioPhoneNumber url: "https://dl.dropboxusercontent.com/u/*****/twilio/alice.xml" # 音声に流れるメッセージをxml形式で書きます。(下にフォーマット書きます。) }, (err, responseData) -> callback(err) module.exports = (robot) -> robot.catchAll (msg) -> matches = msg.message.text.match(/bot sos/i) return if matches == null or matches.length == 0 tos = [] for username of users tos.push users[username] async.forEachSeries tos, (to, cb) -> call to, (err) -> cb(err) , (err) -> if err? msg.send err else msg.send 'calling calling ~'
xmlフォーマット
<Response> <Say voice="alice" language="ja-JP">起きろう!起きろう!早くおきろう!サーバー落ちてるぞ!</Say> </Response>
完成
Amazon Dash Buttonを強く押してみましょう!
We're hiring!
Origamiではいろんなポジションのエンジニアを募集してます。
入って一緒に非常ベルを押しましょう。障害起きた時だけですけどねw
それと別に書いたコードが思う通りに動かない、イライラする時はButton押して上司をいじめて、ストレス解消もできる環境です。
↑の takashiはVPです。
応募お待ちしております。
Top comments (0)