LoginSignup
4
5

More than 3 years have passed since last update.

Amazon Elasticsearch Service で Alarm (Open Distro)

Last updated at Posted at 2019-05-14

やること

Amazon ESにCloudTrailのログを流し、test_user1のログイン成功を検知したらアラートを飛ばします

これをOpenDistroのAlartingを使ってやる

事前準備

Amazon ESはv6.5でセットアップし、CloudTrailのログを流し込んでいます。
Slackを用意してWebhook URLを控えておく

  • Amazon ES: v6.5

画面はKibanaで「eventType: AwsConsoleSignIn AND userIdentity.userName: test_user1 AND responseElements.ConsoleLogin: Success」でフィルタをして"test_user1"というIAMユーザーでログインに成功したデータを検索しています。

スクリーンショット 0031-05-14 17.28.46.png

OpenDistro Alarmの設定

Destination

Kibanaの左側メニューで"Alerting"をクリックし、[Add Destination]をクリックします。

スクリーンショット 0031-05-14 17.32.05.png

今回は通知先をSlackとします。以下の情報いれて[Create]をクリック

  • Name: test_trigger
  • Type: Slack
  • Webhook URL: 自身のSlackのやつ

スクリーンショット 0031-05-14 17.33.49.png

カスタムWebhook含め送り先は選べます

スクリーンショット 0031-05-14 17.34.52.png

これでDestinationは完成

Monitor

"Monitor"をクリックし[Create monitor]をクリック

スクリーンショット 0031-05-14 17.37.12.png

以下を入力

  • Monitor name: test_monitor
  • Every: 5

スクリーンショット 0031-05-14 17.38.30.png

以下を入力し、右下の[Create]をクリックする

  • How do you want to define the monitor?: Define using extraction query
  • Index: cwl-2019.05.14
  • Define extraction query: 以下のクエリを入力
{
    "size": 0,
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "eventType": {
                            "query": "AwsConsoleSignIn",
                            "operator": "AND",
                            "prefix_length": 0,
                            "max_expansions": 50,
                            "fuzzy_transpositions": true,
                            "lenient": false,
                            "zero_terms_query": "NONE",
                            "auto_generate_synonyms_phrase_query": true,
                            "boost": 1
                        }
                    }
                },
                {
                    "match": {
                        "userIdentity.userName": {
                            "query": "test_user1",
                            "operator": "AND",
                            "prefix_length": 0,
                            "max_expansions": 50,
                            "fuzzy_transpositions": true,
                            "lenient": false,
                            "zero_terms_query": "NONE",
                            "auto_generate_synonyms_phrase_query": true,
                            "boost": 1
                        }
                    }
                },
                {
                    "match": {
                        "responseElements.ConsoleLogin": {
                            "query": "Success",
                            "operator": "AND",
                            "prefix_length": 0,
                            "max_expansions": 50,
                            "fuzzy_transpositions": true,
                            "lenient": false,
                            "zero_terms_query": "NONE",
                            "auto_generate_synonyms_phrase_query": true,
                            "boost": 1
                        }
                    }
                }
            ],
            "filter": [
                {
                    "range": {
                        "@timestamp": {
                            "from": "now-10m",
                            "to": null,
                            "include_lower": true,
                            "include_upper": true,
                            "boost": 1
                        }
                    }
                }
            ],
            "adjust_pure_negative": true,
            "boost": 1
        }
    },
    "aggregations": {}
}

スクリーンショット 0031-05-14 17.40.52.png

Trigger

Create Trigger の画面になるので、以下の値を入力する

  • Trigger name: test_trigger1

スクリーンショット 0031-05-14 17.45.20.png

Trigger conditionがhit件数>0となっている。右下の[Run]をクリックしfalseであることを確認(今は10分以内のログインがなく0件なのでfalse)

スクリーンショット 0031-05-14 17.47.12.png

Action

以下を入力し、[Add action]をクリックする

  • Action name: test_action1
  • Destination name: test_general - (Slack)
  • Message subject: login success! test_user1

※入力が終わったら、右下の"Send test message"でWebhookの確認をしてもよい

スクリーンショット 0031-05-14 17.52.28.png

右下の"Send test message"でWebhookの確認をした結果のSlack画面

スクリーンショット 0031-05-14 18.09.25.png

アクションができたら右下の[Create]をクリックする

スクリーンショット 0031-05-14 17.54.36.png

作成した"test_monitor1"

スクリーンショット 0031-05-14 17.56.11.png

テスト

test_user1でAWSに2回ほどログイン/ログアウトを行いしばらく待つ

test_monitor1の画面でアラートが発生したことがわかる

スクリーンショット 0031-05-14 18.13.01.png

Slackにも飛んできた

スクリーンショット 0031-05-14 18.11.01.png

KibanaのDiscoverでも確認できる

スクリーンショット 0031-05-14 18.11.31.png

今回だとDefine extraction queryを直近10分でクエリしているので、10分経つとAlertのStateはCompletedとなる

Dashboardの画面

スクリーンショット 0031-05-14 18.20.26.png

Monitor側の画面

スクリーンショット 0031-05-14 18.22.31.png

4
5
1

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
4
5