# Writing grok filter for my usecase

**URL:** <https://discuss.elastic.co/t/writing-grok-filter-for-my-usecase/95861>\
**Category:** Logstash\
**Created:** [August 4, 2017, 10:36am UTC](https://discuss.elastic.co/t/writing-grok-filter-for-my-usecase/95861 "2017-08-04T10:36:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinod\_hy](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@vinod\_hy](https://discuss.elastic.co/u/vinod_hy)\
**Post date:** [August 4, 2017, 10:36am UTC](https://discuss.elastic.co/t/writing-grok-filter-for-my-usecase/95861/1 "2017-08-04T10:36:54Z")

</div>

I have the following line in log file,

**[2017-07-07 11:41:30.794][DEBUG][Hello]**

for the above log, i have written the grok filter as shown below,  
**match =\> {"message" =\>"[%{TIMESTAMP\_ISO8601:TimeStamp}][%{LOGLEVEL:logLevel}][%{WORD:machineName}]"}**

But i have another scenario where my last part of the log is little changed as below,

**[2017-07-07 11:41:30.794][DEBUG][C:0:O:1]**

For this i am not able to write the proper grok filter. I tried the below,

**match =\> {"message" =\>"[%{TIMESTAMP\_ISO8601:TimeStamp}][%{LOGLEVEL:logLevel}][%{HOSTNAME:machineName}]"}**

**HOSTNAME** is not working. Can you please suggest which keyword to use.

---

<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:** [August 4, 2017, 11:10am UTC](https://discuss.elastic.co/t/writing-grok-filter-for-my-usecase/95861/2 "2017-08-04T11:10:23Z")

</div>

Try `(?<machineName>[^\]]+)` instead of `%{HOSTNAME:machineName}`; one or more characters of any kind except closing square bracket.

---

<div class="post-metadata">

**Author:** ![vinod\_hy](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@vinod\_hy](https://discuss.elastic.co/u/vinod_hy)\
**Post date:** [August 9, 2017, 6:33am UTC](https://discuss.elastic.co/t/writing-grok-filter-for-my-usecase/95861/3 "2017-08-09T06:33:02Z")

</div>

@magnusbaeck ,

This is my exact filter ..  
**match =\> {"message" =\>"[%{TIMESTAMP\_ISO8601:TimeStamp}][%{LOGLEVEL:logLevel}][%{HOSTNAME:machineName}][%{JAVACLASS:className}][%{JAVAMETHOD:methodName}][%{WORD:commandID}][%{GREEDYDATA:myMessage}]"}**

Can you please tell me what to modify here so that **HOSTNAME:machineName** accepts C:0:O:1.

---

<div class="post-metadata">

**Author:** ![vinod\_hy](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@vinod\_hy](https://discuss.elastic.co/u/vinod_hy)\
**Post date:** [August 9, 2017, 7:07am UTC](https://discuss.elastic.co/t/writing-grok-filter-for-my-usecase/95861/4 "2017-08-09T07:07:17Z")

</div>

If my input is **C:0:O:1** , then **HOSTNAME:machineName** is **not able** to parse it.  
But if my input is **C:0:O.1** , then **HOSTNAME:machineName** is **able** to parse it.

Is it because there is : already present in **HOSTNAME:machineName**.. how to solve it. Please help me here

---

<div class="post-metadata">

**Author:** ![vinod\_hy](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@vinod\_hy](https://discuss.elastic.co/u/vinod_hy)\
**Post date:** [August 9, 2017, 7:46am UTC](https://discuss.elastic.co/t/writing-grok-filter-for-my-usecase/95861/5 "2017-08-09T07:46:26Z")

</div>

@magnusbaeck,

I used the below filter and it worked,  
match =\> {"message" =\>"[%{TIMESTAMP\_ISO8601:TimeStamp}][%{LOGLEVEL:logLevel}][(?[0-9A-Z:]{3,15})]"}

Thanks a lot for your input..

---

<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 6, 2017, 7:46am UTC](https://discuss.elastic.co/t/writing-grok-filter-for-my-usecase/95861/6 "2017-09-06T07:46:48Z")

</div>

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