OS가 centos에서 ubuntu로 변경되어 ubuntu에서도 logstash 설정하는 내용을 남깁니다.

 

설명을 위해서 fortigate log를 파싱하기 위한 logstash 설정 입니다.

내용 확인 후 활용하시면 좋을 것 같아요.

 

logstash 설정 파일 생성하기

logmgmt@syslogserver:~$ sudo cat /etc/logstash/conf.d/logstash.conf
input {
        file {
                path => "/var/log/rsyslog/192.168.000.000/*.log"
                start_position => "beginning"
                tags => ["fortigate"]
        }
}

filter {
        if "fortigate" in [tags] {
                grok {
                        patterns_dir => ["/etc/logstash/pattern.d"]
                                match => { "message" => [ "%{FORTILOG} %{GREEDYDATA:sub_message}" ] }
                }
                kv {
                        source => "sub_message"
                        value_split => "="
                }
                mutate { remove_field => [ "message" ] }
                mutate { remove_field => [ "sub_message" ] }
                if "wan" in [srcintfrole] {
                        geoip {
                                source => "srcip"
                                target => "geoip_src"
                        }
                }
                if [sentbyte] != "" and [rcvdbyte] != "" {
                        bytes {
                                source => "rcvdbyte"
                                target => "receivedbyte"
                        }
                        bytes {
                                source => "sentbyte"
                                target => "sentedbyte"
                        }
                }
                mutate {
                        convert => {
                                "rcvdpkt" => "integer"
                                "sentpkt" => "integer"
                                "proto" => "integer"
                                "srcserver" => "integer"
                                "sessionid" => "integer"
                                "duration" => "integer"
                                "policyid" => "integer"
                                "HOUR" => "integer"
                                "MINUTE" => "integer"
                                "SECOND" => "integer"
                        }
                }
        }
}

output {
        if "fortigate" in [tags] {
                if "traffic" in [type] {
                        elasticsearch {
                                hosts => "http://192.168.000.000:9200"
                                index => "logstash-fortigate-traffic-index-%{+YYYY.MM.dd}"
                        }
                }
                else if "event" in [type] {
                        elasticsearch {
                                hosts => "http://192.168.000.000:9200"
                                index => "logstash-fortigate-event-index-%{+YYYY.MM.dd}"
                        }
                }
                else if "utm" in [type] {
                        elasticsearch {
                                hosts => "http://192.168.000.000:9200"
                                index => "logstash-fortigate-utm-index-%{+YYYY.MM.dd}"
                        }
                }
        }
}
logmgmt@syslogserver:~$

 

 

fortigate 패턴 파일 생성하기

logmgmt@syslogserver:~$ sudo cat /etc/logstash/pattern.d/fortigate.pattern
####################################
###Fortinet Syslog Pattern Types:###
####################################

FORTILOG (?<timestamp>^\w+\s+\d+\s+\d+\:\d+\:\d+)\s(?<log_send_dev>(?:%{IP}|\_gateway))
logmgmt@syslogserver:~$

 

logstash-filter-bytes 필터 설치하기

logmgmt@syslogserver:~$ sudo /usr/share/logstash/bin/logstash-plugin install logstash-filter-bytes
Using bundled JDK: /usr/share/logstash/jdk
Validating logstash-filter-bytes
Resolving mixin dependencies
Installing logstash-filter-bytes
Installation successful
logmgmt@syslogserver:~$

'기술 노트 > ubuntu' 카테고리의 다른 글

Prometheus 설치  (1) 2023.12.21
kibana 설정하기  (1) 2023.12.05
elasticsearch 설정하기  (0) 2023.12.04
rsyslog 설정하기  (1) 2023.12.04
우분투에서 IP 주소 확인하기  (1) 2023.12.04

fortigate log 파싱 부분이 추가되었습니다.

fortigate 로그 파싱할때에는 logstash-filter-bytes를 사용하였습니다.

이유는 logstash에서 로그를 파싱하면 모든 자료는 기본적으로 type이 text입니다.

마찬가지로 숫자도 text로 인식합니다.

그래서 데이터 전송량도 type에 맞게 bytes라는 필터를 추가로 설치하였습니다.

logstash-filter-bytes의 설치는 아래의 작성 글을 참고하시기 바랍니다.

https://dirt-spoon.tistory.com/80

 

input {
        file {
                path => "/var/log/rsyslog/192.168.10.2/*.log"
                start_position => "beginning"
                tags => ["ap1"]
        }
        file {
                path => "/var/log/rsyslog/192.168.10.3/*.log"
                start_position => "beginning"
                tags => ["ap2"]
        }
        file {
                path => "/var/log/rsyslog/192.168.10.4/*.log"
                start_position => "beginning"
                tags => ["ap3"]
        }
        file {
                path => "/var/log/rsyslog/192.168.10.5/*.log"
                start_position => "beginning"
                tags => ["ap4"]
        }
        file {
                path => "/var/log/rsyslog/192.168.0.14/*.log"
                start_position => "beginning"
                tags => ["fortigate"]
        }
}

filter {
        if "ap1" in [tags] or "ap2" in [tags] or "ap3" in [tags] or "ap4" in [tags]  {
                grok {
                        patterns_dir => ["/etc/logstash/pattern.d"]
                        match => {
                                "message" => [
                                        "%{SYSLOGTIMESTAMP:access_time} %{IPORHOST:ip_or_host} %{IPORHOST:process}\[%{BASE10NUM:process_id}\]\: %{GREEDYDATA:sub_message}",
                                        "%{SYSLOGTIMESTAMP:access_time} %{IPORHOST:ip_or_host} \[%{BASE10NUM:process_id}\]\: %{GREEDYDATA:sub_message}",
                                        "%{SYSLOGTIMESTAMP:access_time} %{IPORHOST:ip_or_host} %{WORD:process}\: User\: %{GREEDYDATA:user} last logged %{GREEDYDATA:access_result} in %{GREEDYDATA:access_day}\#%{NUMBER:deauthentication_reason_code}, to %{IP:destination_ip}, from %{IP:source_ip} using %{WORD:access_method}",
                                        "%{SYSLOGTIMESTAMP:access_time} %{IPORHOST:ip_or_host} %{WORD:process}\: User\: %{GREEDYDATA:reason} in %{GREEDYDATA:access_day}\#%{NUMBER:deauthentication_reason_code}, to %{IP:destination_ip}, from %{IP:source_ip} using %{WORD:access_method}"
                                ]
                        }
                }
                mutate { remove_field => [ "message" ] }
        }
        else if "fortigate" in [tags] {
                grok {
                        patterns_dir => ["/etc/logstash/pattern.d"]
                        match => { "message" => [ "%{FORTILOG} %{GREEDYDATA:sub_message}" ] }
                }
                kv {
                        source => "sub_message"
                        value_split => "="
                }
                mutate { remove_field => [ "message" ] }
                mutate { remove_field => [ "sub_message" ] }
                if "wan" in [srcintfrole] {
                        geoip {
                                source => "srcip"
                                target => "geoip_src"
                        }
                }
                if [sentbyte] != "" and [rcvdbyte] != "" {
                        bytes {
                                source => "rcvdbyte"
                                target => "receivedbyte"
                        }
                        bytes {
                                source => "sentbyte"
                                target => "sentedbyte"
                        }
                }
                mutate {
                        convert => {
                                "rcvdpkt" => "integer"
                                "sentpkt" => "integer"
                                "proto" => "integer"
                                "srcserver" => "integer"
                                "sessionid" => "integer"
                                "duration" => "integer"
                                "policyid" => "integer"
                                "HOUR" => "integer"
                                "MINUTE" => "integer"
                                "SECOND" => "integer"
                        }
                }
        }
}

output {
        if "ap1" in [tags] {
                elasticsearch {
                        hosts => "http://192.168.0.17:9200"
                        index => "logstash-ap1-index-%{+YYYY.MM.dd}"
                }
        }
        else if "ap2" in [tags] {
                elasticsearch {
                        hosts => "http://192.168.0.17:9200"
                        index => "logstash-ap2-index-%{+YYYY.MM.dd}"
                }
        }
        else if "ap3" in [tags] {
                elasticsearch {
                        hosts => "http://192.168.0.17:9200"
                        index => "logstash-ap3-index-%{+YYYY.MM.dd}"
                }
        }
        else if "ap4" in [tags] {
                elasticsearch {
                        hosts => "http://192.168.0.17:9200"
                        index => "logstash-ap4-index-%{+YYYY.MM.dd}"
                }
        }
        else if "fortigate" in [tags] {
                if "traffic" in [LOG_TYPE] {
                        elasticsearch {
                                hosts => "http://192.168.0.17:9200"
                                index => "logstash-fortigate-traffic-index-%{+YYYY.MM.dd}"
                        }
                }
                else if "event" in [LOG_TYPE] {
                        elasticsearch {
                                hosts => "http://192.168.0.17:9200"
                                index => "logstash-fortigate-event-index-%{+YYYY.MM.dd}"
                        }
                }
                else if "utm" in [LOG_TYPE] {
                        elasticsearch {
                                hosts => "http://192.168.0.17:9200"
                                index => "logstash-fortigate-utm-index-%{+YYYY.MM.dd}"
                        }
                }
        }
}

'기술 노트 > logstash' 카테고리의 다른 글

font 깨질 때  (0) 2025.03.24
logstash.conf_230306  (0) 2023.03.06
logstash.conf_23.02.20  (0) 2023.02.20
logstash 파일 파싱하기  (0) 2023.02.20
logstash 설정  (0) 2023.02.20

grok 패턴의 다양성을 위해서 config 설정 변경 시 내용 공유 합니다.

샘플로 이용을 해주시면 좋을 것 같아요.

설정 중 더 나은 코드 정보가 있으면 의견도 부탁드립니다.

 

input {
	file {
		path => "/var/log/rsyslog/192.168.10.2/*.log"
		start_position => "beginning"
		tags => ["ap1"]
	}
	file {
		path => "/var/log/rsyslog/192.168.10.3/*.log"
		start_position => "beginning"
		tags => ["ap2"]
	}
	file {
		path => "/var/log/rsyslog/192.168.10.4/*.log"
		start_position => "beginning"
		tags => ["ap3"]
	}
	file {
		path => "/var/log/rsyslog/192.168.10.5/*.log"
		start_position => "beginning"
		tags => ["ap4"]
	}
}

filter {
	if "ap1" in [tags] or "ap2" in [tags] or "ap3" in [tags] or "ap4" in [tags]  {
		grok {
			patterns_dir => ["/etc/logstash/pattern.d"]
				match => {
					"message" => [
						"%{SYSLOGTIMESTAMP:access_time} %{IPORHOST:ip_or_host} %{IPORHOST:process}\[%{BASE10NUM:process_id}\]\: %{GREEDYDATA:sub_message}",
						"%{SYSLOGTIMESTAMP:access_time} %{IPORHOST:ip_or_host} \[%{BASE10NUM:process_id}\]\: %{GREEDYDATA:sub_message}",
						"%{SYSLOGTIMESTAMP:access_time} %{IPORHOST:ip_or_host} %{WORD:process}\: User\: %{USER:User} %{GREEDYDATA:Reason} in %{GREEDYDATA:access_day}\#%{NUMBER:Deauthentication_Reason_Code}, to %{IP:Destination_IP}, from %{IP:Start_ip} using %{WORD:Access_Method}"
					]
				}
		}
		mutate { remove_field => [ "message" ] }
	}
}

output {
	if "ap1" in [tags] {
		elasticsearch {
			hosts => ["http://192.168.0.17:9200"]
			index => "logstash-ap1-index-%{+YYYY.MM.dd}"
		}
	}
	else if "ap2" in [tags] {
		elasticsearch {
			hosts => ["http://192.168.0.17:9200"]
			index => "logstash-ap2-index-%{+YYYY.MM.dd}"
		}
	}
	else if "ap3" in [tags] {
		elasticsearch {
			hosts => ["http://192.168.0.17:9200"]
			index => "logstash-ap3-index-%{+YYYY.MM.dd}"
		}
	}
	else if "ap4" in [tags] {
		elasticsearch {
			hosts => ["http://192.168.0.17:9200"]
			index => "logstash-ap4-index-%{+YYYY.MM.dd}"
		}
	}
}

'기술 노트 > logstash' 카테고리의 다른 글

logstash.conf_230405  (0) 2023.04.05
logstash.conf_230306  (0) 2023.03.06
logstash 파일 파싱하기  (0) 2023.02.20
logstash 설정  (0) 2023.02.20
grok pattern  (0) 2023.02.17

+ Recent posts