Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Variable expansion in Ping plugin #5201

Closed
theotherJohnC opened this issue Dec 27, 2018 · 7 comments
Closed

Environment Variable expansion in Ping plugin #5201

theotherJohnC opened this issue Dec 27, 2018 · 7 comments

Comments

@theotherJohnC
Copy link

Relevant telegraf.conf:

[[inputs.ping]]
urls = ["$FQDN_LIST"]

Relevant environment variable:

FQDN_LIST="google.com"

System info:

Docker 18.09, running on Windows 10

Steps to reproduce:

  1. Set the environment variable FQDN_LIST="google.com"
  2. Set telegraf.conf ping plugin as noted above
  3. Run telegraf

Expected behavior:

The environment variable should expand in the IP list as urls = ["google.com"], as printenv FQDN_LIST reports "google.com" for the environment variable. Thus, telegraf should be pinging google.com.

Actual behavior:

[inputs.ping]: Error in plugin: lookup "google.com": no such host

Additional info:

I'm running into this through a Docker Compose exercise in which I'm trying to build a Docker App that starts up a TICK stack with next to no manual configuration on the part of the end user, assuming the end user is running a Windows environment. I've written a rudimentary GUI tool to write a .env file that is imported when the composition is brought up, which includes setting FQDN_LIST and using it in the ping module.

I've considered that perhaps environment variables can't be used with the plugins, but Telegraf is reporting what I believe to be a correctly expanded variable. As the variable is a string, if I remove the quotes (thinking here that maybe it's a double quotes issue?) telegraf exits at startup and using single quotes prevents the variable from expanding, so I'm at a loss here on what to do to get this to work correctly, sans rewriting my configuration tool to output an entire telegraf.conf instead of breaking the config down into smaller individual files.

@danielnelson
Copy link
Contributor

I think the environment variable is quoted, and ping is trying to ping "google.com" instead of google.com. See #3794 (comment)

@theotherJohnC
Copy link
Author

It appears to work if I don't include quotes in the environment variable. For example:

FQDN_LIST=google.com

[[inputs.ping]]
urls = ["$FQDN_LIST"]

The above works as expected and writes ping data. This tells me that it was a double-quotes issue after all, for whatever reason (clearly I'm not understanding expansion correctly). That said, if I go to add a second domain to the list, it lumps the whole environment variable within that double quotes, causing it to fail as, for exampe, "google.com,gentoo.org" isn't a valid domain name.

@danielnelson -- Your reply came in just as I was writing this! You're correct, that's what's happening, and it appears to be correctable by not including the quotes in the environment variable, but prohibits multiple domains this way. I suppose that's a separate issue though, or should I just update this issue title to better reflect what the question now is?

@danielnelson
Copy link
Contributor

danielnelson commented Dec 27, 2018

If it is possible to set the environment variable to FQDN_LIST="google.com", "example.org", then you could remove the quotes in the config:

[[inputs.ping]]
urls = [$FQDN_LIST]

edit: added comma to environment variable value

@theotherJohnC
Copy link
Author

I've set the following per your post @danielnelson --

[[inputs.ping]]
urls = [$FQDN_LIST]

I then set FQDN_LIST="google.com", "gentoo.org", however, Telegraf then exits with the following:

Error running agent: Error parsing /etc/telegraf/telegraf.conf, toml: line 45: parse error

It makes sense that this should work, though I'm noting that in the Telegraf documentation located here, it explicitly states that string variables need to be quoted. It doesn't necessarily make sense to me why that would be, but it appears that this is why the expected result isn't manifesting.

@danielnelson
Copy link
Contributor

It looks like it is because we escape strings, so it turns into something like:

urls = [\"google.com\", \"example.org\"]

I believe you will need to use separate variables for this.

@theotherJohnC
Copy link
Author

Thank you for your help, @danielnelson -- it's appreciated! At this point, in regard to my goal, it looks like I'm just going to have to output a full config as opposed to breaking certain parts of the overall config into smaller files.

@chuflo326
Copy link

La variable FQDN_LIST puede ser el name de una consulta input.snmp, en donde tenga las ip consultadas por snmp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants