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,检查数据

相关推荐
白帽黑客沐瑶1 天前
【网络安全就业】信息安全专业的就业前景(非常详细)零基础入门到精通,收藏这篇就够了
网络·安全·web安全·计算机·程序员·编程·网络安全就业
树码小子1 天前
Java网络编程:(socket API编程:TCP协议的 socket API -- 回显程序的服务器端程序的编写)
java·网络·tcp/ip
猫林老师1 天前
HarmonyOS数据持久化:Preferences轻量级存储实战
华为·harmonyos
绿箭柠檬茶1 天前
Ubuntu 服务器配置转发网络访问
服务器·网络·ubuntu
real 11 天前
传输层协议UDP
网络·网络协议·udp
路由侠内网穿透1 天前
本地部署 GPS 跟踪系统 Traccar 并实现外部访问
运维·服务器·网络·windows·tcp/ip
Devil枫1 天前
鸿蒙深链落地实战:从安全解析到异常兜底的全链路设计
安全·华为·harmonyos
广州腾科助你拿下华为认证2 天前
华为考试:HCIE数通考试难度分析
大数据·华为
与天仙漫步星海2 天前
华为基本命令
华为
喵手2 天前
玩转Java网络编程:基于Socket的服务器和客户端开发!
java·服务器·网络