# Reading values from lsbeat.yml

**URL:** <https://discuss.elastic.co/t/reading-values-from-lsbeat-yml/94838>\
**Category:** Beats\
**Created:** [July 27, 2017, 4:05pm UTC](https://discuss.elastic.co/t/reading-values-from-lsbeat-yml/94838 "2017-07-27T16:05:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![soaguru](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@soaguru](https://discuss.elastic.co/u/soaguru)\
**Post date:** [July 27, 2017, 4:05pm UTC](https://discuss.elastic.co/t/reading-values-from-lsbeat-yml/94838/1 "2017-07-27T16:05:25Z")

</div>

I have written a custom beat lsbeat.yml (similar to the tutorial) and it works fine. I have a question on reading values from yml file.

I added a new property in the lsbeat.yml called  
lastRunTimestamp: "2017-07-27 00:00:00"

Now how do I read the "lastRunTimestamp" property value from lsbeat.yml in the lsbeat.go file?

I tried to look for the code in libbeat directory for the code which reads output.elasticsearch property etc. from lsbeat.yml, but couldn't find anything solid except cfgfile\_test.go file.

Note: I know to use "[gopkg.in/yaml.v2](http://gopkg.in/yaml.v2)" and get the properties. But I want to use something from beat framework itself. Hence the question.

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [July 27, 2017, 5:06pm UTC](https://discuss.elastic.co/t/reading-values-from-lsbeat-yml/94838/2 "2017-07-27T17:06:27Z")

</div>

Your beat has access to the config data through the `*common.Config` object passed to the `New()` function.

```auto
func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) {
	config := config.DefaultConfig
	if err := cfg.Unpack(&config); err != nil {
		return nil, fmt.Errorf("Error unpacking config: %v", err)
	}

```

You can add a new field to your config struct and it will be populated with the value from the config file when calling `Unpack`.

```auto
type Config struct {
    LastRunTimestamp string `config:"lastRunTimestamp"`
}

```

Or you can pass a `map[string]interface{}` object to `Unpack()` and the map will be populated with all the config data from the config file.

---

<div class="post-metadata">

**Author:** ![soaguru](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@soaguru](https://discuss.elastic.co/u/soaguru)\
**Post date:** [July 27, 2017, 5:10pm UTC](https://discuss.elastic.co/t/reading-values-from-lsbeat-yml/94838/3 "2017-07-27T17:10:35Z")

</div>

Thanks Andrew for the response. I added the lastRunTimestamp in the config.go file like below

```auto
package config

import "time"

type Config struct {
	Period time.Duration `config:"period"`
	LastRunTimestamp string `config: "lastRunTimestamp"`
}

var DefaultConfig = Config{
	Period: 60 * time.Second,
	LastRunTimestamp: "2017-07-27 00:00:25",
}

```

But I only get the LastRunTimestamp value configured in the DefaultConfig (i.e., "2017-07-27 00:00:25")and not the value that I enter in the lsbeat.yml ("2017-07-27 00:00:00").

Any clue.

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [July 27, 2017, 5:14pm UTC](https://discuss.elastic.co/t/reading-values-from-lsbeat-yml/94838/4 "2017-07-27T17:14:55Z")

</div>

Try removing that space after the colon in `config: "last`.

---

<div class="post-metadata">

**Author:** ![soaguru](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@soaguru](https://discuss.elastic.co/u/soaguru)\
**Post date:** [July 27, 2017, 5:19pm UTC](https://discuss.elastic.co/t/reading-values-from-lsbeat-yml/94838/5 "2017-07-27T17:19:22Z")

</div>

That worked. Thanks for the help.

---

<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:** [August 17, 2017, 4:05pm UTC](https://discuss.elastic.co/t/reading-values-from-lsbeat-yml/94838/6 "2017-08-17T16:05:25Z")

</div>

This topic was automatically closed after 21 days. New replies are no longer allowed.
