ricoberger / script_exporter

Prometheus exporter to execute scripts and collect metrics from the output or the exit status.
MIT License
354 stars 82 forks source link

params not being honored despite flag noargs not present #88

Closed telsip closed 1 year ago

telsip commented 1 year ago

I am testing v2.14.0 in Docker as shown in the README.

/examples # ps -ef PID USER TIME COMMAND 1 root 0:00 /bin/script_exporter -config.file /examples/config.yaml

I slightly modified the helloworld.sh script as below: /examples # cat helloworld.sh

!/bin/sh

echo "hello_world{params=\"$1\",\"$2\"} 1"

I then query as below: http://localhost:9469/probe?script=helloworld&prefix=mypref&params=argv

The output shows (among other lines): mypref_hello_world{params="test",""} 1

I also tried the ping script (ping.sh) and no argument is passed.

Suggestions?

telsip commented 1 year ago

Seems this block is never entered:

if !e.noargs {
    scriptParams := params.Get("params")
    if scriptParams != "" {
        paramValues = strings.Split(scriptParams, ",")

        for i, p := range paramValues {
            paramValues[i] = params.Get(p)
        }
    }
}
telsip commented 1 year ago

Nevermind, looking at a closed issue had me figure it was the query URL not properly set. Maybe a good thing would be to improve the README.

So params points at query values that has to be set after like: http://localhost:9469/probe?script=helloworld&prefix=mypref&params=argv&argv=test