Metricbeat add_field from file?

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?

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);
        }

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