input {
udp {
port => "9652"
type => "rsys"
}
udp {
# rsyslog使用514/udp,但是监听1000以下端口需要root权限,故而宿主机514转发至docker内高端口,应对不能设置log端口的网络设备
port => "9651"
type => "hw"
}
udp {
port => "9650"
type => "h3c"
}
}
filter {
if [type] == "rsys" {
grok {
match => {
"message" => "<%{BASE10NUM:syslog_pri}>%{SYSLOGTIMESTAMP:timestamp} (?<hostname>.*?) %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:message}"
}
remove_field => [ "timestamp" ]
overwrite => ["message"]
}
}
else if [type] == "h3c" {
grok {
match => {
"message" => "<%{BASE10NUM:syslog_pri}>%{SYSLOGTIMESTAMP:timestamp} %{YEAR:year} %{DATA:hostname} %%%{DATA:vvmodule}/%{POSINT:severity}/%{DATA:digest}: %{GREEDYDATA:message}"
}
remove_field => [ "year" ]
add_field => {
"severity_code" => "%{severity}"
}
overwrite => ["message"]
}
}
else if [type] == "hw" {
grok {
match => {
"message" => "<%{BASE10NUM:syslog_pri}>(?<timestamp>.*? .*?) %{DATA:hostname} %%%{DATA:ddModuleName}/%{POSINT:severity}/%{DATA:Brief}:%{GREEDYDATA:message}"
}
remove_field => [ "timestamp" ]
add_field => {
"severity_code" => "%{severity}"
}
overwrite => ["message"]
}
}
mutate {
gsub => [
"severity", "0", "Emergency",
"severity", "1", "Alert",
"severity", "2", "Critical",
"severity", "3", "Error",
"severity", "4", "Warning",
"severity", "5", "Notice",
"severity", "6", "Informational",
"severity", "7", "Debug"
]
}
}
output {
elasticsearch {
hosts => [ "elasticsearch:9200" ]
}
}
if [type] == "cisco"{
grok{
match => {
"message" => "<%{BASE10NUM:syslog_pri}>%{NUMBER:log_sequence}: %{SYSLOGTIMESTAMP:timestamp}: %%{DATA:facility}-%{POSINT:severity}-%{CISCO_REASON:mnemonic}: %{GREEDYDATA:message}"
}
add_field => {
"severity_code" => "%{severity}"
}
overwrite => ["message"]
}
}
# 自动生成grok表达式网站/测试grok表达式网站
# http://grokconstructor.appspot.com/do/match
# https://grokdebug.herokuapp.com/
version: "3.5"
services:
elasticsearch:
image: elasticsearch:6.5.0
restart: always
#ports:
# - "9200:9200"
environment:
discovery.type: single-node
ES_JAVA_OPTS: -Xms512m -Xmx512m
container_name: elasticsearch
hostname: elasticsearch
volumes:
- ./elasticsearch_data:/usr/share/elasticsearch/data:rw
logstash:
image: logstash:6.5.0
restart: always
ports:
- "9652:9652/udp"
- "9650:9650/udp"
- "514:9651/udp" # rsyslog使用514/udp,但是监听1000以下端口需要root权限,故而宿主机514转发至docker内高端口,应对不能设置log端口的网络设备
depends_on:
- elasticsearch
container_name: logstash
hostname: logstash
command: logstash -f /etc/logstash.conf
volumes:
- ./logstash.conf:/etc/logstash.conf:ro
kibana:
image: kibana:6.5.0
restart: always
ports:
- "5601:5601"
environment:
ELASTICSEARCH_URL: http://elasticsearch:9200
depends_on:
- elasticsearch
container_name: kibana
hostname: kibana