logstash混合json和纯含量

发布于 2025-01-29 22:31:07 字数 1074 浏览 4 评论 0原文

我将LogStash用作系统列出继电器,将数据转发到Graylog并将数据写入文件。

我使用DNS过滤器模块将IP替换为FQDN,在此之后,我无法将原始内容写入文件,IP为“ JSON-ED”。

我得到的:

2022-05-17T15:17:01.580175Z {ip=vm2345.lab.com} <86>1 2022-05-17T17:17:01.579496+02:00 vm2345 CRON 2057538 - -  pam_unix(cron:session): session closed for user root

我想得到什么:

2022-05-17T15:17:01.580175Z vm2345.lab.com <86>1 2022-05-17T17:17:01.579496+02:00 vm2345 CRON 2057538 - -  pam_unix(cron:session): session closed for user root

我的配置:

input {
  syslog {
    port => 514
    type => "rsyslog"
  }
}

filter {
    if [type] == "rsyslog" {
        dns {
            reverse => [ "[host][ip]" ]
            action => "replace"
        }
    }
}

output {
  if [type] == "rsyslog" {
    gelf {
      host => "graylog.lab.com"
      port => 5516
    }
    file {
      path => "/data/%{+YYYY}/%{+MM}/%{+dd}/%{[host][ip]}/%{[host][ip]}_%{{yyyy_MM_dd}}.log"
      codec => "line"
    }
    stdout { }
  }
}

处理此问题的最佳方法是什么?

I use logstash as a syslog relay, it forwards the data to a graylog and writes data to a file.

I use the dns filter module to replace the IP with the FQDN and after this I can't write raw content to file, the IP is "json-ed".

What I get :

2022-05-17T15:17:01.580175Z {ip=vm2345.lab.com} <86>1 2022-05-17T17:17:01.579496+02:00 vm2345 CRON 2057538 - -  pam_unix(cron:session): session closed for user root

What I want to get :

2022-05-17T15:17:01.580175Z vm2345.lab.com <86>1 2022-05-17T17:17:01.579496+02:00 vm2345 CRON 2057538 - -  pam_unix(cron:session): session closed for user root

My config :

input {
  syslog {
    port => 514
    type => "rsyslog"
  }
}

filter {
    if [type] == "rsyslog" {
        dns {
            reverse => [ "[host][ip]" ]
            action => "replace"
        }
    }
}

output {
  if [type] == "rsyslog" {
    gelf {
      host => "graylog.lab.com"
      port => 5516
    }
    file {
      path => "/data/%{+YYYY}/%{+MM}/%{+dd}/%{[host][ip]}/%{[host][ip]}_%{{yyyy_MM_dd}}.log"
      codec => "line"
    }
    stdout { }
  }
}

What's the best way to handle this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2025-02-05 22:31:07

当您使用codec =&gt时; line, there is no default setting for the @format option, so the

codec => line { format => "%{@timestamp} %{[host][ip]} %{message}" }

When you use codec => line, there is no default setting for the @format option, so the codec calls, .to_s on the event. The toString method for an event concatenates the @timestamp, the [host] field, and [message] field. You want the [host][ip] field, not the [host] field (which is an object) so tell the codec that

codec => line { format => "%{@timestamp} %{[host][ip]} %{message}" }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文