# Need a GeoIP Example

**URL:** <https://discuss.elastic.co/t/need-a-geoip-example/246746>\
**Category:** Logstash\
**Created:** [August 28, 2020, 10:58am UTC](https://discuss.elastic.co/t/need-a-geoip-example/246746 "2020-08-28T10:58:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amantha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amantha/32/73592_2.png) [@Amantha](https://discuss.elastic.co/u/Amantha)\
**Post date:** [August 28, 2020, 10:58am UTC](https://discuss.elastic.co/t/need-a-geoip-example/246746/1 "2020-08-28T10:58:17Z")

</div>

Can someone provide a **geoip example for logstash with a log file**?

---

<div class="post-metadata">

**Author:** ![rugenl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rugenl/32/12887_2.png) [@rugenl](https://discuss.elastic.co/u/rugenl)\
**Post date:** [August 28, 2020, 8:04pm UTC](https://discuss.elastic.co/t/need-a-geoip-example/246746/2 "2020-08-28T20:04:45Z")

</div>

```
filter {
  if [fileset][module] == "apache2" or [event][module] == "apache2" {
    if [fileset][name] == "access" {
           grok {
              match => {
                 "message" => [
                    "%{IPORHOST:[apache2][access][remote_ip]} - %{DATA:[apache2][access][user_name]} \[%{HTTPDATE:[apache2][access][time]}\] \"(?:%{WORD:apache2.access.method} %{DATA:apache2.access.url} HTTP/%{NUMBER:apache2.access.http_version}|-)?\" %{NUMBER:apache2.access.response_code} (?:%{NUMBER:apache2.access.body_sent.bytes}|-)( \"%{DATA:[apache2][access][referrer]}\")?( \"%{DATA:[apache2][access][agent]}\")?",
                    "%{IPORHOST:[apache2][access][remote_ip]} - %{DATA:[apache2][access][user_name]} \[%{HTTPDATE:[apache2][access][time]}\] \"-\" %{NUMBER:[apache2][access][response_code]} -",
                    "\[%{HTTPDATE:[apache2][access][time]}\] %{IPORHOST:[apache2][access][remote_ip]} %{DATA:[apache2][access][ssl][protocol]} %{DATA:[apache2][access][ssl][cipher]} \"%{WORD:[http][request][method]} %{DATA:[apache2][access][url]} HTTP/%{NUMBER:[apache2][access][http_version]}\" %{NUMBER:[apache2][access][body_sent][bytes]}"
                 ]
              }
           }

           mutate {
              rename => {
                 "@timestamp" => "read_timestamp"
              }
           }
           date {
              match => [
                 "[apache2][access][time]",
                 "dd/MMM/yyyy:H:m:s Z"
              ]
              target => "@timestamp"
           }

           mutate {
              rename => {
                 "[apache2][access][agent]" => "[apache2][access][user_agent][original]"
              }
           }
           geoip {
              source => "[apache2][access][remote_ip]"
              target => "[apache2][access][geoip]"
           }

           if ![@timestamp] {
              mutate {
                 rename => { "read_timestamp" => "@timestamp" }
                 id => "fix @timestamp when missing"
              }
           }

        }
....snip....
```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 28, 2020, 8:30pm UTC](https://discuss.elastic.co/t/need-a-geoip-example/246746/3 "2020-08-28T20:30:41Z")

</div>

And of course you will need a [mapping template](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html).

---

<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:** [September 25, 2020, 8:30pm UTC](https://discuss.elastic.co/t/need-a-geoip-example/246746/4 "2020-09-25T20:30:46Z")

</div>

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