logstash收集华为、H3C、Cisco交换机日志

网络设备配置

将 syslog-ip 替换成服务器的IP地址。

复制代码
Huawei
info-center loghost source interface
info-center loghost syslog-ip local-time facility local6
H3C
info-center loghost source interface
info-center loghost syslog-ip facility local5
Aruba
logging arm subcat all level warnings
logging network subcat all level warnings
logging security subcat all level warnings
logging security subcat ids level warnings
logging security subcat ids-ap level warnings
logging system subcat all level warnings
logging user subcat all level warnings
logging wireless subcat all level warnings
logging 10.10.4.86 severity warnings facility local3
CISCO
logging on
logging syslog-ip 
logging facility local4
logging source-interface e0

本次以华为交换机为例,首先登录交换机,设置日志收集服务器地址:

复制代码
1、设置日志服务器IP地址
<S5735-EsxiMGT-SW1>system-view
Enter system view, return user view with Ctrl+Z.
[S5735-EsxiMGT-SW1]display current-configuration | in info
info-center loghost source Vlanif100
snmp-agent sys-info version v2c
undo snmp-agent sys-info version v3
[S5735-EsxiMGT-SW1]info-center loghost 10.10.200.35
[S5735-EsxiMGT-SW1]display current-configuration | in info
info-center loghost source Vlanif100
info-center loghost 10.10.200.35
snmp-agent sys-info version v2c
undo snmp-agent sys-info version v3

之后登录logstash服务器,配置conf

复制代码
[root@node3 ~]# cd /etc/logstash/conf.d/
[root@node3 conf.d]# vim switch.conf
input{
    tcp { port => 5002
    type => "Cisco"}
    udp { port => 514
    type => "HUAWEI"}
    udp { port => 5002
    type => "Cisco"}
    udp { port => 5003
    type => "H3C"}
}
filter {
    if [type] == "Cisco" {
    grok {
    match => { "message" => "<%{BASE10NUM:syslog_pri}>%{NUMBER:log_sequence}: .%{SYSLOGTIMESTAMP:timestamp}: %%{DATA:facility}-%{POSINT:severity}-%{CISCO_REASON:mnemonic}: %{GREEDYDATA:message}" }
    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"]
    }
}
    elseif [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"]
    }
}
        elseif [type] == "HUAWEI" {
    grok {
       match => { "message" => "<%{BASE10NUM:syslog_pri}>%{SYSLOGTIMESTAMP:timestamp} %{DATA:hostname} %%%{DATA:ddModuleName}/%{POSINT:severity}/%{DATA:Brief}:%{GREEDYDATA:message}"}
       match => { "message" => "<%{BASE10NUM:syslog_pri}>%{SYSLOGTIMESTAMP: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 {
        index =>
        "syslog-%{+YYYY.MM.dd}"
        hosts => ["10.10.200.33:9200","10.10.200.34:9200","10.10.200.35:9200"]
    }
}

修改后,重启Logstash

登录ELK,检查数据

相关推荐
Jackilina_Stone8 小时前
【网工】华为配置专题进阶篇①
网络·华为·网工
lally.8 小时前
计算机网络
网络·计算机网络
LPH31198 小时前
Linux系统安全管理
linux·网络·安全·系统安全
kikumaru71410 小时前
Mac 安装 finalshell
linux·网络·macos
小兔子酱#10 小时前
【Docker 07】Network - 网络
网络·docker·php
OKUNP10 小时前
LVS+Keepalived高可用群集
网络·智能路由器·lvs
哪 吒14 小时前
突破亚马逊壁垒,Web Unlocker API 助您轻松获取数据
前端·网络·python·网络安全
程序员小刘15 小时前
HarmonyOS 5 原子化服务卡片测试全攻略
华为·harmonyos·原子化服务卡片
蜡笔小电芯15 小时前
【STM32】 LWIP -TCP 客户端收发数据
网络·stm32·tcp/ip
二蛋和他的大花15 小时前
鸿蒙运动开发实战:打造专属运动视频播放器
华为·音视频·harmonyos