# The grok works very strangely in logstash

**URL:** <https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427>\
**Category:** Logstash\
**Created:** [December 10, 2021, 1:11pm UTC](https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427 "2021-12-10T13:11:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![San9](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@San9](https://discuss.elastic.co/u/San9)\
**Post date:** [December 10, 2021, 1:11pm UTC](https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427/1 "2021-12-10T13:11:25Z")

</div>

To all lovers of this hello!  
In some excellent one noticed that my messages in logstash stopped parsing, an error appeared - \_grokparsefailure. but no configuration changes were made.  
Original messages

```auto
1.2.3.4 0 - Test [10/Dec/2021:09:27:35 +0200] "GET /sap(............................................................................................)/webif/notify/polling/SAR::dfyh778/notify.htm HTTP/1.1" 200 155
1.2.3.5 10 - - [10/Dec/2021:09:27:35 +0200] "POST /sap(............................................................................................)/webif/notify/polling/SAE::JHFJFJHJ3543J::202114.90/notify.htm HTTP/1.1" 200 155

```

part with the logstash config:

```auto
grok {
        patterns_dir => ["/etc/logstash/conf.d/patterns"]
        match => {"message" => "%{WEBDISPATCHERTPP}"}
}

```

Initially, the regular expression worked for these messages:

```auto
WEBDISPATCHERTPP %{IP:ip} %{NUMBER:duration} %{USER:remote_log_name} %{USER:ident} \[(?<timestamp>.*)\] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-)

```

at some point these regular expressions stopped working in lostash, but at the same time everything is parsed perfectly in Grok Debugger in kibana

what is the problem? I tried to partially rewrite the parsing, but I cannot fully describe it, there is always an error in some area

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [December 10, 2021, 2:30pm UTC](https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427/2 "2021-12-10T14:30:21Z")

</div>

Are those an example of the the messages that have \_grokparsefailure?

> [@San9](#):
>
> ```auto
> 1.2.3.4 0 - Test [10/Dec/2021:09:27:35 +0200] "GET /sap(............................................................................................)/webif/notify/polling/SAR::dfyh778/notify.htm HTTP/1.1" 200 155
> 1.2.3.5 10 - - [10/Dec/2021:09:27:35 +0200] "POST /sap(............................................................................................)/webif/notify/polling/SAE::JHFJFJHJ3543J::202114.90/notify.htm HTTP/1.1" 200 155
> 
> ```

---

<div class="post-metadata">

**Author:** ![San9](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@San9](https://discuss.elastic.co/u/San9)\
**Post date:** [December 10, 2021, 2:44pm UTC](https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427/3 "2021-12-10T14:44:21Z")

</div>

Unfortunately yes.  
but with this in the GROK debugger, with the help of this expression, everything is parsed perfectly

Now I painted it a little, with other regular expressions and more general ones, but I think this is not entirely correct. At the same time, the time is parsed from me only after - %{GREEDYDATA}.

maybe something is wrong with my version of logtesh or kibana? check with yourself.

---

<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:** [December 10, 2021, 5:32pm UTC](https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427/4 "2021-12-10T17:32:28Z")

</div>

```
input { generator { count => 1 lines => [
    '1.2.3.4 0 - Test [10/Dec/2021:09:27:35 +0200] "GET /sap(............................................................................................)/webif/notify/polling/SAR::dfyh778/notify.htm HTTP/1.1" 200 155',
    '1.2.3.5 10 - - [10/Dec/2021:09:27:35 +0200] "POST /sap(............................................................................................)/webif/notify/polling/SAE::JHFJFJHJ3543J::202114.90/notify.htm HTTP/1.1" 200 155'
] } }
filter {
    grok {
        pattern_definitions => { "WEBDISPATCHERTPP" => '%{IP:ip} %{NUMBER:duration} %{USER:remote_log_name} %{USER:ident} \[(?<timestamp>.*)\] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-)' }
        match => {"message" => "%{WEBDISPATCHERTPP}"}
    }
}
output { stdout { codec => rubydebug { metadata => false } } }

```

parses the lines just fine, so I do not think the problem is in the grok patterns.

---

<div class="post-metadata">

**Author:** ![San9](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@San9](https://discuss.elastic.co/u/San9)\
**Post date:** [December 13, 2021, 9:43am UTC](https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427/5 "2021-12-13T09:43:14Z")

</div>

Thank you for checking, and what is your version of Logstash?

---

<div class="post-metadata">

**Author:** ![San9](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@San9](https://discuss.elastic.co/u/San9)\
**Post date:** [December 13, 2021, 10:13am UTC](https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427/6 "2021-12-13T10:13:42Z")

</div>

In the configuration, we registered everything as you have in the example, my Parsig earned. But with PAINTS\_DIR =\> ["/etc/logstash/conf.d/patterns"] does not work. While I will observe the work. very strange.

---

<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:** [January 10, 2022, 10:13am UTC](https://discuss.elastic.co/t/the-grok-works-very-strangely-in-logstash/291427/7 "2022-01-10T10:13:47Z")

</div>

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