# Removing part of message giving grokparsefailure

**URL:** <https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234>\
**Category:** Logstash\
**Created:** [September 19, 2019, 2:33pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234 "2019-09-19T14:33:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlim0930](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jlim0930](https://discuss.elastic.co/u/jlim0930)\
**Post date:** [September 19, 2019, 2:33pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234/1 "2019-09-19T14:33:23Z")

</div>

while sending logs from a central syslog server it adds "Message forwarded from ...." in the message field.

I added  
if "Message forwarded from" in [message] {  
mutate {  
gsub =\> [  
"message", "Message forwarded from ", "",  
"message", "\<.\*\>", ""  
]  
}  
}  
grok {  
match =\> { "message" =\> "%{SYSLOGTIMESTAMP:syslog\_timestamp} %{SYSLOGHOST:syslog\_hostname} %{DATA:syslog\_program}(?:[%{POSINT:syslog\_pid}])?: %{GREEDYDATA:syslog\_message}" }  
add\_field =\> ["received\_at", "%{@timestamp}"]  
add\_field =\> ["received\_from", "%{host}"]  
}  
}  
}

now the "Message forwarded from" is gone from the message but now i am getting grokparsefailure

---

<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:** [September 19, 2019, 2:45pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234/2 "2019-09-19T14:45:53Z")

</div>

What does [message] look like?

---

<div class="post-metadata">

**Author:** ![jlim0930](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jlim0930](https://discuss.elastic.co/u/jlim0930)\
**Post date:** [September 19, 2019, 7:41pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234/3 "2019-09-19T19:41:30Z")

</div>

just a normal syslog from systems but coming from a centralized syslog server so "message forwarded from" gets added and thats what I am trying to remove

Sep 19 10:46:07 Message forwarded from hostname: program: logs logs losg

i see where the grokparsefailure is coming from... I used mutate to remove "Message forwarded from" but how do you remove the : after the hostname?

---

<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:** [September 19, 2019, 8:48pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234/4 "2019-09-19T20:48:52Z")

</div>

Wouldn't it be easier to add the colon to the grok pattern?

---

<div class="post-metadata">

**Author:** ![jlim0930](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jlim0930](https://discuss.elastic.co/u/jlim0930)\
**Post date:** [September 19, 2019, 10:26pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234/5 "2019-09-19T22:26:00Z")

</div>

is there a way to do grok where the first : can exist or not and still parse ok?

like  
Sep 19 10:46:07 Message forwarded from hostname: program: logs logs losg  
vs  
Sep 19 10:46:07 Message forwarded from hostname program: logs logs losg

---

<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:** [September 19, 2019, 10:33pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234/6 "2019-09-19T22:33:43Z")

</div>

()? is used for optional fields, as you have used for the syslog\_pid, so

```
"%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname}(:)? %{DATA:syslog_program}(?:[%{POSINT:syslog_pid}])?: %{GREEDYDATA:syslog_message}"
```

---

<div class="post-metadata">

**Author:** ![jlim0930](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@jlim0930](https://discuss.elastic.co/u/jlim0930)\
**Post date:** [September 19, 2019, 10:41pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234/7 "2019-09-19T22:41:45Z")

</div>

Great! working like a champ! thanks

---

<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:** [October 17, 2019, 10:41pm UTC](https://discuss.elastic.co/t/removing-part-of-message-giving-grokparsefailure/200234/8 "2019-10-17T22:41:51Z")

</div>

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