# Logstash - If %{statement} has "value"

**URL:** <https://discuss.elastic.co/t/logstash-if-statement-has-value/250702>\
**Category:** Logstash\
**Created:** [October 1, 2020, 2:54pm UTC](https://discuss.elastic.co/t/logstash-if-statement-has-value/250702 "2020-10-01T14:54:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![headtea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/headtea/32/24271_2.png) [@headtea](https://discuss.elastic.co/u/headtea)\
**Post date:** [October 1, 2020, 2:54pm UTC](https://discuss.elastic.co/t/logstash-if-statement-has-value/250702/1 "2020-10-01T14:54:45Z")

</div>

In Logstash, I'm trying to set a condition where if within a file named "cowrie.json", if a new message is received that starts with "login attempt\*" - send an email.

This is what I tried:

```
output {
  if [log][file][path] =~ "cowrie.json" {
  if %{message} =~ "login attempt.*"{
    email {
      to => 'test@address.com'
      subject => 'Honeypot Alert'
      body => "Someone interacted with the honeypot!"
      domain => 'mail.xconnect.net'
      port => 25
    }
  }
 }
}

```

If I remove the second `if` statement, it works. Does anyone happen to know what I have to replace the second `if` statement so that it would only apply to entires/messages that start with "login attempt"?

Huge thanks ahead!

---

<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:** [October 1, 2020, 3:16pm UTC](https://discuss.elastic.co/t/logstash-if-statement-has-value/250702/2 "2020-10-01T15:16:52Z")

</div>

> [@headtea](#):
>
> `if %{message} =~ "login attempt.*"{`

That should be

```
if "login attempt" in [message] {

```

or

```
if [message] =~ "^login attempt" {

```

(note that you said "starts with", so I anchored the pattern).

---

<div class="post-metadata">

**Author:** ![headtea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/headtea/32/24271_2.png) [@headtea](https://discuss.elastic.co/u/headtea)\
**Post date:** [October 1, 2020, 3:22pm UTC](https://discuss.elastic.co/t/logstash-if-statement-has-value/250702/3 "2020-10-01T15:22:12Z")

</div>

Thank you SO MUCH!

---

<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 29, 2020, 3:22pm UTC](https://discuss.elastic.co/t/logstash-if-statement-has-value/250702/4 "2020-10-29T15:22:20Z")

</div>

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