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

Problem with execute jsonpath #242

Open
Sk1v opened this issue Jun 22, 2023 · 3 comments
Open

Problem with execute jsonpath #242

Sk1v opened this issue Jun 22, 2023 · 3 comments

Comments

@Sk1v
Copy link

Sk1v commented Jun 22, 2023

Hi all!

How to fix the error "Failed to execute jsonpath"

The goal is this: go to the url with a whip and take information from it, then transfer this information to the alert. So that when a letter arrived that something was broken, it was immediately written what exactly (and what exactly broke was written in the check).
Check looks very simple:

{
  "status": "OK",
  "description": "All good",
  "sql": null
}

I need to get the description. As a result, I made such a config, focusing on examples:

modules:
  default:
    headers:
      MyHeader: MyHeaderValue
    metrics:
      - name: jsonhc
        type: object
        help: healthcheks description
        path: '{.description}'
        labels:
          env: prod
        values:
          status: 1
          description: '{.description}'

The answer I get is this:

json_exporter  | ts=2023-06-22T11:12:38.760Z caller=collector.go:136 level=error msg="Failed to execute jsonpath" err="description is not found" path={.description} data="\"All good\""
json_exporter  | ts=2023-06-22T11:12:38.761Z caller=collector.go:88 level=error msg="Failed to extract value for metric" path={.description} err="description is not found" metric="Desc{fqName: \"jsonhc_description\", help: \"healthcheks description\", constLabels: {}, variableLabels: [env]}"

The data I get is correct, but I can't take it for an alert. When I check the curl for targets, it's not there.

#curl http://localhost:7979/probe
Target parameter is missing

I've tried different variants of the "path" variable (such as '$.*' and '{ [*] }') but it doesn't work. Please help me figure it out is this a bug or am I doing something wrong?

@boturkin
Copy link

boturkin commented Jul 24, 2023

Try this, it should work:

modules:
  default:
    headers:
      MyHeader: MyHeaderValue
    metrics:
      - name: jsonhc
        type: object
        help: healthcheks description
        path: '{.description}'
        labels:
          env: prod
          description: '{@}'
        values:
          status: 1

@Sk1v
Copy link
Author

Sk1v commented Aug 3, 2023

So the problem was with Healthcheck itself. This is what it was supposed to be.

{
  "healthcheck": [
    {
      "status": "OK",
      "description": "All good",
      "sql": null
    }
  ]
}

After that the module worked as I wanted it to.
Also, to do what I had in mind, I needed a module like this.

path: '{.healthcheck[?(@.status != "OK")]}'

And then in case there was not "OK", I set up an alert so that I would be sent an email when the status == 1

@alexunderboots
Copy link

same problem with non-slice JSON ((((

{"sip_status":"OFFLINE"}

not work
path: '{.sip_status == "OFFLINE"}'
values:
status: 0

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

3 participants