フローインデクサー
flow-indexer indexes flows
Usage:
flow-indexer [command]
Available Commands:
compact Compact the database
daemon Start daemon
expandcidr Expand a CIDR range from those seen in the database
index Index flows
search Search flows
help Help about any command
Flags:
--dbpath="flows.db": Database path
-h, --help[=false]: help for flow-indexer
Use "flow-indexer [command] --help" for more information about a command.
$ export GOPATH=~/go
$ go get github.com/JustinAzoff/flow-indexer
$ cp ~/go/src/github.com/JustinAzoff/flow-indexer/example_config.json config.json
$ vi config.json # Adjust log paths and database paths.
インデクサーの構成は次のとおりです。
データベースを分割する方法の決定要因は、1日に表示される一意のIPの数です。毎月のインデックスから始めることをお勧めします。インデックス作成のパフォーマンスが月末までに大ヒットした場合は、毎日のインデックスに切り替えます。
indexallコマンドはfile_globを展開し、一致するログファイルをインデックスします。
$ ~/go/bin/flow-indexer indexall
初期インデックスが完了したら、デーモンを起動します。デーモンを起動すると、最近_FILE_GLOBが展開され、一致する最近作成されたログファイルがインデックスされます。
$ ~/go/bin/flow-indexer daemon
これを60秒のループで行い、最新の状態に保ちます。
$ curl -s 'localhost:8080/search?i=conn&q=1.2.3.0/24'
$ curl -s 'localhost:8080/dump?i=conn&q=1.2.3.0/24'
$ curl -s 'localhost:8080/stats?i=conn&q=1.2.3.0/24'
サービスとしてフローインデーサーを実行します
SystemDを使用してシステム上のサービスとしてFlow-Indexerを実行するには、提供されたFlow-Indexer.Serviceファイルを使用できます。
アップスタートを使用するシステムのサービスとしてFlow-Indexerを実行することを計画している場合は、Flow-IndexerのStdoutとStderrを適切にsyslog stdoutとStderrを使用して、非ルートユーザーとして実行するために、以下のようなconfファイルを検討することをお勧めします。
# flow-indexer - Flow Indexer
#
# flow-indexer is a service that indexes and allows retrieval of flows using bro logs
description "Flow Indexer Daemon"
start on runlevel [345]
stop on runlevel [!345]
setuid flowindexer
setgid flowindexer
exec /path/to/bin/flow-indexer daemon --config /path/to/flow-indexer/config.json 2>&1 | logger -t flow-indexer
too many open filesエラーを回避するために、Flow-Indexerが実行するユーザーがアクセスできるようにするユーザーを許可するオープンファイルの数を増やすことをお勧めします。これは、以下に示すように、 /etc/security/limits.conf limits.confにnofile設定を変更することで実行できます。
flowindexer soft nofile 65535
flowindexer hard nofile 65535
実際には実際には使用されていませんが、デーモンはFlow-Indexerを使用する推奨方法です。しかし、これらのコマンドはテストと開発に役立ちます。
./flow-indexer --dbpath /tmp/f/flows.db index /tmp/f/conn*
2016/02/06 23:36:51 /tmp/f/conn.00:00:00-01:00:00.log.gz: Read 4260 lines in 24.392765ms
2016/02/06 23:36:51 /tmp/f/conn.00:00:00-01:00:00.log.gz: Wrote 281 unique ips in 2.215219ms
2016/02/06 23:36:51 /tmp/f/conn.01:00:00-02:00:00.log.gz: Read 4376 lines in 24.186168ms
2016/02/06 23:36:51 /tmp/f/conn.01:00:00-02:00:00.log.gz: Wrote 310 unique ips in 1.495277ms
[...]
2016/02/06 23:36:51 /tmp/f/conn.22:00:00-23:00:00.log.gz: Read 7799 lines in 18.350788ms
2016/02/06 23:36:51 /tmp/f/conn.22:00:00-23:00:00.log.gz: Wrote 775 unique ips in 5.155262ms
2016/02/06 23:36:51 /tmp/f/conn.23:00:00-00:00:00.log.gz: Read 5255 lines in 15.296847ms
2016/02/06 23:36:51 /tmp/f/conn.23:00:00-00:00:00.log.gz: Wrote 400 unique ips in 2.910344ms
./flow-indexer --dbpath /tmp/f/flows.db index /tmp/f/conn*
2016/02/06 23:37:36 /tmp/f/conn.00:00:00-01:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.01:00:00-02:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.02:00:00-03:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.03:00:00-04:00:00.log.gz Already indexed
[...]
2016/02/06 23:37:36 /tmp/f/conn.20:00:00-21:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.21:00:00-22:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.22:00:00-23:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.23:00:00-00:00:00.log.gz Already indexed
./flow-indexer --dbpath /tmp/f/flows.db expandcidr 192.30.252.0/24
192.30.252.86
192.30.252.87
192.30.252.92
192.30.252.124
192.30.252.125
192.30.252.126
192.30.252.127
192.30.252.128
192.30.252.129
192.30.252.130
192.30.252.131
192.30.252.141
./flow-indexer --dbpath /tmp/f/flows.db search 192.30.252.0/24
/tmp/f/conn.03:00:00-04:00:00.log.gz
/tmp/f/conn.04:00:00-05:00:00.log.gz
/tmp/f/conn.06:00:00-07:00:00.log.gz
/tmp/f/conn.14:00:00-15:00:00.log.gz
/tmp/f/conn.18:00:00-19:00:00.log.gz
/tmp/f/conn.20:00:00-21:00:00.log.gz
/tmp/f/conn.22:00:00-23:00:00.log.gz