prometheus-community / json_exporter

A prometheus exporter which scrapes remote JSON by JSONPath
Apache License 2.0
631 stars 191 forks source link

Failed to execute jsonpath. #89

Open stamina11 opened 3 years ago

stamina11 commented 3 years ago

I know this is not the best looking json but that's all i get to work with from our developers. Any chance to make this work? jsonpath.com is showing that it should work.

Json: { "status": "ok", "info": { "EVENT_GRID": { "status": "up", "system": "Event Grid", "details": "Event Grid is online." } } }

Query: `

Error: son_exporter | level=error ts=2021-03-04T23:52:03.713Z caller=collector.go:128 msg="Failed to execute jsonpath" err="map[EVENT_GRID:map[details:Event Grid is online. status:up system:Event Grid]] is not array or slice and cannot be filtered" path="{.info[?(@.status==\"down\")]}" data="{\"status\":\"ok\",\"info\":{\"EVENT_GRID\":{\"status\":\"up\",\"system\":\"Event Grid\",\"details\":\"Event Grid is online.\"}},\"error\":{},\"details\":{\"EVENT_GRID\":{\"status\":\"up\",\"system\":\"Event Grid\",\"details\":\"Event Grid is online.\"}}}" json_exporter | level=error ts=2021-03-04T23:52:03.713Z caller=collector.go:69 msg="Failed to extract json objects for metric" err="map[EVENT_GRID:map[details:Event Grid is online. status:up system:Event Grid]] is not array or slice and cannot be filtered" metric="Desc{fqName: \"dependencies_up_on\", help: \"API Check\", constLabels: {}, variableLabels: [dep_name]}"

Thanks in advance.

adean-consensys commented 3 years ago

I think the issue is that the provided example isn't a mapped object, it's nested JSON.

{
    "status": "ok",
    "info": {
        "EVENT_GRID": {
            "status": "up",
            "system": "Event Grid",
            "details": "Event Grid is online."
        }
    }
}

vs. (as in the example config)

{
    "status": "ok",
    "info": [
              {
        "EVENT_GRID": {
            "status": "up",
            "system": "Event Grid",
            "details": "Event Grid is online."
        }
       }
        ]
}