# Link lines context in Logstash

**URL:** <https://discuss.elastic.co/t/link-lines-context-in-logstash/86878>\
**Category:** Logstash\
**Created:** [May 24, 2017, 12:00am UTC](https://discuss.elastic.co/t/link-lines-context-in-logstash/86878 "2017-05-24T00:00:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leandro\_Sampaio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandro_sampaio/32/18409_2.png) [@Leandro\_Sampaio](https://discuss.elastic.co/u/Leandro_Sampaio)\
**Post date:** [May 24, 2017, 12:00am UTC](https://discuss.elastic.co/t/link-lines-context-in-logstash/86878/1 "2017-05-24T00:00:37Z")

</div>

Hi

My post its to explain a parse that I did by myself because didnt exist anyone reference.

I used HashMap reference key value linked using a tag "source" from Filebeat to put a  
context transaction on my script and then link lines loaded by many files in concurrence. with didnt have mistake.

If my knoledge in Ruby was better, I could think a simple solution, it's a little complicated to me nubie in Ruby, in my mind was clear,  
but its to put in the paper.

Below is part of code

```
filter {
        grok {
            match => ["message","%{SPACE}(?<method_action>%{WORD})\((?<params_action>%{GREEDYDATA})\)\n%{SPACE}{\n%{GREEDYDATA:message_action}\n }( time: %{NUMBER:time_action}s, line: %{NUMBER:line_action}\n)?"]
        }
        if "_grokparsefailure" not in [tags] {

        ruby {
            code => "@@timestamp_start[event.get('source')] = Time.at(@@timestamp_start[event.get('source')] + event.get('time_action'));"
        }
        ruby {
            code => "event.set('@timestamp_start', @@timestamp_start[event.get('source')])"
        }
        ruby {
            code => "event.set('version', @@version_start[event.get('source')])"
        }
    } else if [message] =~ "^Version[.:]+ " {
        grok {
            match => ["message", "^Version[.:]+ %{GREEDYDATA:version_start}"]
        }
        ruby {
            init => "@@version_start = {}"
            code => "@@version_start[event.get('source')] = event.get('version_start')"
        }
    } else if [message] =~ "^Date\/time[.:]+ " {
        grok {
            match => ["message", "^Date\/time[: .]+(?<timestamp_start>%{YEAR}-%{MONTHNUM}-%{MONTHDAY}.%{HOUR}:%{MINUTE}:%{SECOND})"]
        }

        date {
            match => ["timestamp_start" , "YYYY-MM-dd.HH:mm:ss"]
        }

        ruby {
            init => "@@timestamp_start = {};"
            code => "@@timestamp_start[event.get('source')] = event.get('@timestamp')"
        }
    }
}

```

If somebody has a better solution, I ask to put in comments

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 24, 2017, 8:08am UTC](https://discuss.elastic.co/t/link-lines-context-in-logstash/86878/2 "2017-05-24T08:08:11Z")

</div>

What does a raw event look like and what is the end result you are looking to achieve?

---

<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:** [June 21, 2017, 8:08am UTC](https://discuss.elastic.co/t/link-lines-context-in-logstash/86878/3 "2017-06-21T08:08:23Z")

</div>

Closed on June 21, 2017, 8:08am UTC

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