ricoberger/script_exporter

script_exporter not passing custom params to script

Closed this issue · 5 comments

Hi, I have a script_exporter configured with the following file:

scripts:
  - name: my_script
    script: /full/path/to/script/my_script.py value3 value4

The script my_script.py is designed to output the received args to a file.
When I use this command:
curl http://127.0.0.1:9469/probe?script=my_script&params=param1&param1=value1
I would have expected to see value1 in the file output, however that is not the case, I see only the params value3 and value4. I cannot figure out what is wrong.

Hi @razvanpaul-mielcioiu , I tried to reproduce the issue in #40, but I think it works as expected.

The example from the mentioned PR sets the first two arguments in the configuration file and takes the third one from the params parameter. Then I get the following output:

script_with_arguments{arg1="test1", arg2="test2", arg3="test3"} 1

So for your case value1 should be added as argument after value4. Maybe it is a problem with the order of the arguments?

After more troubleshootings I've found that this works (note the quotes in url):
curl "http://localhost:9469/probe?script=my_script&params=param1,param2&param1=value1&param2=value2"

This one though doesn't work:
curl "http://localhost:9469/probe?script=my_script&params=param1&params=param2&param1=value1&param2=value2"

I need to check further, but I think the latest is used by prometheus when requesting data from script_exporter.

@ricoberger Yes, I can confirm, even after upgrading ot latest prometheus version, this is how prometheus requests data from script_exporter (taken from a tcpdump):
GET /probe?param1=value1&param2=value2&params=param1&params=param2&script=my_script HTTP/1.1

And after some debug, it seems script_exporter is not able to parse a query string like this:
params=param1&params=param2 - this is handled as a list in Golang, but the code expects a string so it can split it by comma, therefore it handles only the first param.

@razvanpaul-mielcioiu know I got it.

I updated the example in the PR. Passing multiple parameters should work with the following configuration (note the quotes around the params):

scrape_configs:
  - job_name: 'script_args'
    metrics_path: /probe
    params:
      script: [args]
      params: ["param1,param2"]
      param1: [value1]
      param2: [value2]
    static_configs:
      - targets: ["localhost:9469"]

Victory! Everything works now.
Thanks Rico for your excellent support!