【问题标题】:fluentd config to parse auth.log流利的配置来解析 auth.log
【发布时间】:2019-09-06 06:43:37
【问题描述】:

我正在使用以下配置让 fluentd 读取 auth.logs 并将其发送到弹性搜索,但我遇到了一个错误,提示模式不匹配并且日志未推送到 ES。

我正在使用fluentd syslog解析器插件rfc3164-pattern中定义的模式

<source>
  @type tail
  path /var/log/auth.log
  pos_file /var/log/auth.pos
  format /^\<(?<pri>[0-9]+)\>(?<time>[^ ]* {1,2}[^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\]) *(?<message>.*)$/
  tag authlog
</source>
<match authlog.**>
  @type elasticsearch
  hosts "ESHOST:PORT"
  logstash_format true
  logstash_prefix "server-authlogs"
  include_tag_key true
  flush_interval 5s
  logstash_dateformat %Y.%m.%d
  time_precision 3
</match>

输出错误:

2019-04-16 08:00:50 +0000 [警告]:#0 模式不匹配:“Apr 16 08:00:50 hostname-1415 sshd[15134]:pam_unix(sshd:session): 会话打开对于用户 ubuntu (uid = 0)“ 2019-04-16 08:00:50 +0000 [警告]:#0 模式不匹配:“Apr 16 08:00:50 hostname-1415 systemd-logind [1138]:用户 ubuntu 的新会话 10。”

【问题讨论】:

  • 这是一个正则表达式问题,不流畅。尝试使用fluentular.herokuapp.com 进行故障排除。请注意,您的错误示例中有 2 个错误。
  • 我找到了一个匹配 auth.log 的正则表达式。感谢指导。
  • 感谢回帖,很有用

标签: elasticsearch logging kubernetes fluentd efk


【解决方案1】:

对于那些正在寻找类似东西的人来说,这里的配置很好用。

<source> 
 type tail 
 path /var/log/foo/auth.log 
 pos_file /var/log/auth.pos 
 tag authlog
 format /^(?<time>[^ ]* {1,2}[^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?(?:[^\:]*\:)? *(?<message>.*)$/ 
</source>
<match authlog.**>
 @type elasticsearch
 hosts "ESHOST:PORT"
 logstash_format true
 logstash_prefix "server-authlogs"
 include_tag_key true
 flush_interval 5s
 logstash_dateformat %Y.%m.%d
 time_precision 3
</match>

对于 auth.log 模式:

Apr 16 18:02:02 host-1415 sshd[11111]: Accepted password for ubuntu from 111.11.111.11 port 11111 ssh2

【讨论】:

    【解决方案2】:

    使用parser_syslog怎么样? 如果 /var/log/auth.log 有 syslog 格式(RFC3164)。

    <source> 
      @type tail 
      path /var/log/auth.log 
      pos_file /var/log/auth.pos 
      tag authlog
      <parse>
        @type syslog
        message_format rfc3164
        with_priority false
      </parse>
    </source>
    

    【讨论】:

      猜你喜欢
      • 2019-09-26
      • 1970-01-01
      • 2019-11-26
      • 1970-01-01
      • 2015-04-11
      • 2021-08-20
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      相关资源
      最近更新 更多