【问题标题】:how to send only specific files to remote server using rsyslog如何使用 rsyslog 仅将特定文件发送到远程服务器
【发布时间】:2018-11-29 07:21:02
【问题描述】:

我是 rsyslog 的新手。我有多个服务器(rsyslog 服务器)将 syslog 消息发送到远程服务器(syslog-ng 服务器)。 现在,我正在将所有内容发送到远程服务器。我想过滤掉特定文件中的日志并将其发送到远程服务器。

10-custom.conf - 这是我正在使用的自定义配置文件

#Forward specific logs to remote server
module(load="imfile")

input(type="imfile"
      file="/var/log/tomcat8/bar.log"
      Tag="bar:")

input(type="imfile"
      file="/var/log/tomcat8/foo.log"
      Tag="foo:")

input(type="imfile"
      file="/var/log/dpkg.log"
      Tag="dpkg:")

input(type="imfile"
      file="/var/log/syslog"
      Tag="syslog:")

input(type="imfile"
      file="/var/log/auth.log"
      Tag="auth:")

input(type="imfile"
      file="/var/log/kern.log"
      Tag="kern:")


#if $Tag == "catalina:" then @@remoteserver:port
:syslogtag, isequal, "catalina:" @@remoteserver:port
& stop

我正在尝试根据标签进行过滤并将其发送到远程服务器。我无法让这个工作。

进行此设置的最佳方法是什么?

提前致谢!

【问题讨论】:

标签: linux logging syslog rsyslog syslog-ng


【解决方案1】:

您可以将语句放在 rsyslog.conf 顶部,如下所述:

https://www.rsyslog.com/discarding-unwanted-messages/

例如,假设您只想将特定设施消息发送到远程日志服务器,例如所有相关的邮件消息,无论优先级如何,请将以下行添加到 rsyslog 配置文件:

mail.* @192.168.10.254:514

【讨论】:

    【解决方案2】:

    以下示例监视两个文件。如果您只需要一个,请删除第二个。如果您需要更多,请根据示例添加它们;)。此代码必须放在 /etc/rsyslog.conf 中(或您的发行版放置 rsyslog 配置文件的任何位置)。请注意,只需要指定实际需要的命令。第二个文件使用较少的命令并使用默认值。

    module(load="imfile" PollingInterval="10") #needs to be done just once
    
    # File 1
    input(type="imfile"
          File="/path/to/file1"
          Tag="tag1"
          Severity="error"
          Facility="local7")
    
    # File 2
    input(type="imfile"
          File="/path/to/file2"
          Tag="tag2")
    
    # ... and so on ... #
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-03
      • 2012-05-24
      • 2021-07-06
      • 2015-12-24
      • 1970-01-01
      • 2016-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多