# Custom grok\_pattern on syslog input

**URL:** <https://discuss.elastic.co/t/custom-grok-pattern-on-syslog-input/143669>\
**Category:** Logstash\
**Created:** [August 9, 2018, 10:19am UTC](https://discuss.elastic.co/t/custom-grok-pattern-on-syslog-input/143669 "2018-08-09T10:19:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_b/32/17104_2.png) [@A\_B](https://discuss.elastic.co/u/A_B)\
**Post date:** [August 9, 2018, 10:19am UTC](https://discuss.elastic.co/t/custom-grok-pattern-on-syslog-input/143669/1 "2018-08-09T10:19:04Z")

</div>

Hi,

I am trying to ingest logs from our Juniper switshes and I'm trying to configure a `syslog` input. Manyally editing the Logstash input config I got this to work.

```
  # Juniper syslog input
  syslog {
    port => 5518
    grok_pattern => "<%{POSINT:priority}>1 %{SYSLOGLINE}"
    }
  }

```

Unfortunately I can use this with Puppet. The input config file is an .erb template and ruby can not parse all the special characters...

I I created my own pattern to simplify the syntax

```
# cat /etc/logstash/patterns/extra_patterns
JUNIPER_INPUT <%{POSINT:priority}>1 %{SYSLOGLINE}

```

The I changed the input to

```
  # Juniper syslog input
  syslog {
    port => 5518
    grok_pattern => %{JUNIPER_INPUT}"
    }
  }

```

Puppet would be fine with that but Logstash does not find the pattern `JUNIPER_INPUT`. If it was a grok filter I could set `patterns_dir` but that does not seem to be possible to do on the syslog input.

Any suggestions on how to get around this? I guess I could move everything to the filter section but I was very happy to see that it was possible to do some grok stuff already on the input...

-AB

---

<div class="post-metadata">

**Author:** ![A\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_b/32/17104_2.png) [@A\_B](https://discuss.elastic.co/u/A_B)\
**Post date:** [August 9, 2018, 12:31pm UTC](https://discuss.elastic.co/t/custom-grok-pattern-on-syslog-input/143669/2 "2018-08-09T12:31:01Z")

</div>

I am still very interested in hearing suggestions and ideas on this. I did manage to find a working solution for now by looking through and choosing patterns already known to Logstash

```
  # Juniper log JSON input
  syslog {
    port => 5518
    grok_pattern => "%{SYSLOG5424PRI}1 %{SYSLOGLINE}"
    type => "juniper"
    add_field => {
      "[@metadata][index]" => "juniper"
      "[@metadata][log_prefix]" => "dc"
    }
  }
```

---

<div class="post-metadata">

**Author:** ![waqark3389](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waqark3389/32/34265_2.png) [@waqark3389](https://discuss.elastic.co/u/waqark3389)\
**Post date:** [August 9, 2018, 12:57pm UTC](https://discuss.elastic.co/t/custom-grok-pattern-on-syslog-input/143669/3 "2018-08-09T12:57:44Z")

</div>

In the Puppet ERB file you need to escape the special characters... From first looks you have

grok\_pattern =\> "\<%{POSINT:priority}\>1 %{SYSLOGLINE}"

Where as % is a puppet character so use:

grok\_pattern =\> "\<%%{POSINT:priority}\>1 %{SYSLOGLINE}"

With regard to the extra patterns - you have to set patterns\_dir inside the "filter" section and create a grok pattern there.  
You can make the filter conditional by using if [type] == "juniper"

Here you are trying to filter inside the syslog input...

---

<div class="post-metadata">

**Author:** ![A\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_b/32/17104_2.png) [@A\_B](https://discuss.elastic.co/u/A_B)\
**Post date:** [August 10, 2018, 8:23am UTC](https://discuss.elastic.co/t/custom-grok-pattern-on-syslog-input/143669/4 "2018-08-10T08:23:54Z")

</div>

Thanks @waqark3389, I'll keep that in mind 🙂

---

<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 7, 2018, 8:23am UTC](https://discuss.elastic.co/t/custom-grok-pattern-on-syslog-input/143669/5 "2018-09-07T08:23:57Z")

</div>

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