if ($programname == "nginx") then {
action(type="omfwd" target="logserver" port="514")
}
*.* action(type="omfwd" target="logserver" port="514")
この場合、
nginxログは if に一致
その後 *.* にも一致
結果として、nginxログは2回送信されます。
正しい書き方:stop を必ず入れる
if ($programname == "nginx") then {
action(type="omfwd" target="logserver" port="514")
stop
}
*.* action(type="omfwd" target="logserver" port="514")
stop は、
「このログの処理はここで終了」
という意味です。
これにより nginx ログは if ブロック内だけで処理されます。
条件分岐でよく使う判定要素
programname
if ($programname == "sshd") then { ... }
facility / severity
if ($syslogfacility-text == "auth") then { ... }
文字列一致
if ($msg contains "error") then { ... }
複数条件も可能です。
if ($programname == "nginx" and $msg contains "error") then { ... }
条件分岐を安全に書く設計パターン
パターン1:特定ログだけ先に処理
if ($programname == "nginx") then {
action(...)
stop
}
if ($programname == "mysql") then {
action(...)
stop
}
*.* action(...)
「例外 → 共通処理」の順で書くのが鉄則です。
パターン2:送信先ごとに完全分離
if ($programname == "nginx") then {
action(type="omfwd" target="web-log")
stop
}
if ($programname == "mysql") then {
action(type="omfwd" target="db-log")
stop
}