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

Ability to retrieve string value via httpjson #2835

Closed
amertner opened this issue May 20, 2017 · 9 comments
Closed

Ability to retrieve string value via httpjson #2835

amertner opened this issue May 20, 2017 · 9 comments
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Milestone

Comments

@amertner
Copy link
Contributor

Feature Request

I'd like to retrieve a string value in an http request, for example using inputs.http-response or inputs.httpjson. However, http-response discards any text returned, and httpjson ignores values that are not numbers.

Proposal:

I'd like to be able to process a json response a la this one, to create a field called ip:
{"ip":"81.171.xx.xx"}

Alternatively, I'd like to just have the entire http reply made available as a field so I can parse it.

Current behavior:

The json parser ignores fields that are not numbers.

Desired behavior:

The json parser should include fields that contain string values.

Use case: [Why is this important (helps with prioritizing requests)]

I would like to monitor my public IP addresses, using a service such as

https://api.ipify.org?format=json

(for json) or just this to get a straight string:

https://api.ipify.org

I think it could be useful for a wide range of other purposes, where people have an HTTP-based service that returns useful data that is not just a number.

@danielnelson
Copy link
Contributor

It would be great to have support for more advanced JSON parsing, I've been thinking about JSON Pointer or JSONPath.

We could also add a json_field_keys parser option that would behave like tag_keys.

In the meantime, you would need to use the exec plugin.

@danielnelson danielnelson added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label May 22, 2017
@danielnelson
Copy link
Contributor

#1363

@danielnelson danielnelson changed the title Ability to retrieve string value via http Ability to retrieve string value via httpjson Jun 9, 2017
@Dripoul
Copy link

Dripoul commented Feb 2, 2018

Hello guys,

Is that possible to know if this issue will be resolved on the next weeks/months ?
I'm very interested by retrieving Strings values by "httpjson" plugin in a monitoring project.

Thank you !

@danielnelson
Copy link
Contributor

@Dripoul I'm not aware of any direct work on this, if you are interested in working on this let me know. Don't forget you can get strings as tags today with tag_keys.

@marianob85
Copy link
Contributor

I've made another input for json and xml with full tree support also with strings as value. It's still under develop but in working state. The custom tags are not implemented yet.
https://github.com/marianob85/telegraf/tree/WebApi

@marianob85 marianob85 mentioned this issue Feb 7, 2018
@danielnelson
Copy link
Contributor

We are planning to merge #3546 soon, it is a HTTP input that can handle any of the input data formats and will eventually deprecate httpjson. We still need help on the next generation JSON parser #1363 and a XML parser #1758.

@danielnelson
Copy link
Contributor

In 1.8.0, this can be done with the string_keys option.

@danielnelson danielnelson added this to the 1.8.0 milestone Aug 23, 2018
@jbrischle
Copy link

@danielnelson could you please add this to the readme? Thanks.

@danielnelson
Copy link
Contributor

My previous comment has the incorrect option name, it should be json_strings_fields. The documentation for the JSON parser(data_format = "json") is here:

https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md#json

Keep in mind that this must be used with an input that supports the data_format option, in this case you will want to use the http input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

No branches or pull requests

5 participants