Heartbeat parsing JSON object for HTTP monitor failure

hey there, I am using Heartbeat 8.x and according to

I was trying to check the Sendgrid SMTP service using the public url https://status.sendgrid.com/api/v2/components.json

Using this code:

- type: http
  id: sendgrid-smtp-status
  name: Check Sendgrid SMTP
  fields:
    component: "sendgrid-smtp-status"
  schedule: '@every 10s'
  response.include_body: always
  tags: ["sendgrid-smtp"]
  urls:
    - https://status.sendgrid.com/api/v2/components.json
  check.request.method: GET
  check.response:
    status: [200]
    json:
      - description: Check Sendgrid SMTP status
        expression: '$.components[4].status == "operational"'

I can reach my goal. Anyway, if I want to use a more flexible syntax like this one (since I am not sure that SMTP service will be forever at position 4):

   expression: '$.components[?(@.name=="SMTP")].status == "operational"'

I will face the error

JSON body did not match 1 expressions or conditions 'rule 'Check Sendgrid SMTP status'($.components[?(@.name=="SMTP")].status == "operational") not matched

Can you explain me the reason?
Furthermore, if I use the following code just to check if SMTP object exists, it works:

   expression: '$.components[?(@.name=="SMTP")] != []'

ok. I found a possible solution. probably it is not the best but it works.
This is the way to check it:

expression: '$.components[?(@.name == "SMTP" && @.status == "operational")] != []'

In my opinion, official doc should be integrated with an example with logical operators

Hi @rschirin - sorry we failed to get back to you promptly on this. I actually did pull down the same API last week and do a PoC. I was able to write an expression that worked well with the latest version of the library Heartbeat uses for processing JSON with this feature, but my expression didn't work for the version of the lib Heartbeat requires. I apologize that I failed to reply back here with a status update.

In any case, I'm glad you were able to solve the issue and I'll mention the case to my team that perhaps we can enhance the documentation around this feature.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.