仕事やプライベートで調べたことのメモ書きなど(@札幌)

仕事やプライベートで調べたこと、興味ある事のメモ書きです。2016年4月から札幌で働いてます。※このブログは個人によるもので、団体を代表するものではありません。

fluentdでWindowsのeventログを集めてmongoDBへ入れる、をやってみる

以下のページを参考にして、本当にできるかを試してみる編。
qiita.com

以前、とりあえずイベントログをfluentdで取ってこれてそうなところまではやったので、今度はそれをmongoに突っ込んでみます。
takumats.hatenablog.com


まずfluentdにmongoのプラグインをインストールします。で、別の投稿で、エラー発生&対応については言及しています。
takumats.hatenablog.com
また、vagrant上のmongoへ接続しており、これは以下の記事で言及しています。
takumats.hatenablog.com
これらを踏まえたうえで。
fluentdのconfigファイルは以下のような中身になりました。本設定により、eventログが、画面に出力されて、mongoにも入れられます。

<source>
  type winevtlog
  channel application
  pos_file C:/fluentd/log/eventlog.pos
  tag winevt.raw
</source>

#<match winevt.raw>
#  type record_modifier
#  char_encoding Windows-31J:utf-8
#  tag winevt.filtered
#</match>

<match winevt.raw>
  type copy
  <store>
    type stdout
  </store>
  <store>
    type mongo
    host localhost
    port 27777
    database fluentd
    collection test
  </store>
</match>

mongoへの接続は、teratermでやってるport転送で実施しています。

fluentdの起動は、コマンドラインからの起動なら以下のような感じ。

fluentd -c fluent_winevt_mongo.conf

fluentdを起動したら、別コマンドプロンプトを起動して以下のように実行してみます。

eventcreate /L Application /SO mytest /ID 1000 /T Information /D "This is a test!"

すると、fluentdを起動した画面には、以下のような表示が出ますよ!

2016-10-18 00:42:33 +0900 winevt.raw: {"channel":"application","record_number":"6591","time_generated":"2016-10-1
8 00:42:33 +0900","time_written":"2016-10-18 00:42:33 +0900","event_id":"1000","event_type":"information","event_
category":"0","source_name":"mytest","computer_name":"DESKTOP-82ICNJ6","user":"xxxxxx","description":"This is a t
est!\r\n"}

そして、mongodbには以下のような感じで入りました!
f:id:takumats:20161018005731p:plain

めでたし!