# "Extracting" Data from a Message

**URL:** <https://discuss.elastic.co/t/extracting-data-from-a-message/31795>\
**Category:** Logstash\
**Created:** [October 7, 2015, 5:33pm UTC](https://discuss.elastic.co/t/extracting-data-from-a-message/31795 "2015-10-07T17:33:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![just5guy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/just5guy/32/5198_2.png) [@just5guy](https://discuss.elastic.co/u/just5guy)\
**Post date:** [October 7, 2015, 5:33pm UTC](https://discuss.elastic.co/t/extracting-data-from-a-message/31795/1 "2015-10-07T17:33:00Z")

</div>

So I am coming from Splunk, currently using Graylog, and trying to set up the ELK Stack to analyze power usage. I have my Energy Monitor sending messages to the server properly. Here are a couple lines for an example:

Vera-35030422 EventWatcher: M [022] Home Energy Monitor, Watts = 1001.520  
Vera-35030422 EventWatcher: M [022] Home Energy Monitor, Watts = 1002.240  
Vera-35030422 EventWatcher: M [022] Home Energy Monitor, Watts = 764.040  
Vera-35030422 EventWatcher: M [022] Home Energy Monitor, Watts = 5115.480  
Vera-35030422 EventWatcher: M [022] Home Energy Monitor, Watts = 894.720

I am pulling my hair out trying to "extract" a few things from each message. It was relatively easy using regular expressions and capture groups with the other products I used.

Basically, I need to be able to pull (make fields) from:  
-DeviceID 022 (variable)  
-DeviceName "Home Energy Monitor" (there are two more so it's variable, ie. HEM, HEM2, HEM3).  
-Watts ... just the float number at the end.

I need to convert the Watts to a float value rather than a string so that it can be graphed.

Anyone have any hints?

---

<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:** [October 7, 2015, 5:49pm UTC](https://discuss.elastic.co/t/extracting-data-from-a-message/31795/2 "2015-10-07T17:49:26Z")

</div>

The [grok filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html) is the Logstash plugin that provides regular expressions and capture groups. Something like this should work for you:

```
filter {
  grok {
    match => [
      "message",
      "%{NOTSPACE} %{NOTSPACE}: M \[%{INT:DeviceID:int}\] %{GREEDYDATA:DeviceName}, Watts = %{NUMBER:Watts:float}"
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![just5guy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/just5guy/32/5198_2.png) [@just5guy](https://discuss.elastic.co/u/just5guy)\
**Post date:** [October 7, 2015, 6:01pm UTC](https://discuss.elastic.co/t/extracting-data-from-a-message/31795/3 "2015-10-07T18:01:54Z")

</div>

Thank You!! I guess I am just still trying to get my head around grok and patterns, that helps A LOT!

---

<div class="post-metadata">

**Author:** ![just5guy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/just5guy/32/5198_2.png) [@just5guy](https://discuss.elastic.co/u/just5guy)\
**Post date:** [October 9, 2015, 4:02pm UTC](https://discuss.elastic.co/t/extracting-data-from-a-message/31795/4 "2015-10-09T16:02:31Z")

</div>

Just wanted to follow up that this worked great!

---

<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:** [July 6, 2017, 5:26am UTC](https://discuss.elastic.co/t/extracting-data-from-a-message/31795/5 "2017-07-06T05:26:58Z")

</div>


