Configuring fields.yml for custom Beat

I am writing a custom beat to read temperature.

I have created the Beat using this, https://www.elastic.co/blog/build-your-own-beat, as an example.

However I am confused as to how to modify the fields.yml file so that the correct data types are set. I have tried adding the following to the fields.yml file in the root of my project:

- key: temperaturebeat
  title: temperaturebeat
  description:
  fields:
    - name: counter
      type: long
      required: true
      description: >
        PLEASE UPDATE DOCUMENTATION
    - name: deviceid
      type: string
    - name: sensorid
      type: string
    - name: celcius
      type: double
    - name: farenheit
      type: double

But each time I run male update the file is modified and these entries are removed. I have tried creating a file etc/fields.yml but the same thing happens.

My beat sort of works as it is, but the celcius measurement is seen as a long whereas the farehnheit is seen as a float. As you can see from the above I want them both to be double.

The following is how I am reading the values

func (bt *Temperaturebeat) readThermometers(dirFile string, beatname string, deviceid string) {

	// Build the pattern for the glob
	pattern := fmt.Sprintf("%s/??-????????????", dirFile)

	// Find all the files that have the specified pattern
	files, _ := filepath.Glob(pattern)
	for _, thermo := range files {

		// Create the path to the file from which to read the value
		thermoFile := fmt.Sprintf("%s/w1_slave", thermo)

		// get the C and F
		temperatureC, temperatureF := temperature(thermoFile)

		event := common.MapStr{
			"@timestamp":    common.Time(time.Now()),
			"type":          beatname,
			"deviceid":      deviceid,
			"sensorid":      path.Base(thermo),
			"celcius":       temperatureC,
			"farenheit":     temperatureF,
		}

		bt.client.PublishEvent(event)
	}
}

func temperature(file string) (float64, float64) {

	// Read the data in from the device
	dataBytes, err := ioutil.ReadFile(file)
	check(err)
	data := string(dataBytes)

	// Get the value of the temperature from the device
	result := regexTemp.FindStringSubmatch(data)
	tempFloat, err := strconv.ParseFloat(result[1], 64)
	check(err)

	// determine the C and F
	celcius := tempFloat / 1000
	farenheit := celcius*1.8 + 32

	return celcius, farenheit
}

The beat is configured to output to logstash if that makes any difference.

Any help is gratefully received.

Thanks, Russell

Which version of libbeat are you using? The most recent one looks under the _meta/fields.yml for your fields file.

@ruflin, thanks for that - it is exactly where the file is.

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