HKL's Notes
N/A C.V. · Linkedin · Github


ELK收集处理Huawei/H3C交换机日志

By , on , tagged: 🏷️Networking  🏷️Operating 

通过ELK logstash模块收集处理交换机日志并进行可视化处理

这里主要是写一下logstash grok的对交换机日志的正则实现,之后再补充可视化的分析模板

1.Huawei Switch 华为交换机

效果如下

Huawei Switch ELK

logstash配置文件如下:

/etc/logstash/conf.d/hw-log.conf

input {
   udp {
    port => 2514
    type => syslog 
   }
}
filter {
 if [type] == "syslog" {
 	grok {
            match => {
                "message" => "<%{BASE10NUM:syslog_pri}>(?<switchtime>.*) %{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 => ["127.0.0.1:9200"]
     index => "switchlog"
  }
}

2.H3C Switch 华三交换机

效果如下 H3C Switch ELK

logstash配置文件如下:

/etc/logstash/conf.d/h3c-log.conf

input {
   udp {
    port => 3514
    type => syslog 
   }
}
filter {
 if [type] == "syslog" {
    grok {
            match => {
                "message" => "<%{BASE10NUM:syslog_pri}>%{DATA:hostname} %%%{DATA:vvmodule}/%{POSINT:severity}/%{DATA:digest}: %{GREEDYDATA:message}"
            }
            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 => ["127.0.0.1:9200"]
     index => "h3clog-logstash"
     template_overwrite => true
  }


Articles are licensed under CC BY-NC 4.0