# If statement is failing to match for certain values.. pls help

**URL:** <https://discuss.elastic.co/t/if-statement-is-failing-to-match-for-certain-values-pls-help/210438>\
**Category:** Logstash\
**Created:** [December 3, 2019, 11:31pm UTC](https://discuss.elastic.co/t/if-statement-is-failing-to-match-for-certain-values-pls-help/210438 "2019-12-03T23:31:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cdnvballer](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Cdnvballer](https://discuss.elastic.co/u/Cdnvballer)\
**Post date:** [December 3, 2019, 11:31pm UTC](https://discuss.elastic.co/t/if-statement-is-failing-to-match-for-certain-values-pls-help/210438/1 "2019-12-03T23:31:28Z")

</div>

I have syslog network messages successfully parsed with logstash,  
event 1 has [system][syslog][hostname]=10.20.0.3  
event 2 has [system][syslog][hostname]=10.111.0.3

however the following statements fail to match for 10.111.x.x, and never uses the last else statement.  
any ideas?

I'm trying to match as follows

```
   if [system][syslog][hostname] =~ /10\.111\..*/ {
   mutate { 
                add_field => { 
                          "[geoip][location][latitude]" => "77.777777"
                          "[geoip][location][longitude]" => "77.777777" 
                          } 
          }
      }  
   else if [system][syslog][hostname] =~ /10\.20\./ {
    mutate {
            add_field => {
                    "[geoip][location][latitude]" => "88.888888"
                    "[geoip][location][longitude]" => "88.888888"
                    }
            }
    }    
   else {
    mutate {
                add_field => {
                          "[geoip][location][latitude]" => "99.999999"
                          "[geoip][location][longitude]" => "99.999999"
                          }
                }
      }
```

---

<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 3, 2019, 11:51pm UTC](https://discuss.elastic.co/t/if-statement-is-failing-to-match-for-certain-values-pls-help/210438/2 "2019-12-03T23:51:17Z")

</div>

> [@Cdnvballer](#):
>
> [syslog][system][hostname]

You are testing [system][syslog][hostname], not [syslog][system][hostname]

---

<div class="post-metadata">

**Author:** ![Cdnvballer](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Cdnvballer](https://discuss.elastic.co/u/Cdnvballer)\
**Post date:** [December 4, 2019, 12:03am UTC](https://discuss.elastic.co/t/if-statement-is-failing-to-match-for-certain-values-pls-help/210438/3 "2019-12-04T00:03:45Z")

</div>

sorry, that was a typo .. I meant that the fields as matched by grok should be [system][syslog][hostname]  
and discover console is showing this correctly

---

<div class="post-metadata">

**Author:** ![Cdnvballer](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Cdnvballer](https://discuss.elastic.co/u/Cdnvballer)\
**Post date:** [December 4, 2019, 9:24pm UTC](https://discuss.elastic.co/t/if-statement-is-failing-to-match-for-certain-values-pls-help/210438/4 "2019-12-04T21:24:54Z")

</div>

issue resolved:

I changed all my match statements to use .\* in the match

i.e.

```
"[system][syslog][hostname] =~ /10\.111\..*/"
"[system][syslog][hostname] =~ /10\.20\..*/"

```

all issues seemed to go away overnight... =) thx

```auto

```

---

<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:** [January 1, 2020, 9:24pm UTC](https://discuss.elastic.co/t/if-statement-is-failing-to-match-for-certain-values-pls-help/210438/5 "2020-01-01T21:24:57Z")

</div>

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