rsyslog和過濾規則

2022-06-14 18:54:08 字數 1852 閱讀 9253

vim /etc/rsyslog.conf

$includeconfig /etc/rsyslog.d/*.conf

# 個人建議,將所有的rule都配置在該目錄下,在/etc/rsyslog.conf中不寫rule

配置檔案/etc/rsyslog.conf主要有3個部分

modules :模組

global drictives :全域性設定

rules:規則

$msg

if $msg contains '%asa-' and $syslogseverity <= '6' then

任何rsyslog生成的日誌都可以根據需要使用模板進行格式化,要建立模板,使用如下指令

$template template_name,"text %property% more text", [option]

這裡的$template指令表明了接下來的內容定義了乙個模板,template_name是模板的名稱,接下來雙引號之間的內容為模板的內容。

這裡還有乙個 option , 它指定了模板的功能,支援選項為sqlstdsql,在使用資料庫儲存的時候會用到。
模板可以用來生成動態檔名,就如之前所述,在使用動態檔名的時候,需要在 action 中的模板名稱前增加?表明該檔名是動態生成的。

例如:

$template dynamicfile,"/var/log/test_logs/%timegenerated%-test.log"

*.* ?dynamicfile

timegenerated屬性從日誌資訊中提取出訊息的時間戳,這樣可以為每個日誌生成唯一檔名稱。

以下是一些簡單屬性的示例:

以下屬性獲取系統日誌訊息的整個訊息文字:

%msg%

以下屬性獲取系統日誌訊息的訊息文字的前兩個字元:

%msg:1:2%

以下屬性獲取系統日誌訊息的整個訊息文字,並刪除其最後乙個換行符:

%msg ::: drop-last-lf%

以下屬性獲取接收到syslog訊息時生成的時間戳的前10個字元,並根據rfc 3999日期標準對其進行格式化。

%timegenic:1:10:date-rfc3339%

#  %syslogpriority-text% : syslog priority

# %syslogfacilityt-text% : syslog facility

# %timegenerated% : timestamp when the message was received

# %hostname% : hostname

# %syslogtag% : tag

# %msg% : the message sent to syslog

所有的屬性參考:

logrotate配置檔案

logrotate的配置檔案為/etc/logrotate.conf

自定義的log rotation配置檔案在/etc/logrotate.d目錄下

比較全的總結:

Linux rsyslog和過濾規則

vim etc rsyslog.conf includeconfig etc rsyslog.d conf個人建議,將所有的rule都配置在該目錄下,在 etc rsyslog.conf中不寫rule modules 模組 global drictives 全域性設定 rules 規則 msg if...

WinPcap過濾規則

下面對winpcap的過濾表示式語法進行一下簡要的介紹,其中關鍵字用黑體字表示。1 表示式支援邏輯操作符,可以使用關鍵字 and or not對子表示式進行組合,同時支援使用小括號。2 基於協議的過濾要使用協議限定符,協議限定符可以為ip arp rarp tcp udp等。3 基於mac位址的過濾...

Wireshark過濾規則

一 ip過濾 包括 ip或者目標ip等於某個ip 比如 ip.src addr 192.168.0.208 or ip.src addr eq 192.168.0.208 顯示 ip ip.dst addr 192.168.0.208 or ip.dst addr eq 192.168.0.208 ...