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

Fix Ping Input plugin for FreeBSD's ping6 #7861

Merged
merged 1 commit into from
Aug 20, 2020

Conversation

DasSkelett
Copy link
Contributor

@DasSkelett DasSkelett commented Jul 20, 2020

Problem

FreeBSD has separate ping binaries for IPv4 and IPv6, ping(8) and ping6(8).
Both have differently named options (or sometimes even with the same name but different function...),
and differently formatted outputs.

When using the exec method, the ping plugin, searches for a ttl= string to get the remaining TTL of the echo response, however ping6 has a different output format and returns the TTL as hlim=<integer>. Thus the plugin throws this error:

E! [inputs.ping] Error in plugin: Fatal error processing ping output: 2a09::

Furthermore the ping plugin isn't aware of the different command options and always tries to use the arguments for the IPv4 ping command, which fails:

E! [inputs.ping] Error in plugin: host 2a09::: ping6: Non-recoverable failure in name resolution, exit status 1

ping's -W is called -x for ping6
ping's -t is called -X for ping6

Changes

processPingOutput() searches for both ttl= and hlim= in the returned lines. The regex in getTTL() is updated accordingly, to match both cases.

p.args() now checks whether the binary string contains ping6 and if the system / GOOS is freebsd, and if yes, adds the arguments needed for ping6.
This effectively will result in the following default command lines:

# IPv4 ping command, nothing changed
ping -c 1 -n -s 16 -i 1 -W 1000 -t 10 2a09::
# IPv6 ping6 command to reach the same effect
ping6 -c 1 -n -s 16 -i 1 -x 1000 -X 10 2a09::

Unit tests

I've also added tests for this. I had to duplicate TestArgs(), since the expected result now also depends on other factors (p.Binary) besides the system.
With iputils-ping on Linux ping6 is a symlink to ping, so the options are the same. Don't know for inetuitls-ping, but it isn't supported by this plugin anyways.
The test also assumes that "anything else" uses the same args for ping and ping6, since that is basically what's implemented now.

PR testing

I have tested this myself on OPNsense 20.1.8 / FreeBSD 11.2-RELEASE-p21-HBSD
Here's an example config excerpt to reproduce the problem and to test the changes of this PR:

[[inputs.ping]]
  urls = ["8.8.8.8","216.58.207.36"]

[[inputs.ping]]
  urls = ["2001:4860:4860::8888","2a00:1450:4001:824::2004","2a09::"]
  binary = "ping6"
  ipv6 = true

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated. -> Not really, don't think there's anything to change in the README, is there?
  • Has appropriate unit tests.

@DasSkelett
Copy link
Contributor Author

DasSkelett commented Jul 26, 2020

If there's something else I can do or provide to make reviewing and/or testing easier for you, please tell me.

@DasSkelett
Copy link
Contributor Author

Do I need to do something else to get someone to look at this? Did I forget something?

Copy link
Contributor

@ssoroka ssoroka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the submission! Sorry about the delay.

@ssoroka ssoroka merged commit 7354a44 into influxdata:master Aug 20, 2020
@DasSkelett DasSkelett deleted the fix/freebsd-ping6 branch August 20, 2020 22:32
pmalek-sumo pushed a commit to SumoLogic/telegraf that referenced this pull request Aug 26, 2020
@sjwang90 sjwang90 added this to the 1.15.3 milestone Sep 1, 2020
idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
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

Successfully merging this pull request may close these issues.

3 participants