# Grok Pattern not working

**URL:** <https://discuss.elastic.co/t/grok-pattern-not-working/293159>\
**Category:** Logstash\
**Created:** [December 29, 2021, 11:11pm UTC](https://discuss.elastic.co/t/grok-pattern-not-working/293159 "2021-12-29T23:11:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pranav\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pranav_m/32/97609_2.png) [@Pranav\_M](https://discuss.elastic.co/u/Pranav_M)\
**Post date:** [December 29, 2021, 11:11pm UTC](https://discuss.elastic.co/t/grok-pattern-not-working/293159/1 "2021-12-29T23:11:18Z")

</div>

Hey Community,

**Received packet: Type = N5abcde8AbcAbcde9AbcdAbcde15AbcdefghAbcdefA, xx = 95, xxx = 441, xxxXxo = 2, xXxxXxx = 1, xxxx = 9 accepted.**

The above line is a message from my log and I want to seperate each data into a field to visualize it in Kibana, I tried to use Grok and Dissect, however I am unable to achieve it. I would be extremely thankful if someone from you could guide me to put them together in a pattern

The following is the grok pattern that I have defined, however it isn't working  
grok {  
match =\> {` "Log_Message" => "%{GREEDYDATA:Packet_Type}%{NUMBER:ts:int}%{NUMBER:cts:int}%{NUMBER:SeqNo:int}%{NUMBER:cSeqNo:int}%{NUMBER:trtd:int}" } }`

---

<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 30, 2021, 12:21am UTC](https://discuss.elastic.co/t/grok-pattern-not-working/293159/2 "2021-12-30T00:21:25Z")

</div>

That does not match your example message. If the set of fields is constant you could use something like

```
Type = %{NOTSPACE:type}, xx = %{NUMBER:ts:int}, xxx = %{NUMBER:cts:int}, xxxXxo = %{NUMBER:SeqNo:int}, xXxxXxx = {NUMBER:cSeqNo:int}, xxxx = %{NUMBER:trtd:int} accepted

```

If the set of fields varies it might be better to use an array of patterns, one for each field

```
grok {
    break_on_match => false
    match => { "log_message" => [
        "Type = %{NOTSPACE:type}",
        "xx = %{NUMBER:ts:int}",
        "xxx = %{NUMBER:cts:int}",
        "xxxXxo = %{NUMBER:SeqNo:int}",
        "xXxxXxx = {NUMBER:cSeqNo:int}",
        "xxxx = %{NUMBER:trtd:int}"
    ]
}
```

---

<div class="post-metadata">

**Author:** ![Pranav\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pranav_m/32/97609_2.png) [@Pranav\_M](https://discuss.elastic.co/u/Pranav_M)\
**Post date:** [December 30, 2021, 9:34am UTC](https://discuss.elastic.co/t/grok-pattern-not-working/293159/3 "2021-12-30T09:34:48Z")

</div>

@Badger Thank you for the quick response, its working, thanks a lot

---

<div class="post-metadata">

**Author:** ![Pranav\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pranav_m/32/97609_2.png) [@Pranav\_M](https://discuss.elastic.co/u/Pranav_M)\
**Post date:** [January 10, 2022, 11:48am UTC](https://discuss.elastic.co/t/grok-pattern-not-working/293159/4 "2022-01-10T11:48:22Z")

</div>

Hi @Badger

I would like to filter out this patter as well from my message, how do I add a filter for it, i tried the following but then neither of them works, I request you to help me out with catching the following message

Abcde Abcde : XX

where Abcde is a string and XX is an integer

* * *

I tried the following grok patterns, but doesn't seem to work

match =\> { "message" =\> ["ABCDE ABCDE= %{NUMBER:ABCDE ABCDE:int}"] }

and

match =\> { "message" =\> ["ABCDE\_ABCDE= %{NUMBER:ABCDE ABCDE:int}"] }

and

match =\> { "message" =\> ["ABCDE ABCDE= %{NUMBER:ABCDE\_ABCDE:int}"] }

and

match =\> { "message" =\> ["ABCDE\_ABCDE= %{NUMBER:ABCDE\_ABCDE:int}"] }

Can you please help me out in retrieving the message using grok

---

<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:** [January 10, 2022, 3:01pm UTC](https://discuss.elastic.co/t/grok-pattern-not-working/293159/5 "2022-01-10T15:01:02Z")

</div>

Your sample data is separated using : but your patterns use =. That is not going to work.

---

<div class="post-metadata">

**Author:** ![Pranav\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pranav_m/32/97609_2.png) [@Pranav\_M](https://discuss.elastic.co/u/Pranav_M)\
**Post date:** [January 11, 2022, 4:50am UTC](https://discuss.elastic.co/t/grok-pattern-not-working/293159/6 "2022-01-11T04:50:00Z")

</div>

@Badger , Thanks for your quick response, I understood the working of the filter now and was able to script according to the parameters.

I am now trying to retrieve values out of the log message.

**Aaaaaaa AaaaaaaaaaaaAaaaaaa : Aaaaaa: X|X.**

the values of X ranges from 0 to 8 and this was the script that I wrote for it  
**match =\> { "message" =\> ["Aaaaaaa AaaaaaaaaaaaAaaaaaa : Aaaaaa: %{NUMBER:AAA:float}|%{NUMBER:BBB:float}"] }**

there is no error thrown, however Logstash is now capturing all messages containing an integer, is there any way where I can make it work?

I want to take the first value and plot in field AAA and second value and plot in field BBB

---

<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:** [February 8, 2022, 4:50am UTC](https://discuss.elastic.co/t/grok-pattern-not-working/293159/7 "2022-02-08T04:50:43Z")

</div>

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