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

[httpjson] Array of objects error - unable to parse out as JSON #2156

Closed
marketadvorackova opened this issue Dec 13, 2016 · 1 comment
Closed

Comments

@marketadvorackova
Copy link

Bug report

Hi,
I've installed and configured httpjson input for telegraf and it works well for single object jsons. Getting a response with an array of objects (multiple measurements), it gives the following error:
ERROR in input [inputs.httpjson]: unable to parse out as JSON, json: cannot unmarshal array into Go value of type map[string]interface {} and I there seems to be no reason. I've copied the new version of the json parser in /plugins/parsers/json. If I'm not missing anything, how come it doesn't work?
Thanks a lot,
Marketa

Relevant telegraf.conf:

Functional input
[[inputs.httpjson]] name = "myapp_systeminfo" interval = "30s" servers = [ "http://test.myapp.company.it/rest/api/2/serverInfo" ] pass = [ "buildNumber", "versionNumbers" ] tag_keys = [ "baseUrl", "version" ] method = "GET" response_timeout = "5s" [inputs.httpjson.headers] Authorization = "Basic AJRtuiW46YNRtaB4=" [inputs.httpjson.parameters] doHealthCheck = "true"

Error giving input

[[inputs.httpjson]] name = "myapp_applicenses" servers = [ "http://test.myapp.company.it/rest/myappmonitor/1.0/applicenses" ] pass = [ "daysLeft" ] tag_keys = [ "application" ] method = "GET" response_timeout = "5s" [inputs.httpjson.headers] Authorization = "Basic AJRtuiW46YNRtaB4="

System info:

Telegraf version 1.1.2
OS Ubuntu 14.04.5 LTS
[Include Telegraf version, operating system name, and other relevant details]

Steps to reproduce:

  1. Input server config - call (rest api) responding with an array of objects json

Expected behavior:

Process each object in the array as a single metric.

Actual behavior:

Does nothing, logs an error ERROR in input [inputs.httpjson]: unable to parse out as JSON, json: cannot unmarshal array into Go value of type map[string]interface {}

Additional info:

Functional response (gets processed)
{ "baseUrl":"http://test.myapp.company.it", "version":"7.2.4", "versionNumbers":[ 7, 2, 4 ], "deploymentType":"Server", "buildNumber":72006, "buildDate":"2016-10-31T00:00:00.000+0100", "serverTime":"2016-12-13T17:43:48.952+0100", "scmInfo":"91606a849e49df24789f9d9a6614de45c98c37a8", "serverTitle":"MyAPPtest - MYAPP" }

Non-functional response (logs the error)
[ { "application":"myapp-app1", "daysLeft":126 }, { "application":"myapp-app2", "daysLeft":126 }, { "application":"myapp-app3", "daysLeft":126 } ]

@sparrc
Copy link
Contributor

sparrc commented Dec 13, 2016

json arrays will be supported in version 1.2: #1965

@sparrc sparrc closed this as completed Dec 13, 2016
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

2 participants