官术网_书友最值得收藏!

3.3 Postfix日志

Postfix是Linux平臺上最常用的郵件服務(wù)器軟件。郵件服務(wù)的運維復(fù)雜度一向較高,在此提供一個針對Postfix日志的解析處理方案。方案出自:https://github.com/whyscream/postfix-grok-patterns。

因為Postfix默認(rèn)通過syslog方式輸出日志,所以可以選擇通過rsyslog直接轉(zhuǎn)發(fā)給Logstash,也可以由Logstash讀取rsyslog記錄的文件。

Postfix會根據(jù)實際日志的不同,主動設(shè)置好不同的syslogtag,有anvil、bounce、cleanup、dnsblog、local、master、pickup、pipe、postdrop、postscreen、qmgr、scache、sendmail、smtp、lmtp、smtpd、tlsmgr、tlsproxy、trivial-rewrite和discard等20個不同的后綴,而在Logstash中,syslogtag通常被解析為program字段。本節(jié)以第一種anvil日志的處理配置作為示例:

input {
    syslog { }
}
filter {
    if [program] =~ /^postfix.*\/anvil$/ {
        grok {
            patterns_dir   =>“/etc/logstash/patterns.d”
            match          => [ “message”, “%{POSTFIX_ANVIL}” ]
            tag_on_failure => [ “_grok_postfix_anvil_nomatch” ]
            add_tag        => [ “_grok_postfix_success” ]
        }
    }
    mutate {
        convert => [
        “postfix_anvil_cache_size”, “integer”,
        “postfix_anvil_conn_count”, “integer”,
        “postfix_anvil_conn_rate”, “integer”,
        ]
    }
}

配置中使用了一個叫POSTFIX_ANVIL的自定義grok正則,該正則及其相關(guān)正則內(nèi)容如下所示。將這段grok正則保存成文本文件,放入/etc/logstash/patterns.d/目錄即可使用。

POSTFIX_TIME_UNIT %{NUMBER}[smhd]
POSTFIX_ANVIL_CONN_RATE statistics: max connection rate %{NUMBER:postfix_anvil_conn_
    rate}/%{POSTFIX_TIME_UNIT:postfix_anvil_conn_period} for \(%{DATA:postfix_
    service}:%{IP:postfix_client_ip}\) at %{SYSLOGTIMESTAMP:postfix_anvil_
    timestamp}
POSTFIX_ANVIL_CONN_CACHE statistics: max cache size %{NUMBER:postfix_anvil_
    cache_size} at %{SYSLOGTIMESTAMP:postfix_anvil_timestamp}
POSTFIX_ANVIL_CONN_COUNT statistics: max connection count %{NUMBER:postfix_
    anvil_conn_count} for \(%{DATA:postfix_service}:%{IP:postfix_client_ip}\) at
    %{SYSLOGTIMESTAMP:postfix_anvil_timestamp}
POSTFIX_ANVIL %{POSTFIX_ANVIL_CONN_RATE}|%{POSTFIX_ANVIL_CONN_CACHE}|%{POSTFIX_
    ANVIL_CONN_COUNT}

其余19種Postfix日志的完整grok正則和Logstash過濾配置,讀者可以通過https://github.com/whyscream/postfix-grok-patterns獲取。

主站蜘蛛池模板: 鄂伦春自治旗| 蓝山县| 元朗区| 阆中市| 潮州市| 汝南县| 缙云县| 天长市| 临泽县| 中牟县| 潞城市| 武汉市| 罗城| 加查县| 韩城市| 同心县| 曲阳县| 堆龙德庆县| 湄潭县| 长汀县| 彭州市| 青浦区| 汉中市| 常宁市| 小金县| 嘉义市| 长岛县| 兴安县| 喀喇沁旗| 延川县| 高邮市| 静乐县| 健康| 绥德县| 昆明市| 综艺| 开江县| 平阳县| 陵川县| 东台市| 虎林市|