如何在 elasticsearch 中读取 /var/log/wtmp 日志

How to read /var/log/wtmp logs in elasticsearch

我正在尝试从 elasticsearch

中的 /var/log/wtmp 读取访问日志

使用 last -F /var/log/wtmp

登录框后我可以读取文件

我有 logstash 运行 并将日志发送到 elasticsearch,这里是 logstash conf 文件。

input {
  file {
    path => "/var/log/wtmp"
    start_position => "beginning"
  }
}

output {
  elasticsearch {
    host => localhost
    protocol => "http"
    port => "9200"
  }
}

elasticsearch 中显示的是

G

使用 less 打开文件后,我只能看到二进制数据。 现在 logstash 无法理解这些数据。 像下面这样的 logstash 文件应该可以正常工作 -

input { 
  pipe {
    command => "/usr/bin/last -f /var/log/wtmp"
  }
}

output {
    elasticsearch {
    host => localhost
    protocol => "http"
    port => "9200"
    }
}

Vineeth 的回答是正确的,但以下更清洁的配置也适用:

input { pipe { command => "last" } }

last /var/log/wtmplast完全一样


utmp, wtmp, btmp 是用于跟踪用户登录和注销的 Unix 文件。它们不能直接读取,因为它们不是常规文本文件。但是,有 last 命令以纯文本显示 /var/log/wtmp 的信息。

$ last --help

Usage:
 last [options] [<username>...] [<tty>...]

I can read the file when logged into the box by using last -F /var/log/wtmp

我对此表示怀疑。 -F 标志的作用:

-F, --fulltimes      print full login and logout times and dates

因此,last -F /var/log/wtmp 会将 /var/log/wtmp 解释为用户名,并且不会打印任何登录信息。

-f 标志的作用:

-f, --file <file>    use a specific file instead of /var/log/wtmp