OPNsense: Adding inputs.ping to telegraf plugin

Last week there was a feature request to add the ping input to telegraf for monitoring latency.

First we check the .sample conf:

# [[inputs.ping]]
# ## NOTE: this plugin forks the ping command. You may need to set capabilities
# ## via setcap cap_net_raw+p /bin/ping
# #
# ## List of urls to ping
# urls = [„www.google.com“] # required
# ## number of pings to send per collection (ping -c <COUNT>)
# # count = 1
# ## interval, in s, at which to ping. 0 == default (ping -i <PING_INTERVAL>)
# # ping_interval = 1.0
# ## per-ping timeout, in s. 0 == no timeout (ping -W <TIMEOUT>)
# # timeout = 1.0
# ## interface to send ping from (ping -I <INTERFACE>)
# # interface = „“

 

Ok, seems we only need a checkbox to enable/disable ping and a field for adding hosts/urls to monitor. If this would only be one host, a simple text field is fine, but what about monitoring multiple hosts? We need the CSVListField type!

 

So this is our form:

Then the model:

And the templating in the telegraf.conf:

 

Forms and model is quite easy but what about templating? Contents of the object CSVListField look like:

8.8.8.8, 8.8.4.4

But we need:

‚8.8.8.8‘,’8.8.4.4′

 

To be honest I don’t know how to do it, but the good thing is, there is a community! I just pushed my ideas via a pull request and got the fix promptly:

https://github.com/opnsense/plugins/pull/522#issuecomment-360843054

 

You don’t have to be an expert to contribute code 🙂