Can metricbeat support run command?

Hi all,

Is there any way to run small command in the metricbeat?

fields:
os_version: "cat /etc/redhat-release"

But in result, we can see this command did not run. Is there any way we can run it?

metricbeat will not run external commands for you. One option is to pass environment variables to metricbeat. e.g.

    $ OS_VERSION=$(cat /etc/redhat-release) metricbeat ...

then you can configure:

  fields.os_version: ${OS_VERSION:unknown}

Optionally without environment variables start metricbeat with:

    metricbeat -E os.version=$(cat /etc/redhat-release) ... -E os.type=linux -E os.distro=redhat -E os.arch=...

then you can configure:

  fields.os: ${os}

This config will get you an event with

"fields": {
  "os": {
    "type": "linux",
    "distro": "redhat",
    "version": "...",
    "arch": "...",
  }
}

Just an idea :wink:

this is a great idea. will test it tomorrow and share result to u.
but just be quereosity, why not support shell scripty or command? for security concern or performance?

One of the main concerns in security but also performance and complexity. If we would just execute any script in the config metricbeat would become a script execution engine...

verified the 2nd way, it can work as expected. and we use ansible to combind this as well. thanks again for ur detail explains.

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