6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Kibana上のアクセスログをIPレンジで見る為、ElasticsearchにIP Typeフィールドを追加してみるといい感じ

Posted at

アクセスログをKibanaで見る時に、特定レンジのIPでフィルタかけれたら色々便利なのではという同僚からの意見を受け、試してみたのでシェア!

Elasticsearchのフィールドのスキーマ変更(template)

まずは、Elasticsearch側のテンプレートで、クライアントIPを定義しているフィールドに対しIP Typeを追加

下記例でいくと、c-ip.iptypeでIP Typeのレンジクエリ等を発行出来る。

        "c-ip" : { "type":"multi_field",
          "fields":{
            "c-ip":{ "type":"string","index":"not_analyzed"},
            "iptype":{ "type":"ip"}
          }
        }

templateを更新(反映は、次回インデックス作成時 ※アクセスログなので日単位で)

手順は、下記を読み替える

$ curl -XPUT localhost:9200/_template/[テンプレート名] -d "`cat [json設置場所]`"
# 反映を確認
$ curl -XGET "localhost:9200/_template/[テンプレート名]?pretty" 

インデックスを日単位で更新してなかったり、即時反映したい場合は下記参照に直接mapping更新のAPIを突けば出来ます。

http://kobitosan.hatenablog.com/entry/2014/12/23/103746

実際にレンジクエリでKibana上で可視化してみる

IP Typeのレンジクエリは、Kibanaだと下記形式で使えた(dateと同じ)

c-ip.iptype:[開始IP TO 終了IP]

適当な試験環境で、レンジクエリと実際のクライアントIP毎のアクセス量のtermの集計値が合っているかを確認した↓

Kibana_3_-_New_Dashboard.png

特定ISPから不正アクセス来た時にどのページ見てるとか、ある程度IPで絞れるところから何かされてるのを検知したい時に、クライアントIPにレンジクエリ使えれば便利そう!

6
7
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
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?