LoginSignup
7
5

【Windows】イベントログをLinuxに転送する

Last updated at Posted at 2020-07-17

WindowsのイベントログをLinuxに転送してログ管理を一元化してぇ
って時の設定。

Windowsに「NXlog」というツールを導入します。
ダウンロードはコチラから↓
https://nxlog.co/products/nxlog-community-edition/download

Windows版を選んでサーバに配置し、インストールします。
20180611172950.png
選択項目は特になく、インストールも一瞬で終わります。


完了後、設定ファイルを編集します。
C:\Program Files (x86)\nxlog\conf\nxlog.conf

ファイル内容を以下のように修正します。 

nxlog.conf
## This is a sample configuration file. See the nxlog reference manual about the
## configuration options. It should be installed locally and is also available
## online at http://nxlog.org/docs/

## Please set the ROOT to the folder your nxlog was installed into,
## otherwise it will not start.

#define ROOT C:\Program Files\nxlog
define ROOT C:\Program Files (x86)\nxlog

Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
LogFile %ROOT%\data\nxlog.log

<Extension syslog>
Module xm_syslog
</Extension>

<Extension charconv>
Module xm_charconv
AutodetectCharsets shift_jis, utf-8
</Extension>

<Extension json>
Module xm_json
</Extension>

<Input in>
Module im_msvistalog
Query <QueryList>\
<Query Id="0">\
<Select Path="Application">*[System[(Level=1 or Level=2 or Level=3)]]</Select>\
<Select Path="System">*[System[(Level=1 or Level=2 or Level=3)]]</Select>\
<Select Path="Security">*[System[(Level=1 or Level=2 or Level=3)]]</Select>\
</Query>\
</QueryList>
Exec $raw_event = "json=" + to_json(); $SyslogFacilityValue = 21;
Exec convert_fields("utf-8", "utf-8");
</Input>

<Processor t>
Module pm_transformer
OutputFormat syslog_bsd
Exec $Message=(": "+$raw_event);
</Processor>

<Output out>
Module om_udp
Host xxx.xxx.xxx.xxx
Port 514
</Output>

<Route r>
Path in => t => out
</Route>

"Output out"の箇所で送りたいサーバのIPアドレスとポートを指定してください。

"QueryList"

Select Path="Application"
Select Path="System"
Select Path="Security"
で各イベントログの出力とLevelの指定ができます。
消すとそのイベントは吐かれません。レベルは参考以下

クリティカル=Level1
エラー=Level2
警告=Level3
情報=Level4


次は転送先のLinuxサーバの設定です。rsyslog.confに以下を追記

rsyslog.conf
## Remote host logging
:fromhost-ip, isequal, "xxx.xxx.xxx.xxx" /var/log/xxxx.log
& stop

NXLOGサーバのIPアドレスとログの出力先を指定してください。
他にも、このファイルを編集することでファシリティを絞ったり出力形式を変えたりできます。


最後に
Windowsでnxlogサービスを再起動
Linuxでrsyslog再起動

systemctl restart rsyslog

指定したログファイルが作成され、イベントログの内容が吐かれているはずです。
こんな感じで

Jul 3 11:00:29 dango NRPE_NT[0]: [err] : json={"EventTime":"2018-07-03 11:00:28","Hostname":"dango","Keywords":36028797018963968,"EventType":"ERROR","SeverityValue":4,"Severity":"ERROR","EventID":3,"SourceName":"NRPE_NT","Task":4,"RecordNumber":8618,"ProcessID":0,"ThreadID":0,"Channel":"Application","ERROR_EVT_UNRESOLVED":true,"EventReceivedTime":"2018-07-03 11:00:29","SourceModuleName":"in","SourceModuleType":"im_msvistalo 

なかなかに見づらいですが、ここはrsyslog.confをいじれば整えられます。


以上ィ

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