# Logstash multiline with incrementation

**URL:** <https://discuss.elastic.co/t/logstash-multiline-with-incrementation/40338>\
**Category:** Logstash\
**Created:** [January 28, 2016, 8:57am UTC](https://discuss.elastic.co/t/logstash-multiline-with-incrementation/40338 "2016-01-28T08:57:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrianolimit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrianolimit/32/11930_2.png) [@adrianolimit](https://discuss.elastic.co/u/adrianolimit)\
**Post date:** [January 28, 2016, 8:57am UTC](https://discuss.elastic.co/t/logstash-multiline-with-incrementation/40338/1 "2016-01-28T08:57:01Z")

</div>

Hi everyone,

I'm working on log files and I have a little problem, this is an example of my logs :

> 192.168.0.1(localhost) (user1)  
> file1
> 
> 192.168.0.2(localhost) (user2)  
> file2  
> file3  
> file2 - read only

A new line is identified by an IP address, for each line I want to keep the following information :

- IP address
- domain
- user
- file

For the first line, it isn't very complicated because I have only 1 file but for the second line I have a problem, I can get only the first file (file2). At the end, I'd like to have the following data into Elasticsearch :

> 192.168.0.1 localhost user1 file1  
> 192.168.0.2 localhost user2 file2  
> 192.168.0.2 localhost user2 file3

I don't want to keep the lines that don't begin by an IP address or that contain a dash '-', in my example I don't want to keep : file2 - read only.

This is the configuration file that I use for Logstash :

```
input {
    file {
        type => "my_dashboard"
        path => "/path-to-my-data/*"
        start_position => "beginning"
        sincedb_path => "since_db"
        codec => plain { charset => "ANSI_X3.4-1968"}
    }
}
filter {
    multiline {
        pattern => "%{IP:IP}"
        what => "next"
    }
    grok {
        match => {"message" => "%{IP:IP}\(%{HOSTNAME:domain}\)%{SPACE}\(%{USERNAME:user}\)%{SPACE}%{NOTSPACE:file}"}
    }
    mutate {
        remove_field => ["host","@version","path"]
    }
}
output {
    if "_grokparsefailure" in [tags] {
        file {
            path => "./grokparsefailure.log"
        }
    }
    else if [type] == "my_dashboard" {
        elasticsearch {
            hosts => "192.168.0.1:9200"
            index => "user_data"
            document_type => "user"
        }
    }
}

```

Thank you in advance for your help 😉

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 28, 2016, 8:49pm UTC](https://discuss.elastic.co/t/logstash-multiline-with-incrementation/40338/2 "2016-01-28T20:49:53Z")

</div>

You need to reverse the logic. Join with the previous line _unless_ it's an IP.

```auto
multiline {
  pattern => "^%{IP}"
  what => "previous"
  negate => true
}

```

---

<div class="post-metadata">

**Author:** ![adrianolimit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrianolimit/32/11930_2.png) [@adrianolimit](https://discuss.elastic.co/u/adrianolimit)\
**Post date:** [January 29, 2016, 10:49am UTC](https://discuss.elastic.co/t/logstash-multiline-with-incrementation/40338/3 "2016-01-29T10:49:24Z")

</div>

I tried your suggestion and I get the following results :

```
192.168.0.1 localhost user1 file1
192.168.0.2 localhost user2 file2 file3 file2 - read only

```

The expected results should be :

```
192.168.0.1 localhost user1 file1
192.168.0.2 localhost user2 file2
192.168.0.2 localhost user2 file3

```

The problem is I don't know in advance how many files will be under each IP line. For now, I can only get the first file under each IP :

```
192.168.0.1 localhost user1 file1
192.168.0.2 localhost user2 file2

```

For each file line, I would like to add IP, domain and user to output in Elasticsearch.

---

<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:** [July 6, 2017, 5:13am UTC](https://discuss.elastic.co/t/logstash-multiline-with-incrementation/40338/4 "2017-07-06T05:13:47Z")

</div>


