# Metricbeat add\_field from file?

**URL:** <https://discuss.elastic.co/t/metricbeat-add-field-from-file/300718>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [March 25, 2022, 3:31pm UTC](https://discuss.elastic.co/t/metricbeat-add-field-from-file/300718 "2022-03-25T15:31:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thech](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@thech](https://discuss.elastic.co/u/thech)\
**Post date:** [March 25, 2022, 3:31pm UTC](https://discuss.elastic.co/t/metricbeat-add-field-from-file/300718/1 "2022-03-25T15:31:15Z")

</div>

Hello,

I have Metricbeat and my application running from different containers. The application starts and generates a UUID, storing it in a file app.uuid. I can mount this file to Metricbeat, but how can I add it as a field to events? The file will not exist when Metricbeat first starts.

I've tried the following, but the script processor doesn't seem to have File(), and logs a javascript execption. Any recommendations?

```auto
processors:
  - add_docker_metadata: ~
  - add_host_metadata: ~
  - script:
      lang: javascript
      source: >
        function process(event) {
            var uuidFile = new File("/app.uuid");
            var uuid = "UNDEFINED"

            if (uuidFile.exists()) {
              var reader = new FileReader();
              reader.onload = function(e) {
                uuid = reader.result;
              }
              reader.readAsText(file, 'UTF-8');  
            }
            event.Put("app.uuid", uuid);
        }

```

---

<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:** [April 22, 2022, 5:31pm UTC](https://discuss.elastic.co/t/metricbeat-add-field-from-file/300718/2 "2022-04-22T17:31:46Z")

</div>

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