如何在logstash中添加beats输入的主机名?

问题描述 投票:0回答:1

让我解释一下我现有的结构,我有4台服务器(Web服务器,API服务器,数据库服务器,SSIS Severs),并在这4台服务器上安装了filebeat和winlog,从那里我得到了所有的日志在我的logstash中,但这里有一个问题,我得到的每一个日志都在消息正文中,对于一些消息,我很难写出正确的GROK模式,有什么办法可以让我从Kibana中得到模式(仅供参考,目前我把所有的日志存储在弹性搜索中,我可以通过Kibana看到。

我的Logstash配置是这样的

1. Api-Pipeline
input {
  beats {
    host => "IP Address where my filebeat (API Server) is running"
    port => 5044
  }
}

2. DB Pipeline
input {
      beats {
        host => "IP Address where my filebeat (Database Server) is running"
        port => 5044
      }
    }

我只用端口的时候还能用,一加主机就不工作了。谁能帮帮我。

下面我想实现

enter image description here

我在这里做了修改,这是否可行,因为我需要编写冗长的过滤器,这就是为什么我想在单独的文件中加入以下内容

Filebeat.yml on API Server
-----------------------------------------------------------------------------------------
filebeat.inputs:
- type: log
  source: 'ApiServerName' // MyAPIServerName(Same Server Where I have installed filebeat)
  enabled: true
  paths:
    - C:\Windows\System32\LogFiles\SMTPSVC1\*.log
    - E:\AppLogs\*.json

scan_frequency: 10s
ignore_older: 24h

filebeat.config.modules:
  path: C:\Program Files\Filebeat\modules.d\iis.yml
  reload.enabled: false

setup.template.settings:
  index.number_of_shards: 3

setup.kibana:
  host: "kibanaServerName:5601"

output.logstash:
  hosts: ["logstashServerName:5044"]



Logstash Configuration
----------------------------------------------------------------
Pipeline.yml

- pipeline.id: beats-server
  config.string: |
    input { beats { port => 5044 } }
    output {
        if [source] == 'APISERVERNAME' {
          pipeline { send_to => apilog }
        } else if [source] == 'DBSERVERNAME' {
          pipeline { send_to => dblog }
        }
        else{
          pipeline { send_to => defaultlog }
        }
    }

- pipeline.id: apilog-processing
  path.config: "/Logstash/config/pipelines/apilogpipeline.conf"

- pipeline.id: dblog-processing
  path.config: "/Logstash/config/pipelines/dblogpipeline.conf"

- pipeline.id: defaultlog-processing
  path.config: "/Logstash/config/pipelines/defaultlogpipeline.conf"



1. apilogpipeline.conf
----------------------------------------------------------
input { 
    pipeline { 
        address => apilog 
    } 
}
output {
    file {
        path => ["C:/Logs/apilog_%{+yyyy_MM_dd}.log"]
    }
}



2. dbilogpipeline.conf
---------------------------------------------------------
input { 
    pipeline { 
        address => dblog 
    } 
}
output {
    file {
        path => ["C:/Logs/dblog_%{+yyyy_MM_dd}.log"]
    }
}


3. defaultlogpipeline.conf
---------------------------------------------------------
input { 
    pipeline { 
        address => defaultlog 
    } 
}
output {
    file {
        path => ["C:/Logs/defaultlog_%{+yyyy_MM_dd}.log"]
    }
} 
elasticsearch logstash kibana filebeat
1个回答
0
投票

它的工作原理是相反的,即不是Logstash连接到Filebeat,而是Filebeat向Logstash发送数据。所以在你的输入部分,主机需要是Logstash运行的主机名称。

beats {
  host => "logstash-host"
  port => 5044
}

然后在你的Filebeat配置中,你需要配置的是 Logstash输出 像这样。

output.logstash:
  hosts: ["logstash-host:5044"]

既然你有多个Filebeat源,并且想给每个源建立一个专门的管道,你可以做的是定义一个管道。自定义字段 在每个Filebeat配置中(例如 source: db, source: api-server等),然后在Logstash中,你可以根据这些值应用不同的逻辑。

filebeat.inputs:
- type: log
  fields:
    source: 'APISERVERNAME'
  fields_under_root: true

在 Logstash 中,你可以利用 条件管道与管道之间的通信 以便根据事件数据应用不同的逻辑。

在最新的链接中,你可以看到一个例子。配电盘 这几乎是你所追求的。

© www.soinside.com 2019 - 2024. All rights reserved.