RHEL9 RainerScript if文 rsyslogの設定サンプル

環境
Red Hat Enterprise Linux release 9.2 (Plow)

書式
RainerScriptを使った設定の基本は、次のようにif文を使って条件を指定したうえで
action()文を使ってアクションを実行します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if (<条件式>) then {
action()
if (<条件式>) then { action()
if (<条件式>) then {
action()

条件式は、先の「if~then式を使った表記」と同じく
「==」や「!=」、「<>」、「<」、「>」、「<=」、「>=」、「and」、
「or」、「not」などが利用可能だ。

操作例1
メッセージ内に「arkgame」という文字列が含まれていた場合、これを「/var/log/arkgame.log」というファイルに出力

サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if ($msg contains "arkgame") then {
action(type="omfile" file="/var/log/arkgame.log")
}
if ($msg contains "arkgame") then { action(type="omfile" file="/var/log/arkgame.log") }
if ($msg contains "arkgame") then {
   action(type="omfile" file="/var/log/arkgame.log")
}

操作例2
メッセージの送信元(hostname)によって出力先ファイルを切り替えます。
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if ($msg contains "arkgame") then {
if ($hostname startswith "tokyo") {
action(type="omfile" file="/var/log/arkgame_tokyo.log")
} else if ($hostname startswith "oosaka") then {
action(type="omfile" file="/var/log/arkgame_oosaka.log")
} else {
action(type="omfile" file="/var/log/arkgame.log")
}
}
if ($msg contains "arkgame") then { if ($hostname startswith "tokyo") { action(type="omfile" file="/var/log/arkgame_tokyo.log") } else if ($hostname startswith "oosaka") then { action(type="omfile" file="/var/log/arkgame_oosaka.log") } else { action(type="omfile" file="/var/log/arkgame.log") } }
if ($msg contains "arkgame") then {
    if ($hostname  startswith "tokyo") {
        action(type="omfile" file="/var/log/arkgame_tokyo.log")
    } else if ($hostname startswith "oosaka") then {
        action(type="omfile" file="/var/log/arkgame_oosaka.log")
    } else {
       action(type="omfile" file="/var/log/arkgame.log")
    }
}

 

RHEL9

Posted by arkgame