正如@baudsp 所建议的,您需要为 BIND9 日志创建自定义模式。为此,您首先需要了解每个字段的实际含义,
查询日志条目首先以@0x 格式报告客户端对象标识符。接下来,它会报告客户端的 IP 地址和端口号,以及查询名称、类和类型。接下来,它报告是否设置了 Recursion Desired 标志(+ 如果设置,- 如果未设置),如果查询已签名 (S),EDNS 与 EDNS 版本号 (E(#)) 一起使用,如果 TCP已使用 (T),如果设置了 DO(DNSSEC Ok) (D),如果设置了 CD(禁用检查)(C),如果收到了有效的 DNS 服务器 COOKIE (V),或者如果 DNS COOKIE 选项没有存在有效的服务器 COOKIE (K)。在此之后,报告发送查询的目标地址。注意:这反映了 BIND 9.11.0 的行为。
所以对于你的 BIND9 查询日志,
17-Feb-2018 23:06:56.326 queries: info: client @0x563d72c3ea20 172.26.0.1#34564 (test.example.com): query: test.example.com IN A +E(0)K (172.26.0.3)
模式是,
%{MONTHDAY:day}[-]%{MONTH}[-]%{YEAR}\s*%{TIME}\s*%{WORD:queries}[:]\s*%{WORD:info}[:]\s*%{WORD:client}\s*%{DATA:client_data}\s*%{IP:client_ip}[#]%{NUMBER:client_port}\s*\(%{HOSTNAME}\)[:]\s*query:\s*%{HOSTNAME:query_value}\s*%{WORD}\s*%{WORD:record_type}\s*%{NOTSPACE:misc}\s*\(%{IP:destination}\)
这将生成以下输出,
{
"day": [
[
"27"
]
],
"MONTH": [
[
"Feb"
]
],
"YEAR": [
[
"2018"
]
],
"TIME": [
[
"23:06:56.326"
]
],
"HOUR": [
[
"23"
]
],
"MINUTE": [
[
"06"
]
],
"SECOND": [
[
"56.326"
]
],
"queries": [
[
"queries"
]
],
"info": [
[
"info"
]
],
"client": [
[
"client"
]
],
"client_data": [
[
"@0x563d72c3ea20"
]
],
"client_ip": [
[
"172.26.0.1"
]
],
"IPV6": [
[
null,
null
]
],
"IPV4": [
[
"172.26.0.1",
"172.26.0.3"
]
],
"client_port": [
[
"34564"
]
],
"BASE10NUM": [
[
"34564"
]
],
"HOSTNAME": [
[
"test.example.com"
]
],
"query_value": [
[
"test.example.com"
]
],
"WORD": [
[
"IN"
]
],
"record_type": [
[
"A"
]
],
"misc": [
[
"+E(0)K"
]
],
"destination": [
[
"172.26.0.3"
]
]
}