イベントドリブンな StackStorm で運用自動化
こんにちは。@jedipunkz です。 今回は StackStorm (https://stackstorm.com/) というイベントドリブンオートメーションツールを使ってみましたので 紹介したいと思います。 クラウドとプロビジョニングツールの登場で昨今はエンジニアがほぼ全ての操作を自動化出来るようになりました。 ですが監視についてはどうでしょうか?監視システムを自動で構築することが出来ても障害発生時に対応を行う のは手動になっていませんでしょうか。もちろんクラスタ組んでいれば大抵のアラートは放置出来ますが、クラスタ を組むことが出来ないような箇所はクラウドを使ってもどうしても出てきます。 そこで登場するのが今回紹介する StackStorm のようなツールかなぁと考えるようになりました。 インストール インストール手順は下記の URL にあります。 https://docs.stackstorm.com/install/index.html 自分は CentOS7 を使ったので下記のワンライナーでインストールできました。 password は任意のものを入れてください。 curl -sSL https://stackstorm.com/packages/install.sh | bash -s -- --user=st2admin --password=foo MongoDB, postgreSQL が依存してインストールされます。 80番ポートで下記のような WEB UI も起動します。 StackStorm の基本 基本を知るために幾つかの要素について説明していきます。 まず CLI で操作するために TOKEN を取得して環境変数にセットする必要があります。 上記で設定したユーザ名・パスワードを入力してください。 export ST2_AUTH_TOKEN=`st2 auth -t -p foo st2admin` Action Action はイベントが発生した際に実行できるアクションになります。早速アクションの一覧を取得してみましょう。 $ st2 action list +---------------------------------+---------+-------------------------------------------------------------+ | ref | pack | description | +---------------------------------+---------+-------------------------------------------------------------+ | chatops.format_execution_result | chatops | Format an execution result for chatops | | chatops.post_message | chatops | Post a message to stream for chatops | | chatops.post_result | chatops | Post an execution result to stream for chatops | <省略> | core.http | core | Action that performs an http request. | | core.local | core | Action that executes an arbitrary Linux command on the | | | | localhost. | | core.local_sudo | core | Action that executes an arbitrary Linux command on the | | | | localhost. | | core.remote | core | Action to execute arbitrary linux command remotely. | | core.remote_sudo | core | Action to execute arbitrary linux command remotely. | | core.sendmail | core | This sends an email | | core.windows_cmd | core | Action to execute arbitrary Windows command remotely. | <省略> | linux.cp | linux | Copy file(s) | | linux.diag_loadavg | linux | Diagnostic workflow for high load alert | | linux.dig | linux | Dig action | <省略> | st2.kv.get | st2 | Get value from datastore | | st2.kv.set | st2 | Set value in datastore | +---------------------------------+---------+-------------------------------------------------------------+ 上記のように Linux のコマンドや ChatOps, HTTP でクエリを投げるもの、Key Value の読み書きを行うモノまであります。 上記はかなり咲楽して貼り付けたので本来はもっと沢山のアクションがあります。 ...