# \[Working example\]Fortigate config for Logstash

**URL:** <https://discuss.elastic.co/t/working-example-fortigate-config-for-logstash/108493>\
**Category:** Logstash\
**Created:** [November 21, 2017, 3:04am UTC](https://discuss.elastic.co/t/working-example-fortigate-config-for-logstash/108493 "2017-11-21T03:04:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [November 21, 2017, 3:04am UTC](https://discuss.elastic.co/t/working-example-fortigate-config-for-logstash/108493/1 "2017-11-21T03:04:32Z")

</div>

Hi,

I've been working on a Logstash filter for Fortigate syslogs and I finally have it working. I noticed a lot of people on this board and other places asking for a Fortigate config so I decided to upload mine here. Hopefully the board search and Google search pick this up so others can use it.

Thanks to @magnusbaeck for all the help.

**Readme**

- This config expects you have csv output set to enable on your Fortigate.
- Tested on FortiOS 5.2 but should work on other versions as well.
- For some reason certain fields get a bit messed up, I've seen fields renamed as tran\_sdip while the Fortigate documentation shows it should be transdip (from memory, example might be wrong but I definitely show some field naming issues so compare the fields Elasticsearch is creating with the Fortigate documentation if you need to). I might look into what is causing this later.
- I'm sure this isn't the best or fastest way to processes Fortigate logs but it works. Feel free to make modifications.

```auto
input {
   udp {
     port => 9910
     type => "forti_log"
     tags => ["location_a"]
  }
}

filter {
#The Fortigate syslog contains a type field as well, we'll need to rename that field in order for this to work
 if [type] == "forti_log" {

	grok {
			match => ["message", "%{SYSLOG5424PRI:syslog_index}%{GREEDYDATA:message}"]
			overwrite => ["message"]
			tag_on_failure => ["forti_grok_failure"]
		}

        kv {
    source => "message"
    value_split => "="
#Expects you have csv enable set on your Fortigate. If not I think you'll have to change it to " " but I didn't test that.
    field_split => ","
}

    mutate {
#I want to use the timestamp inside the logs instead of Logstash's timestamp so we'll first create a new field containing the date and time fields from the syslog before we convert that to the @timestamp field
    add_field => { "temp_time" => "%{date} %{time}" }
#The syslog contains a type field which messes with the Logstash type field so we have to rename it.
    rename => { "type" => "ftg_type" }
    rename => { "subtype" => "ftg_subtype" }
    add_field => { "type" => "forti_log" }
    convert => { "rcvdbyte" => "integer" }
    convert => { "sentbyte" => "integer" }
}

date {
    match => ["temp_time", "yyyy-MM-dd HH:mm:ss"]
    timezone => "UTC"
    target => "@timestamp"
    }

    mutate {
#add/remove fields as you see fit.
    remove_field => ["syslog_index","syslog5424_pri","path","temp_time","service","date","time","sentpkt","rcvdpkt","log_id","message","poluuid"]
}
}
}

output {
if [type] == "forti_log" {
elasticsearch {
hosts => "yourip:9200"
http_compression => "true"
index => "forti-%{+YYYY.MM.dd}"
}
}
}
```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 21, 2017, 4:02am UTC](https://discuss.elastic.co/t/working-example-fortigate-config-for-logstash/108493/2 "2017-11-21T04:02:00Z")

</div>

Thanks for sharing this!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 19, 2017, 4:02am UTC](https://discuss.elastic.co/t/working-example-fortigate-config-for-logstash/108493/3 "2017-12-19T04:02:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
